Fix patching YAML in some cases

This commit is contained in:
Alexey Khit
2023-09-02 08:43:37 +03:00
parent 6288c2a57f
commit b1c4bcc508
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -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) {
+18
View File
@@ -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))
}