-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_test.go
79 lines (70 loc) · 1.28 KB
/
delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package yaml_test
import (
"fmt"
"testing"
"github.com/VojtechVitek/yaml-cli"
"github.com/google/go-cmp/cmp"
)
func TestDelete(t *testing.T) {
tt := []struct {
delete string
in []byte
out []byte
}{
{
in: deployment,
delete: "kind",
out: deploymentWithoutKind,
},
{
in: deployment,
delete: "metadata.labels.app",
out: deploymentWithoutMetadataLabelsApp,
},
{
in: []byte(fmt.Sprintf("a:\n b:\n c:\n d: value\nkey: value\n")),
delete: "a",
out: []byte("key: value\n"),
},
}
for i, tc := range tt {
doc, err := yaml.Parse(tc.in)
if err != nil {
t.Error(err)
}
if err := yaml.Delete(doc, tc.delete); err != nil {
t.Error(err)
}
if diff := cmp.Diff(tc.out, yaml.Bytes(doc)); diff != "" {
t.Errorf("tc[%v] mismatch (-want +got):\n%s", i, diff)
}
}
}
var deployment = []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
app: api
other: label
spec:
replicas: 3
`)
var deploymentWithoutKind = []byte(`apiVersion: apps/v1
metadata:
name: api
labels:
app: api
other: label
spec:
replicas: 3
`)
var deploymentWithoutMetadataLabelsApp = []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
other: label
spec:
replicas: 3
`)