Skip to content

Commit

Permalink
Added a nill check to lookup.
Browse files Browse the repository at this point in the history
was causing vacuum to crash during testing.
  • Loading branch information
daveshanley committed Jul 9, 2024
1 parent c9155f7 commit 425b25c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func FindKeyNodeFull(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelN
}
}

if key == v.Content[x].Value {
if len(v.Content) > 0 && key == v.Content[x].Value {
if IsNodeMap(v) {
if x+1 == len(v.Content) {
return v, v.Content[x], NodeAlias(v.Content[x])
Expand Down
41 changes: 41 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,47 @@ func TestDetermineJSONWhitespaceLength_None(t *testing.T) {
assert.Equal(t, 0, DetermineWhitespaceLength(string(someBytes)))
}

func TestFindFirstKeyNode_MergeTest(t *testing.T) {
yml := []byte(`openapi: 3.0.3
x-a: &anchor
important-field: true
x-b:
<<: *anchor
`)

var rootNode yaml.Node
_ = yaml.Unmarshal(yml, &rootNode)

k, v := FindFirstKeyNode("important-field", rootNode.Content[0].Content[5].Content, 0)
assert.NotNil(t, k)
assert.NotNil(t, v)
assert.Equal(t, "true", v.Value)

}

func TestFindKeyNodeFull_MergeTest(t *testing.T) {
yml := []byte(`openapi: 3.0.3
x-a: &anchor
important-field: true
x-b:
<<: *anchor
`)

var rootNode yaml.Node
_ = yaml.Unmarshal(yml, &rootNode)

k, l, v := FindKeyNodeFull("servers", rootNode.Content[0].Content)
assert.NotNil(t, k)
assert.NotNil(t, v)
assert.NotNil(t, l)
assert.Equal(t, "true", v.Value)

}

func TestFindFirstKeyNode_DoubleMerge(t *testing.T) {
yml := []byte(`openapi: 3.0.3
Expand Down

0 comments on commit 425b25c

Please sign in to comment.