From cb5bafe956710ad144ed83d55a061ccada321431 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Sat, 22 Jul 2023 13:39:30 -0400 Subject: [PATCH] updated test coverage Signed-off-by: Dave Shanley --- datamodel/spec_info_test.go | 11 +++++++++++ document_test.go | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/datamodel/spec_info_test.go b/datamodel/spec_info_test.go index ac63c562..702ae147 100644 --- a/datamodel/spec_info_test.go +++ b/datamodel/spec_info_test.go @@ -189,6 +189,17 @@ why: assert.Len(t, *r.SpecBytes, 55) } +func TestExtractSpecInfo_AnyDocument_JSON(t *testing.T) { + + random := `{ "something" : "yeah"}` + + r, e := ExtractSpecInfoWithDocumentCheck([]byte(random), true) + assert.Nil(t, e) + assert.NotNil(t, r.RootNode) + assert.Equal(t, "something", r.RootNode.Content[0].Content[0].Value) + assert.Len(t, *r.SpecBytes, 23) +} + func TestExtractSpecInfo_AnyDocumentFromConfig(t *testing.T) { random := `something: yeah diff --git a/document_test.go b/document_test.go index 67b8a0ed..050a6ff7 100644 --- a/document_test.go +++ b/document_test.go @@ -291,13 +291,24 @@ func TestDocument_RenderAndReload_Swagger(t *testing.T) { func TestDocument_BuildModelPreBuild(t *testing.T) { petstore, _ := ioutil.ReadFile("test_specs/petstorev3.json") - doc, _ := NewDocument(petstore) - doc.BuildV3Model() - doc.BuildV3Model() - _, _, _, e := doc.RenderAndReload() + _, e := NewDocument(petstore) assert.Len(t, e, 0) } +func TestDocument_AnyDoc(t *testing.T) { + anything := []byte(`{"chickens": "3.0.0", "burgers": {"title": "hello"}}`) + _, e := NewDocumentWithTypeCheck(anything, true) + assert.NoError(t, e) +} + +func TestDocument_AnyDocWithConfig(t *testing.T) { + anything := []byte(`{"chickens": "3.0.0", "burgers": {"title": "hello"}}`) + _, e := NewDocumentWithConfiguration(anything, &datamodel.DocumentConfiguration{ + BypassDocumentCheck: true, + }) + assert.NoError(t, e) +} + func TestDocument_BuildModelCircular(t *testing.T) { petstore, _ := ioutil.ReadFile("test_specs/circular-tests.yaml") doc, _ := NewDocument(petstore)