diff --git a/pkg/yaml/yaml.go b/pkg/yaml/yaml.go index 6864a87f..0a020e91 100644 --- a/pkg/yaml/yaml.go +++ b/pkg/yaml/yaml.go @@ -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) { diff --git a/pkg/yaml/yaml_test.go b/pkg/yaml/yaml_test.go index 4b3d8dfe..2129c175 100644 --- a/pkg/yaml/yaml_test.go +++ b/pkg/yaml/yaml_test.go @@ -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)) +}