Skip to content

Commit 3f09341

Browse files
committed
Rename kube.assert to just assert
Breaking API change. In order to align with the `exec` and `http` plugins, this brings the assertions contained in the `kube.assert` field into a top-level Spec field called `assert`. Signed-off-by: Jay Pipes <[email protected]>
1 parent 8c46526 commit 3f09341

21 files changed

+184
-170
lines changed

README.md

+87-87
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,27 @@ matches some expectation:
157157
* `kube.with.labels`: (optional) `map[string]string` containing the label keys
158158
and values to use in constructing an equality label selector (for all listed
159159
labels)
160-
* `kube.assert`: (optional) object containing assertions to make about the
160+
* `assert`: (optional) object containing assertions to make about the
161161
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
163163
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
166166
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
168168
Kubernetes API server to respond that it does not know the type of resource
169169
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
171171
`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
173173
string, the string can be either a file path to a YAML manifest or
174174
inline an YAML string containing the resource fields to compare.
175175
Only fields present in the Matches resource are compared. There is a
176176
check for existence in the retrieved resource as well as a check that
177177
the value of the fields match. Only scalar fields are matched entirely.
178178
In other words, you do not need to specify every field of a struct field
179179
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,
181181
of any of the following:
182182
- a string containing the `Status` value that the `Condition` with the
183183
`ConditionType` should have.
@@ -189,18 +189,18 @@ matches some expectation:
189189
`ConditionType` should have
190190
* `reason` which is the exact string that should be present in the
191191
`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
193193
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
195195
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
197197
are JSONPath expressions and the values of the map are the expected value to
198198
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
200200
JSONPath expressions and the values of the map are the expected format of the
201201
value to be found when evaluating the JSONPath expression. See the
202202
[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
204204
JSONSchema document. If present, the resource's structure will be validated
205205
against this JSONSChema document.
206206

@@ -227,8 +227,8 @@ name: test-nginx-pod-not-exist
227227
tests:
228228
- kube:
229229
get: pods/nginx
230-
assert:
231-
notfound: true
230+
assert:
231+
notfound: true
232232
```
233233

234234
Testing that there are two Pods having the label `app:nginx`:
@@ -242,8 +242,8 @@ tests:
242242
with:
243243
labels:
244244
app: nginx
245-
assert:
246-
len: 2
245+
assert:
246+
len: 2
247247
```
248248
249249
Testing that a Pod with the name `nginx` exists by the specified timeout
@@ -323,9 +323,9 @@ tests:
323323
- exec: ssh -T someuser@ip
324324
```
325325

326-
### Asserting resource fields using `kube.assert.matches`
326+
### Asserting resource fields using `assert.matches`
327327

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
329329
to specify expected fields and those field contents in a resource that was
330330
returned by the Kubernetes API server from the result of a `kube.get` call.
331331

@@ -342,27 +342,27 @@ tests:
342342
- name: check deployment's ready replicas is 2
343343
kube:
344344
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
352352
```
353353

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`.
355355
If missing, no kind and name matching will be performed.
356356

357357
```yaml
358358
tests:
359359
- name: check deployment's ready replicas is 2
360360
kube:
361361
get: deployments/my-deployment
362-
assert:
363-
matches: |
364-
status:
365-
readyReplicas: 2
362+
assert:
363+
matches: |
364+
status:
365+
readyReplicas: 2
366366
```
367367

368368
In fact, you don't need to use an inline multiline YAML string. You can
@@ -373,15 +373,15 @@ tests:
373373
- name: check deployment's ready replicas is 2
374374
kube:
375375
get: deployments/my-deployment
376-
assert:
377-
matches:
378-
status:
379-
readyReplicas: 2
376+
assert:
377+
matches:
378+
status:
379+
readyReplicas: 2
380380
```
381381

382-
### Asserting resource `Conditions` using `kube.assert.conditions`
382+
### Asserting resource `Conditions` using `assert.conditions`
383383

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
385385
`Status.Conditions` collection. It is a map, keyed by the ConditionType
386386
(matched case-insensitively), of assertions to make about that Condition. The
387387
assertions can be:
@@ -402,9 +402,9 @@ use lowercase strings:
402402
tests:
403403
- kube:
404404
get: pods/nginx
405-
assert:
406-
conditions:
407-
ready: true
405+
assert:
406+
conditions:
407+
ready: true
408408
```
409409

410410
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:
414414
tests:
415415
- kube:
416416
get: pods/nginx
417-
assert:
418-
conditions:
419-
containersReady:
420-
- false
421-
- unknown
417+
assert:
418+
conditions:
419+
containersReady:
420+
- false
421+
- unknown
422422
```
423423

424424
Finally, if we wanted to assert that a Deployment's `Progressing`
@@ -429,24 +429,24 @@ Condition had a Reason field with a value "NewReplicaSetAvailable"
429429
tests:
430430
- kube:
431431
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
437437
```
438438

439-
### Asserting resource fields using `kube.assert.json`
439+
### Asserting resource fields using `assert.json`
440440

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
442442
specify expected fields, the value of those fields as well as the format of
443443
field values in a resource that was returned by the Kubernetes API server from
444444
the result of a `kube.get` call.
445445

446446
Suppose you have a Deployment resource and you want to write a test that checks
447447
that a Deployment resource's `Status.ReadyReplicas` field is `2`.
448448

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,
450450
which is a `map[string]interface{}` that takes map keys that are JSONPath
451451
expressions and map values of what the field at that JSONPath expression should
452452
contain:
@@ -456,10 +456,10 @@ tests:
456456
- name: check deployment's ready replicas is 2
457457
kube:
458458
get: deployments/my-deployment
459-
assert:
460-
json:
461-
paths:
462-
$.status.readyReplicas: 2
459+
assert:
460+
json:
461+
paths:
462+
$.status.readyReplicas: 2
463463
```
464464

465465
JSONPath expressions can be fairly complex, allowing the test author to, for
@@ -471,14 +471,14 @@ tests:
471471
- name: check deployment's pod template "app" label is "nginx"
472472
kube:
473473
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
478478
```
479479

480480
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,
482482
keyed by JSONPath expression, of the data format the value of the field at that
483483
JSONPath expression should have. Valid data formats are:
484484

@@ -511,11 +511,11 @@ date-time timestamp:
511511
tests:
512512
- kube:
513513
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
519519
```
520520

521521
### Updating a resource and asserting corresponding field changes
@@ -564,10 +564,10 @@ tests:
564564
after: 20s
565565
kube:
566566
get: deployments/nginx
567-
assert:
568-
matches:
569-
status:
570-
readyReplicas: 2
567+
assert:
568+
matches:
569+
status:
570+
readyReplicas: 2
571571
- name: apply-deployment-change
572572
kube:
573573
apply: |
@@ -582,10 +582,10 @@ tests:
582582
after: 20s
583583
kube:
584584
get: deployments/nginx
585-
assert:
586-
matches:
587-
status:
588-
readyReplicas: 1
585+
assert:
586+
matches:
587+
status:
588+
readyReplicas: 1
589589
- name: delete-deployment
590590
kube:
591591
delete: deployments/nginx
@@ -619,16 +619,16 @@ tests:
619619
- name: deployment-exists
620620
kube:
621621
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
632632
- name: delete-deployment
633633
kube:
634634
delete: deployments/nginx
@@ -685,13 +685,13 @@ ok command-line-arguments 3.683s
685685

686686
You can see from the debug output above that `gdt` created the Deployment and
687687
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
689689
`status.readyReplicas` field was not present in the returned resource. `gdt`
690690
retried the `kube.get` call 4 more times (attempts 2-5), with attempts 2 and 3
691691
failed the existence check for the `status.readyReplicas` field and attempt 4
692692
failing the *value* check for the `status.readyReplicas` field being `1`
693693
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.
695695

696696
## Determining Kubernetes config, context and namespace values
697697

0 commit comments

Comments
 (0)