Skip to content

Commit

Permalink
Improved code coverage and fixed nil error when copying references
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Lobo authored and daveshanley committed Sep 9, 2024
1 parent 2fc6ac8 commit 07ed25a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index/rolodex.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ func (r *Rolodex) BuildIndexes() {
func (r *Rolodex) GetAllReferences() map[string]*Reference {
allRefs := make(map[string]*Reference)
for _, idx := range append(r.GetIndexes(), r.GetRootIndex()) {
if idx == nil {
continue
}
refs := idx.GetAllReferences()
maps.Copy(allRefs, refs)
}
Expand All @@ -446,6 +449,9 @@ func (r *Rolodex) GetAllReferences() map[string]*Reference {
func (r *Rolodex) GetAllMappedReferences() map[string]*Reference {
mappedRefs := make(map[string]*Reference)
for _, idx := range append(r.GetIndexes(), r.GetRootIndex()) {
if idx == nil {
continue
}
refs := idx.GetMappedReferences()
maps.Copy(mappedRefs, refs)
}
Expand Down
13 changes: 12 additions & 1 deletion index/rolodex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
func TestRolodex_NewRolodex(t *testing.T) {
c := CreateOpenAPIIndexConfig()
rolo := NewRolodex(c)
assert.Len(t, rolo.GetAllReferences(), 0)
assert.Len(t, rolo.GetAllMappedReferences(), 0)
assert.NotNil(t, rolo)
assert.NotNil(t, rolo.indexConfig)
assert.Nil(t, rolo.GetIgnoredCircularReferences())
Expand Down Expand Up @@ -1520,18 +1522,27 @@ func TestRolodex_SimpleTest_OneDoc(t *testing.T) {
}

cf := CreateOpenAPIIndexConfig()
cf.SpecFilePath = filepath.Join(baseDir, "doc1.yaml")
cf.BasePath = baseDir
cf.IgnoreArrayCircularReferences = true
cf.IgnorePolymorphicCircularReferences = true

rolo := NewRolodex(cf)
rolo.AddLocalFS(baseDir, fileFS)

rootBytes, err := os.ReadFile(cf.SpecFilePath)
assert.NoError(t, err)
var rootNode yaml.Node
_ = yaml.Unmarshal(rootBytes, &rootNode)
rolo.SetRootNode(&rootNode)

err = rolo.IndexTheRolodex()

//assert.NotZero(t, rolo.GetIndexingDuration()) comes back as 0 on windows.
assert.Nil(t, rolo.GetRootIndex())
assert.NotNil(t, rolo.GetRootIndex())
assert.Len(t, rolo.GetIndexes(), 10)
assert.Len(t, rolo.GetAllReferences(), 7)
assert.Len(t, rolo.GetAllMappedReferences(), 7)

lineCount := rolo.GetFullLineCount()
assert.Equal(t, int64(158), lineCount, "total line count in the rolodex is wrong")
Expand Down

0 comments on commit 07ed25a

Please sign in to comment.