Fix patching YAML in some cases
This commit is contained in:
+1
-1
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user