Skip to content

Commit

Permalink
Fix patching YAML in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 2, 2023
1 parent 6288c2a commit b1c4bcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func LastChild(node *yaml.Node) *yaml.Node {
if node.Content == nil {
return node
}
return node.Content[len(node.Content)-1]
return LastChild(node.Content[len(node.Content)-1])
}

func AddOrReplace(src []byte, key string, value any, nodeParent *yaml.Node) ([]byte, error) {
Expand Down
18 changes: 18 additions & 0 deletions pkg/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ streams:
camera1: url1
`, string(b))
}

func TestPatch2(t *testing.T) {
b := []byte(`streams:
camera1:
- url1
- url2
`)

b, err := Patch(b, "camera2", "url3", "streams")
require.Nil(t, err)

require.Equal(t, `streams:
camera1:
- url1
- url2
camera2: url3
`, string(b))
}

0 comments on commit b1c4bcc

Please sign in to comment.