Bumping coverage on 0.6.0

This commit is contained in:
Dave Shanley
2023-02-18 17:10:52 -05:00
parent e6626fe22e
commit c5e9dbc360
5 changed files with 114 additions and 23 deletions

View File

@@ -0,0 +1,101 @@
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package index
import (
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)
func TestSpecIndex_performExternalLookup(t *testing.T) {
yml := `{
"openapi": "3.1.0",
"paths": [
{"/": {
"get": {}
}}
]
}`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
assert.Len(t, index.GetPathsNode().Content, 1)
}
func TestSpecIndex_performExternalLookup_invalidURL(t *testing.T) {
yml := `openapi: 3.1.0
components:
schemas:
thing:
properties:
thong:
$ref: 'httpssss://not-gonna-work.com'`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
assert.Len(t, index.GetReferenceIndexErrors(), 2)
}
func TestSpecIndex_FindComponentInRoot(t *testing.T) {
yml := `openapi: 3.1.0
components:
schemas:
thing:
properties:
thong: hi!`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
thing := index.FindComponentInRoot("#/$splish/$.../slash#$///./")
assert.Nil(t, thing)
assert.Len(t, index.GetReferenceIndexErrors(), 0)
}
func TestSpecIndex_FailLookupRemoteComponent_badPath(t *testing.T) {
yml := `openapi: 3.1.0
components:
schemas:
thing:
properties:
thong:
$ref: 'https://pb33f.io/site.webmanifest#/....$.ok../oh#/$$_-'`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
thing := index.FindComponentInRoot("#/$splish/$.../slash#$///./")
assert.Nil(t, thing)
assert.Len(t, index.GetReferenceIndexErrors(), 2)
}
func TestSpecIndex_FailLookupRemoteComponent_Ok_butNotFound(t *testing.T) {
yml := `openapi: 3.1.0
components:
schemas:
thing:
properties:
thong:
$ref: 'https://pb33f.io/site.webmanifest#/valid-but-missing'`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
thing := index.FindComponentInRoot("#/valid-but-missing")
assert.Nil(t, thing)
assert.Len(t, index.GetReferenceIndexErrors(), 1)
}