forked from instrumenta/kubeval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acceptance.bats
executable file
·185 lines (151 loc) · 6.35 KB
/
acceptance.bats
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bats
@test "Pass when parsing a valid Kubernetes config YAML file" {
run bin/kubeval fixtures/valid.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/valid.yaml contains a valid ReplicationController (bob)" ]
}
@test "Pass when parsing a valid Kubernetes config YAML file on stdin" {
run bash -c "cat fixtures/valid.yaml | bin/kubeval"
[ "$status" -eq 0 ]
[ "$output" = "PASS - stdin contains a valid ReplicationController (bob)" ]
}
@test "Pass when parsing a valid Kubernetes config YAML file explicitly on stdin" {
run bash -c "cat fixtures/valid.yaml | bin/kubeval -"
[ "$status" -eq 0 ]
[ "$output" = "PASS - stdin contains a valid ReplicationController (bob)" ]
}
@test "Pass when parsing a valid Kubernetes config JSON file" {
run bin/kubeval fixtures/valid.json
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/valid.json contains a valid Deployment (default.nginx-deployment)" ]
}
@test "Pass when parsing a Kubernetes file with string and integer quantities" {
run bin/kubeval fixtures/quantity.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/quantity.yaml contains a valid LimitRange (mem-limit-range)" ]
}
@test "Pass when parsing a valid Kubernetes config file with int_to_string vars" {
run bin/kubeval fixtures/int_or_string.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/int_or_string.yaml contains a valid Service (kube-system.heapster)" ]
}
@test "Pass when parsing a valid Kubernetes config file with null arrays" {
run bin/kubeval fixtures/null_array.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/null_array.yaml contains a valid Deployment (kube-system.kubernetes-dashboard)" ]
}
@test "Pass when parsing a valid Kubernetes config file with null strings" {
run bin/kubeval fixtures/null_string.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/null_string.yaml contains a valid Service (frontend)" ]
}
@test "Pass when parsing a valid Kubernetes config YAML file with generate name" {
run bin/kubeval fixtures/generate_name.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/generate_name.yaml contains a valid Job (pi-{{ generateName }})" ]
}
@test "Pass when parsing a multi-document config file" {
run bin/kubeval fixtures/multi_valid.yaml
[ "$status" -eq 0 ]
}
@test "Fail when parsing a multi-document config file with one invalid resource" {
run bin/kubeval fixtures/multi_invalid.yaml
[ "$status" -eq 1 ]
}
@test "Fail when parsing an invalid Kubernetes config file" {
run bin/kubeval fixtures/invalid.yaml
[ "$status" -eq 1 ]
}
@test "Fail when parsing an invalid Kubernetes config file on stdin" {
run bash -c "cat fixtures/invalid.yaml | bin/kubeval -"
[ "$status" -eq 1 ]
}
@test "Return relevant error for non-existent file" {
run bin/kubeval fixtures/not-here
[ "$status" -eq 1 ]
[ $(expr "$output" : "^ERR - Could not open file") -ne 0 ]
}
@test "Pass when parsing a blank config file" {
run bin/kubeval fixtures/blank.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/blank.yaml contains an empty YAML document" ]
}
@test "Pass when parsing a blank config file with a comment" {
run bin/kubeval fixtures/comment.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/comment.yaml contains an empty YAML document" ]
}
@test "Return relevant error for YAML missing kind key" {
run bin/kubeval fixtures/missing_kind.yaml
[ "$status" -eq 1 ]
}
@test "Fail when parsing a config with additional properties and strict set" {
run bin/kubeval --strict fixtures/extra_property.yaml
[ "$status" -eq 1 ]
}
@test "Fail when parsing a config with a kind key but no value" {
run bin/kubeval fixtures/missing_kind_value.yaml
[ "$status" -eq 1 ]
}
@test "Pass when parsing a config with additional properties" {
run bin/kubeval fixtures/extra_property.yaml
[ "$status" -eq 0 ]
}
@test "Fail when parsing a config with CRD" {
run bin/kubeval fixtures/test_crd.yaml
[ "$status" -eq 1 ]
}
@test "Pass when parsing a config with CRD and ignoring missing schemas" {
run bin/kubeval --ignore-missing-schemas fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}
@test "Pass when using a valid --schema-location" {
run bin/kubeval fixtures/valid.yaml --schema-location https://kubernetesjsonschema.dev
[ "$status" -eq 0 ]
}
@test "Fail when using a faulty --schema-location" {
run bin/kubeval fixtures/valid.yaml --schema-location foo
[ "$status" -eq 1 ]
}
@test "Pass when using a valid KUBEVAL_SCHEMA_LOCATION variable" {
KUBEVAL_SCHEMA_LOCATION=https://kubernetesjsonschema.dev run bin/kubeval fixtures/valid.yaml
[ "$status" -eq 0 ]
}
@test "Fail when using a faulty KUBEVAL_SCHEMA_LOCATION variable" {
KUBEVAL_SCHEMA_LOCATION=foo run bin/kubeval fixtures/valid.yaml
[ "$status" -eq 1 ]
}
@test "Pass when using a valid --schema-location, which overrides a faulty KUBEVAL_SCHEMA_LOCATION variable" {
KUBEVAL_SCHEMA_LOCATION=foo run bin/kubeval fixtures/valid.yaml --schema-location https://kubernetesjsonschema.dev
[ "$status" -eq 0 ]
}
@test "Fail when using a faulty --schema-location, which overrides a valid KUBEVAL_SCHEMA_LOCATION variable" {
KUBEVAL_SCHEMA_LOCATION=https://kubernetesjsonschema.dev run bin/kubeval fixtures/valid.yaml --schema-location foo
[ "$status" -eq 1 ]
}
@test "Pass when using --openshift with a valid input" {
run bin/kubeval fixtures/valid.yaml --openshift
[ "$status" -eq 0 ]
}
@test "Fail when using --openshift with an invalid input" {
run bin/kubeval fixtures/invalid.yaml --openshift
[ "$status" -eq 1 ]
}
@test "Only prints a single warning when --ignore-missing-schemas is supplied" {
run bin/kubeval --ignore-missing-schemas fixtures/valid.yaml fixtures/valid.yaml
[ "$status" -eq 0 ]
[[ "${lines[0]}" == *"WARN - Set to ignore missing schemas"* ]]
[[ "${lines[1]}" == *"PASS - fixtures/valid.yaml contains a valid ReplicationController"* ]]
[[ "${lines[2]}" == *"PASS - fixtures/valid.yaml contains a valid ReplicationController"* ]]
}
@test "Does not print warnings if --quiet is supplied" {
run bin/kubeval --ignore-missing-schemas --quiet fixtures/valid.yaml
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/valid.yaml contains a valid ReplicationController (bob)" ]
}
@test "Adjusts help string when invoked as a kubectl plugin" {
ln -sf kubeval bin/kubectl-kubeval
run bin/kubectl-kubeval --help
[ "$status" -eq 0 ]
[[ ${lines[2]} == " kubectl kubeval <file>"* ]]
}