32 lines
941 B
Go
32 lines
941 B
Go
package composeedit
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPatchPreservesUnknownAndComments(t *testing.T) {
|
|
src := "# top\nservices:\n app:\n image: nginx:old # keep\n x-future:\n magic: true\n deploy:\n replicas: 2\n"
|
|
out, e := Apply(src, Patch{Path: []string{"services", "app", "image"}, Value: "nginx:new"})
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if !strings.Contains(out, "x-future:") || !strings.Contains(out, "magic: true") || !strings.Contains(out, "replicas: 2") || !strings.Contains(out, "# top") {
|
|
t.Fatalf("preservation failed:\n%s", out)
|
|
}
|
|
r, e := Parse(out)
|
|
if e != nil || r.Value == nil {
|
|
t.Fatalf("parse %v", e)
|
|
}
|
|
}
|
|
func TestArrayPatch(t *testing.T) {
|
|
src := "services:\n app:\n ports:\n - 8080:80\n"
|
|
out, e := Apply(src, Patch{Path: []string{"services", "app", "ports", "0"}, Value: "9090:80"})
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if !strings.Contains(out, "9090:80") {
|
|
t.Fatal(out)
|
|
}
|
|
}
|