mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Another round of coverage
will it go green? will it stay red? who knows… Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -181,10 +181,7 @@ func createDocument(info *datamodel.SpecInfo, config *datamodel.DocumentConfigur
|
|||||||
if idxConfig.BaseURL != nil {
|
if idxConfig.BaseURL != nil {
|
||||||
|
|
||||||
// create a remote filesystem
|
// create a remote filesystem
|
||||||
remoteFS, fsErr := index.NewRemoteFSWithConfig(idxConfig)
|
remoteFS, _ := index.NewRemoteFSWithConfig(idxConfig)
|
||||||
if fsErr != nil {
|
|
||||||
return nil, fsErr
|
|
||||||
}
|
|
||||||
if config.RemoteURLHandler != nil {
|
if config.RemoteURLHandler != nil {
|
||||||
remoteFS.RemoteHandlerFunc = config.RemoteURLHandler
|
remoteFS.RemoteHandlerFunc = config.RemoteURLHandler
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -467,3 +467,22 @@ func TestRolodexRemoteFileSystem_CustomHttpHandler(t *testing.T) {
|
|||||||
assert.NotNil(t, lDoc)
|
assert.NotNil(t, lDoc)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRolodexRemoteFileSystem_FailRemoteFS(t *testing.T) {
|
||||||
|
data, _ := os.ReadFile("../../../test_specs/first.yaml")
|
||||||
|
info, _ := datamodel.ExtractSpecInfo(data)
|
||||||
|
|
||||||
|
cf := datamodel.NewDocumentConfiguration()
|
||||||
|
cf.RemoteURLHandler = http.Get
|
||||||
|
baseUrl := "https://no-no-this-will-not-work-it-just-will-not-get-the-job-done-mate.com"
|
||||||
|
u, _ := url.Parse(baseUrl)
|
||||||
|
cf.BaseURL = u
|
||||||
|
|
||||||
|
pizza := func(url string) (resp *http.Response, err error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
cf.RemoteURLHandler = pizza
|
||||||
|
lDoc, err := CreateDocumentFromConfig(info, cf)
|
||||||
|
assert.NotNil(t, lDoc)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -825,6 +825,16 @@ func TestCreateDocument_YamlAnchor(t *testing.T) {
|
|||||||
assert.NotNil(t, postJsonType)
|
assert.NotNil(t, postJsonType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateDocument_NotOpenAPI_EnforcedDocCheck(t *testing.T) {
|
||||||
|
yml := `notadoc: no`
|
||||||
|
|
||||||
|
info, _ := datamodel.ExtractSpecInfo([]byte(yml))
|
||||||
|
var err error
|
||||||
|
_, err = CreateDocumentFromConfig(info, &datamodel.DocumentConfiguration{})
|
||||||
|
assert.Equal(t,
|
||||||
|
"no openapi version/tag found, cannot create document", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleCreateDocument() {
|
func ExampleCreateDocument() {
|
||||||
// How to create a low-level OpenAPI 3 Document
|
// How to create a low-level OpenAPI 3 Document
|
||||||
|
|
||||||
|
|||||||
@@ -706,6 +706,9 @@ paths:
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.NotNil(t, doc.GetConfiguration())
|
||||||
|
assert.Equal(t, doc.GetConfiguration(), cf)
|
||||||
|
|
||||||
result, errs := doc.BuildV3Model()
|
result, errs := doc.BuildV3Model()
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
panic(errs)
|
panic(errs)
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
|
|||||||
assert.Len(t, index.GetAllReferenceSchemas(), 1972)
|
assert.Len(t, index.GetAllReferenceSchemas(), 1972)
|
||||||
assert.NotNil(t, index.GetRootServersNode())
|
assert.NotNil(t, index.GetRootServersNode())
|
||||||
assert.Len(t, index.GetAllRootServers(), 1)
|
assert.Len(t, index.GetAllRootServers(), 1)
|
||||||
|
assert.Equal(t, "", index.GetSpecAbsolutePath())
|
||||||
|
assert.NotNil(t, index.GetLogger())
|
||||||
|
|
||||||
// not required, but flip the circular result switch on and off.
|
// not required, but flip the circular result switch on and off.
|
||||||
assert.False(t, index.AllowCircularReferenceResolving())
|
assert.False(t, index.AllowCircularReferenceResolving())
|
||||||
|
|||||||
Reference in New Issue
Block a user