add test for SetLabel and SetAnnotation

This commit is contained in:
Jingfang Liu
2020-02-27 13:37:36 -08:00
parent 39094f2aeb
commit ef76575ab6

60
kyaml/yaml/kfns_test.go Normal file
View File

@@ -0,0 +1,60 @@
package yaml
import (
"testing"
)
var input = `apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Good Morning!"
enableRisky: "false"
`
func TestSetLabel(t *testing.T) {
rn := MustParse(input)
_, err := rn.Pipe(SetLabel("foo", "bar"))
if err != nil {
t.Fatalf("unexpected error %v", err)
}
output := rn.MustString()
expected := `apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
labels:
foo: 'bar'
data:
altGreeting: "Good Morning!"
enableRisky: "false"
`
if output != expected {
t.Fatalf("expected \n%s\nbut got \n%s\n", expected, output)
}
}
func TestAnnotation(t *testing.T) {
rn := MustParse(input)
_, err := rn.Pipe(SetAnnotation("foo", "bar"))
if err != nil {
t.Fatalf("unexpected error %v", err)
}
output := rn.MustString()
expected := `apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
annotations:
foo: 'bar'
data:
altGreeting: "Good Morning!"
enableRisky: "false"
`
if output != expected {
t.Fatalf("expected \n%s\nbut got \n%s\n", expected, output)
}
}