...
1#!/usr/bin/env bats
2
3@test "Pass when parsing a valid Kubernetes config YAML file" {
4 run bin/kubeval fixtures/valid.yaml
5 [ "$status" -eq 0 ]
6 [ "$output" = "PASS - fixtures/valid.yaml contains a valid ReplicationController (bob)" ]
7}
8
9@test "Pass when parsing a valid Kubernetes config YAML file on stdin" {
10 run bash -c "cat fixtures/valid.yaml | bin/kubeval"
11 [ "$status" -eq 0 ]
12 [ "$output" = "PASS - stdin contains a valid ReplicationController (bob)" ]
13}
14
15@test "Pass when parsing a valid Kubernetes config YAML file explicitly on stdin" {
16 run bash -c "cat fixtures/valid.yaml | bin/kubeval -"
17 [ "$status" -eq 0 ]
18 [ "$output" = "PASS - stdin contains a valid ReplicationController (bob)" ]
19}
20
21@test "Pass when parsing a valid Kubernetes config JSON file" {
22 run bin/kubeval fixtures/valid.json
23 [ "$status" -eq 0 ]
24 [ "$output" = "PASS - fixtures/valid.json contains a valid Deployment (default.nginx-deployment)" ]
25}
26
27@test "Pass when parsing a Kubernetes file with string and integer quantities" {
28 run bin/kubeval fixtures/quantity.yaml
29 [ "$status" -eq 0 ]
30 [ "$output" = "PASS - fixtures/quantity.yaml contains a valid LimitRange (mem-limit-range)" ]
31}
32
33@test "Pass when parsing a valid Kubernetes config file with int_to_string vars" {
34 run bin/kubeval fixtures/int_or_string.yaml
35 [ "$status" -eq 0 ]
36 [ "$output" = "PASS - fixtures/int_or_string.yaml contains a valid Service (kube-system.heapster)" ]
37}
38
39@test "Pass when parsing a valid Kubernetes config file with null arrays" {
40 run bin/kubeval fixtures/null_array.yaml
41 [ "$status" -eq 0 ]
42 [ "$output" = "PASS - fixtures/null_array.yaml contains a valid Deployment (kube-system.kubernetes-dashboard)" ]
43}
44
45@test "Pass when parsing a valid Kubernetes config file with null strings" {
46 run bin/kubeval fixtures/null_string.yaml
47 [ "$status" -eq 0 ]
48 [ "$output" = "PASS - fixtures/null_string.yaml contains a valid Service (frontend)" ]
49}
50
51@test "Pass when parsing a valid Kubernetes config YAML file with generate name" {
52 run bin/kubeval fixtures/generate_name.yaml
53 [ "$status" -eq 0 ]
54 [ "$output" = "PASS - fixtures/generate_name.yaml contains a valid Job (pi-{{ generateName }})" ]
55}
56
57@test "Pass when parsing a multi-document config file" {
58 run bin/kubeval fixtures/multi_valid.yaml
59 [ "$status" -eq 0 ]
60}
61
62@test "Fail when parsing a multi-document config file with one invalid resource" {
63 run bin/kubeval fixtures/multi_invalid.yaml
64 [ "$status" -eq 1 ]
65}
66
67@test "Fail when parsing an invalid Kubernetes config file" {
68 run bin/kubeval fixtures/invalid.yaml
69 [ "$status" -eq 1 ]
70}
71
72@test "Fail when parsing an invalid Kubernetes config file on stdin" {
73 run bash -c "cat fixtures/invalid.yaml | bin/kubeval -"
74 [ "$status" -eq 1 ]
75}
76
77@test "Return relevant error for non-existent file" {
78 run bin/kubeval fixtures/not-here
79 [ "$status" -eq 1 ]
80 [ $(expr "$output" : "^ERR - Could not open file") -ne 0 ]
81}
82
83@test "Pass when parsing a blank config file" {
84 run bin/kubeval fixtures/blank.yaml
85 [ "$status" -eq 0 ]
86 [ "$output" = "PASS - fixtures/blank.yaml contains an empty YAML document" ]
87 }
88
89 @test "Pass when parsing a blank config file with a comment" {
90 run bin/kubeval fixtures/comment.yaml
91 [ "$status" -eq 0 ]
92 [ "$output" = "PASS - fixtures/comment.yaml contains an empty YAML document" ]
93 }
94
95@test "Return relevant error for YAML missing kind key" {
96 run bin/kubeval fixtures/missing_kind.yaml
97 [ "$status" -eq 1 ]
98}
99
100@test "Fail when parsing a config with additional properties and strict set" {
101 run bin/kubeval --strict fixtures/extra_property.yaml
102 [ "$status" -eq 1 ]
103}
104
105@test "Fail when parsing a config with a kind key but no value" {
106 run bin/kubeval fixtures/missing_kind_value.yaml
107 [ "$status" -eq 1 ]
108}
109
110@test "Pass when parsing a config with additional properties" {
111 run bin/kubeval fixtures/extra_property.yaml
112 [ "$status" -eq 0 ]
113}
114
115@test "Fail when parsing a config with CRD" {
116 run bin/kubeval fixtures/test_crd.yaml
117 [ "$status" -eq 1 ]
118}
119
120@test "Pass when parsing a config with CRD and ignoring missing schemas" {
121 run bin/kubeval --ignore-missing-schemas fixtures/test_crd.yaml
122 [ "$status" -eq 0 ]
123}
124
125@test "Pass when using a valid --schema-location" {
126 run bin/kubeval fixtures/valid.yaml --schema-location https://kubernetesjsonschema.dev
127 [ "$status" -eq 0 ]
128}
129
130@test "Fail when using a faulty --schema-location" {
131 run bin/kubeval fixtures/valid.yaml --schema-location foo
132 [ "$status" -eq 1 ]
133}
134
135@test "Pass when using a valid KUBEVAL_SCHEMA_LOCATION variable" {
136 KUBEVAL_SCHEMA_LOCATION=https://kubernetesjsonschema.dev run bin/kubeval fixtures/valid.yaml
137 [ "$status" -eq 0 ]
138}
139
140@test "Fail when using a faulty KUBEVAL_SCHEMA_LOCATION variable" {
141 KUBEVAL_SCHEMA_LOCATION=foo run bin/kubeval fixtures/valid.yaml
142 [ "$status" -eq 1 ]
143}
144
145@test "Pass when using a valid --schema-location, which overrides a faulty KUBEVAL_SCHEMA_LOCATION variable" {
146 KUBEVAL_SCHEMA_LOCATION=foo run bin/kubeval fixtures/valid.yaml --schema-location https://kubernetesjsonschema.dev
147 [ "$status" -eq 0 ]
148}
149
150@test "Fail when using a faulty --schema-location, which overrides a valid KUBEVAL_SCHEMA_LOCATION variable" {
151 KUBEVAL_SCHEMA_LOCATION=https://kubernetesjsonschema.dev run bin/kubeval fixtures/valid.yaml --schema-location foo
152 [ "$status" -eq 1 ]
153}
154
155@test "Pass when using --openshift with a valid input" {
156 run bin/kubeval fixtures/valid.yaml --openshift
157 [ "$status" -eq 0 ]
158}
159
160@test "Fail when using --openshift with an invalid input" {
161 run bin/kubeval fixtures/invalid.yaml --openshift
162 [ "$status" -eq 1 ]
163}
164
165@test "Only prints a single warning when --ignore-missing-schemas is supplied" {
166 run bin/kubeval --ignore-missing-schemas fixtures/valid.yaml fixtures/valid.yaml
167 [ "$status" -eq 0 ]
168 [[ "${lines[0]}" == *"WARN - Set to ignore missing schemas"* ]]
169 [[ "${lines[1]}" == *"PASS - fixtures/valid.yaml contains a valid ReplicationController"* ]]
170 [[ "${lines[2]}" == *"PASS - fixtures/valid.yaml contains a valid ReplicationController"* ]]
171}
172
173@test "Does not print warnings if --quiet is supplied" {
174 run bin/kubeval --ignore-missing-schemas --quiet fixtures/valid.yaml
175 [ "$status" -eq 0 ]
176 [ "$output" = "PASS - fixtures/valid.yaml contains a valid ReplicationController (bob)" ]
177}
178
179@test "Adjusts help string when invoked as a kubectl plugin" {
180 ln -sf kubeval bin/kubectl-kubeval
181
182 run bin/kubectl-kubeval --help
183 [ "$status" -eq 0 ]
184 [[ ${lines[2]} == " kubectl kubeval <file>"* ]]
185}
View as plain text