@@ -157,27 +157,27 @@ matches some expectation:
157
157
* `kube.with.labels`: (optional) `map[string]string` containing the label keys
158
158
and values to use in constructing an equality label selector (for all listed
159
159
labels)
160
- * `kube. assert`: (optional) object containing assertions to make about the
160
+ * `assert`: (optional) object containing assertions to make about the
161
161
action performed by the test.
162
- * `kube. assert.error`: (optional) string to match a returned error from the
162
+ * `assert.error`: (optional) string to match a returned error from the
163
163
Kubernetes API server.
164
- * `kube. assert.len`: (optional) int with the expected number of items returned.
165
- * `kube. assert.notfound`: (optional) bool indicating the test author expects
164
+ * `assert.len`: (optional) int with the expected number of items returned.
165
+ * `assert.notfound`: (optional) bool indicating the test author expects
166
166
the Kubernetes API to return a 404/Not Found for a resource.
167
- * `kube. assert.unknown`: (optional) bool indicating the test author expects the
167
+ * `assert.unknown`: (optional) bool indicating the test author expects the
168
168
Kubernetes API server to respond that it does not know the type of resource
169
169
attempting to be fetched or created.
170
- * `kube. assert.matches`: (optional) a YAML string, a filepath, or a
170
+ * `assert.matches`: (optional) a YAML string, a filepath, or a
171
171
` map[string]interface{}` representing the content that you expect to find in
172
- the returned result from the `kube.get` call. If `kube. assert.matches` is a
172
+ the returned result from the `kube.get` call. If `assert.matches` is a
173
173
string, the string can be either a file path to a YAML manifest or
174
174
inline an YAML string containing the resource fields to compare.
175
175
Only fields present in the Matches resource are compared. There is a
176
176
check for existence in the retrieved resource as well as a check that
177
177
the value of the fields match. Only scalar fields are matched entirely.
178
178
In other words, you do not need to specify every field of a struct field
179
179
in order to compare the value of a single field in the nested struct.
180
- * `kube. assert.conditions`: (optional) a map, keyed by `ConditionType` string,
180
+ * `assert.conditions`: (optional) a map, keyed by `ConditionType` string,
181
181
of any of the following :
182
182
- a string containing the `Status` value that the `Condition` with the
183
183
` ConditionType` should have.
@@ -189,18 +189,18 @@ matches some expectation:
189
189
` ConditionType` should have
190
190
* `reason` which is the exact string that should be present in the
191
191
` Condition` with the `ConditionType`
192
- * `kube. assert.json`: (optional) object describing the assertions to make about
192
+ * `assert.json`: (optional) object describing the assertions to make about
193
193
resource(s) returned from the `kube.get` call to the Kubernetes API server.
194
- * `kube. assert.json.len`: (optional) integer representing the number of bytes in the
194
+ * `assert.json.len`: (optional) integer representing the number of bytes in the
195
195
resulting JSON object after successfully parsing the resource.
196
- * `kube. assert.json.paths`: (optional) map of strings where the keys of the map
196
+ * `assert.json.paths`: (optional) map of strings where the keys of the map
197
197
are JSONPath expressions and the values of the map are the expected value to
198
198
be found when evaluating the JSONPath expression
199
- * `kube. assert.json.path_formats`: (optional) map of strings where the keys of the map are
199
+ * `assert.json.path_formats`: (optional) map of strings where the keys of the map are
200
200
JSONPath expressions and the values of the map are the expected format of the
201
201
value to be found when evaluating the JSONPath expression. See the
202
202
[list of valid format strings](#valid-format-strings)
203
- * `kube. assert.json.schema`: (optional) string containing a filepath to a
203
+ * `assert.json.schema`: (optional) string containing a filepath to a
204
204
JSONSchema document. If present, the resource's structure will be validated
205
205
against this JSONSChema document.
206
206
@@ -227,8 +227,8 @@ name: test-nginx-pod-not-exist
227
227
tests:
228
228
- kube:
229
229
get: pods/nginx
230
- assert:
231
- notfound: true
230
+ assert:
231
+ notfound: true
232
232
` ` `
233
233
234
234
Testing that there are two Pods having the label `app:nginx` :
@@ -242,8 +242,8 @@ tests:
242
242
with :
243
243
labels :
244
244
app : nginx
245
- assert :
246
- len : 2
245
+ assert :
246
+ len : 2
247
247
` ` `
248
248
249
249
Testing that a Pod with the name ` nginx` exists by the specified timeout
@@ -323,9 +323,9 @@ tests:
323
323
- exec: ssh -T someuser@ip
324
324
` ` `
325
325
326
- # ## Asserting resource fields using `kube. assert.matches`
326
+ # ## Asserting resource fields using `assert.matches`
327
327
328
- The `kube. assert.matches` field of a `gdt-kube` test Spec allows a test author
328
+ The `assert.matches` field of a `gdt-kube` test Spec allows a test author
329
329
to specify expected fields and those field contents in a resource that was
330
330
returned by the Kubernetes API server from the result of a `kube.get` call.
331
331
@@ -342,27 +342,27 @@ tests:
342
342
- name: check deployment's ready replicas is 2
343
343
kube:
344
344
get: deployments/my-deployment
345
- assert:
346
- matches: |
347
- kind: Deployment
348
- metadata:
349
- name: my-deployment
350
- status:
351
- readyReplicas: 2
345
+ assert:
346
+ matches: |
347
+ kind: Deployment
348
+ metadata:
349
+ name: my-deployment
350
+ status:
351
+ readyReplicas: 2
352
352
` ` `
353
353
354
- you don't even need to include the kind and metadata in `kube. assert.matches`.
354
+ you don't even need to include the kind and metadata in `assert.matches`.
355
355
If missing, no kind and name matching will be performed.
356
356
357
357
` ` ` yaml
358
358
tests:
359
359
- name: check deployment's ready replicas is 2
360
360
kube:
361
361
get: deployments/my-deployment
362
- assert:
363
- matches: |
364
- status:
365
- readyReplicas: 2
362
+ assert:
363
+ matches: |
364
+ status:
365
+ readyReplicas: 2
366
366
` ` `
367
367
368
368
In fact, you don't need to use an inline multiline YAML string. You can
@@ -373,15 +373,15 @@ tests:
373
373
- name: check deployment's ready replicas is 2
374
374
kube:
375
375
get: deployments/my-deployment
376
- assert:
377
- matches:
378
- status:
379
- readyReplicas: 2
376
+ assert:
377
+ matches:
378
+ status:
379
+ readyReplicas: 2
380
380
` ` `
381
381
382
- # ## Asserting resource `Conditions` using `kube. assert.conditions`
382
+ # ## Asserting resource `Conditions` using `assert.conditions`
383
383
384
- ` kube. assertion.conditions` contains the assertions to make about a resource's
384
+ ` assertion.conditions` contains the assertions to make about a resource's
385
385
` Status.Conditions` collection. It is a map, keyed by the ConditionType
386
386
(matched case-insensitively), of assertions to make about that Condition. The
387
387
assertions can be :
@@ -402,9 +402,9 @@ use lowercase strings:
402
402
tests:
403
403
- kube:
404
404
get: pods/nginx
405
- assert:
406
- conditions:
407
- ready: true
405
+ assert:
406
+ conditions:
407
+ ready: true
408
408
` ` `
409
409
410
410
If we wanted to assert that the `ContainersReady` Condition had a status
@@ -414,11 +414,11 @@ of either `False` or `Unknown`, we could write the test like this:
414
414
tests:
415
415
- kube:
416
416
get: pods/nginx
417
- assert:
418
- conditions:
419
- containersReady:
420
- - false
421
- - unknown
417
+ assert:
418
+ conditions:
419
+ containersReady:
420
+ - false
421
+ - unknown
422
422
` ` `
423
423
424
424
Finally, if we wanted to assert that a Deployment's `Progressing`
@@ -429,24 +429,24 @@ Condition had a Reason field with a value "NewReplicaSetAvailable"
429
429
tests:
430
430
- kube:
431
431
get: deployments/nginx
432
- assert:
433
- conditions:
434
- progressing:
435
- status: true
436
- reason: NewReplicaSetAvailable
432
+ assert:
433
+ conditions:
434
+ progressing:
435
+ status: true
436
+ reason: NewReplicaSetAvailable
437
437
` ` `
438
438
439
- # ## Asserting resource fields using `kube. assert.json`
439
+ # ## Asserting resource fields using `assert.json`
440
440
441
- The `kube. assert.json` field of a `gdt-kube` test Spec allows a test author to
441
+ The `assert.json` field of a `gdt-kube` test Spec allows a test author to
442
442
specify expected fields, the value of those fields as well as the format of
443
443
field values in a resource that was returned by the Kubernetes API server from
444
444
the result of a `kube.get` call.
445
445
446
446
Suppose you have a Deployment resource and you want to write a test that checks
447
447
that a Deployment resource's `Status.ReadyReplicas` field is `2`.
448
448
449
- You can specify this expectation using the `kube. assert.json.paths` field,
449
+ You can specify this expectation using the `assert.json.paths` field,
450
450
which is a `map[string]interface{}` that takes map keys that are JSONPath
451
451
expressions and map values of what the field at that JSONPath expression should
452
452
contain :
@@ -456,10 +456,10 @@ tests:
456
456
- name: check deployment's ready replicas is 2
457
457
kube:
458
458
get: deployments/my-deployment
459
- assert:
460
- json:
461
- paths:
462
- $.status.readyReplicas: 2
459
+ assert:
460
+ json:
461
+ paths:
462
+ $.status.readyReplicas: 2
463
463
` ` `
464
464
465
465
JSONPath expressions can be fairly complex, allowing the test author to, for
@@ -471,14 +471,14 @@ tests:
471
471
- name: check deployment's pod template "app" label is "nginx"
472
472
kube:
473
473
get: deployments/my-deployment
474
- assert:
475
- json:
476
- paths:
477
- $.spec.template.labels["app"]: nginx
474
+ assert:
475
+ json:
476
+ paths:
477
+ $.spec.template.labels["app"]: nginx
478
478
` ` `
479
479
480
480
You can check that the value of a particular field at a JSONPath is formatted
481
- in a particular fashion using `kube. assert.json.path_formats`. This is a map,
481
+ in a particular fashion using `assert.json.path_formats`. This is a map,
482
482
keyed by JSONPath expression, of the data format the value of the field at that
483
483
JSONPath expression should have. Valid data formats are :
484
484
@@ -511,11 +511,11 @@ date-time timestamp:
511
511
tests:
512
512
- kube:
513
513
get: deployments/nginx
514
- assert:
515
- json:
516
- path_formats:
517
- $.metadata.uid: uuid4
518
- $.metadata.creationTimestamp: date-time
514
+ assert:
515
+ json:
516
+ path_formats:
517
+ $.metadata.uid: uuid4
518
+ $.metadata.creationTimestamp: date-time
519
519
` ` `
520
520
521
521
# ## Updating a resource and asserting corresponding field changes
@@ -564,10 +564,10 @@ tests:
564
564
after: 20s
565
565
kube:
566
566
get: deployments/nginx
567
- assert:
568
- matches:
569
- status:
570
- readyReplicas: 2
567
+ assert:
568
+ matches:
569
+ status:
570
+ readyReplicas: 2
571
571
- name: apply-deployment-change
572
572
kube:
573
573
apply: |
@@ -582,10 +582,10 @@ tests:
582
582
after: 20s
583
583
kube:
584
584
get: deployments/nginx
585
- assert:
586
- matches:
587
- status:
588
- readyReplicas: 1
585
+ assert:
586
+ matches:
587
+ status:
588
+ readyReplicas: 1
589
589
- name: delete-deployment
590
590
kube:
591
591
delete: deployments/nginx
@@ -619,16 +619,16 @@ tests:
619
619
- name: deployment-exists
620
620
kube:
621
621
get: deployments/nginx
622
- assert:
623
- matches:
624
- spec:
625
- replicas: 2
626
- template:
627
- metadata:
628
- labels:
629
- app: nginx
630
- status:
631
- readyReplicas: 2
622
+ assert:
623
+ matches:
624
+ spec:
625
+ replicas: 2
626
+ template:
627
+ metadata:
628
+ labels:
629
+ app: nginx
630
+ status:
631
+ readyReplicas: 2
632
632
- name: delete-deployment
633
633
kube:
634
634
delete: deployments/nginx
@@ -685,13 +685,13 @@ ok command-line-arguments 3.683s
685
685
686
686
You can see from the debug output above that `gdt` created the Deployment and
687
687
then did a `kube.get` for the `deployments/nginx` Deployment. Initially
688
- (attempt 1), the `kube. assert.matches` assertion failed because the
688
+ (attempt 1), the `assert.matches` assertion failed because the
689
689
` status.readyReplicas` field was not present in the returned resource. `gdt`
690
690
retried the `kube.get` call 4 more times (attempts 2-5), with attempts 2 and 3
691
691
failed the existence check for the `status.readyReplicas` field and attempt 4
692
692
failing the *value* check for the `status.readyReplicas` field being `1`
693
693
instead of the expected `2`. Finally, when the Deployment was completely rolled
694
- out, attempt 5 succeeded in all the `kube. assert.matches` assertions.
694
+ out, attempt 5 succeeded in all the `assert.matches` assertions.
695
695
696
696
# # Determining Kubernetes config, context and namespace values
697
697
0 commit comments