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 committed Aug 28, 2024
1 parent eb7e09a commit e4a49c0
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 @@ -1516,18 +1518,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)

assert.NoError(t, err)
assert.Len(t, rolo.indexes, 10)
Expand Down

0 comments on commit e4a49c0

Please sign in to comment.