mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
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)
|
|
}
|
|
}
|