more coverage bumps to rolodex

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-10-31 14:10:48 -04:00
parent 0b08a63e63
commit b37b9a2fb9
3 changed files with 138 additions and 118 deletions

View File

@@ -44,7 +44,6 @@ func (index *SpecIndex) FindComponent(componentId string) *Reference {
// root search // root search
return index.FindComponentInRoot(componentId) return index.FindComponentInRoot(componentId)
} }
return nil
} }
func FindComponent(root *yaml.Node, componentId, absoluteFilePath string, index *SpecIndex) *Reference { func FindComponent(root *yaml.Node, componentId, absoluteFilePath string, index *SpecIndex) *Reference {

View File

@@ -164,7 +164,7 @@ func TestRolodexLocalFile_TestFilters(t *testing.T) {
} }
func TestRolodexLocalFile_TestBasFS(t *testing.T) { func TestRolodexLocalFile_TestBadFS(t *testing.T) {
testFS := test_badfs{} testFS := test_badfs{}
@@ -176,3 +176,11 @@ func TestRolodexLocalFile_TestBasFS(t *testing.T) {
assert.Nil(t, fileFS) assert.Nil(t, fileFS)
} }
func TestNewRolodexLocalFile_BadOffset(t *testing.T) {
lf := &LocalFile{offset: -1}
z, y := io.ReadAll(lf)
assert.Len(t, z, 0)
assert.Error(t, y)
}

View File

@@ -4,6 +4,7 @@
package index package index
import ( import (
"context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"os" "os"
@@ -21,3 +22,15 @@ func TestSpecIndex_SearchIndexForReference(t *testing.T) {
ref, _ := idx.SearchIndexForReference("#/components/schemas/Pet") ref, _ := idx.SearchIndexForReference("#/components/schemas/Pet")
assert.NotNil(t, ref) assert.NotNil(t, ref)
} }
func TestSpecIndex_SearchIndexForReferenceWithContext(t *testing.T) {
petstore, _ := os.ReadFile("../test_specs/petstorev3.json")
var rootNode yaml.Node
_ = yaml.Unmarshal(petstore, &rootNode)
c := CreateOpenAPIIndexConfig()
idx := NewSpecIndexWithConfig(&rootNode, c)
ref, _, _ := idx.SearchIndexForReferenceWithContext(context.Background(), "#/components/schemas/Pet")
assert.NotNil(t, ref)
}