This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Reference

Composing features

1 - Step Definitions

Available step definitions for scenarios.

Composing a Scenario with Step Definitions

All steps should be prefixed with either ‘Given’, ‘When’, ‘Then’, ‘And’, ‘But’, ‘*’.

Once execution begins, for each step, Cucumber will look for a registered step definition with a matching Regexp. If it finds one, it will execute it, passing all capture group s and variables from the Regexp as arguments to the method.

The specific preposition/adverb used has no significance when Cucumber is registering or looking up step definitions.

a resource called <reference>

Assigns a reference to the resource given the in the DocString. This reference can be referred to in future steps in the same scenario. JSON and YAML formats are accepted.

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  data:
    foo: bar
  """
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
Additional Step Arguments: A Kubernetes manifest.
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/ Can be yaml or json depending on the content type.

I create <reference>

Creates the referenced resource. Step will fail if the reference was not defined in a previous step.

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  data:
    foo: bar
  """
And I create cm
  | field manager | example |
Then within 1s cm jsonpath '{.metadata.uid}' should not be empty
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

Additional Step Arguments: (optional) A table of additional client create options.

https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#CreateOptions

Create Options:
| dry run       | boolean |
| field manager | string  |

I delete <reference>

Deletes the referenced resource. Step will fail if the reference was not defined in a previous step.

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  data:
    foo: bar
  """
And I create cm
And I delete cm
  | grace period seconds | 30         |
  | propagation policy   | Foreground |
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

Additional Step Arguments: (optional) A table of additional client delete options.

https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#DeleteOptions

Delete Options:
| dry run              | boolean                        |
| grace period seconds | number                         |
| propagation policy   | (Orphan|Background|Foreground) |

I evict <reference>

Evicts the referenced pod resource. Step will fail if the pod reference was not defined in a previous step.

When I evict pod
  | grace period seconds | 120 |
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

Additional Step Arguments: (optional) A table of additional client delete options.

https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#DeleteOptions

Delete Options:
| dry run              | boolean                        |
| grace period seconds | number                         |
| propagation policy   | (Orphan|Background|Foreground) |

I exec <command> in <reference>/<container>

Executes the given command in a shell in the referenced pod and container.

When I exec "echo helloworld" in pod/app
<command>: The command to execute in the container.
https://kubernetes.io/docs/tasks/debug/debug-application/get-shell-running-container/ The command will run in a shell on the container and its outputs will be captured and can be asserted against in future steps.
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
<container>: The container name.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

I exec <command> in <reference>

Executes the given command in a shell in the referenced pod and default container.

When I exec "echo helloworld" in pod
<command>: The command to execute in the container.
https://kubernetes.io/docs/tasks/debug/debug-application/get-shell-running-container/ The command will run in a shell on the container and its outputs will be captured and can be asserted against in future steps.
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

I patch <reference>

Patches the referenced resource. Step will fail if the reference was not defined in a previous step.

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  data:
    foo: bar
  """
And I create cm
When I patch cm
  | patch | {"data":{"foo":"nobar"}} |
Then for at least 10s cm jsonpath '{.data.foo}' should equal nobar
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.

Additional Step Arguments: A table of additional client patch options.

https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#PatchOptions

Patch Options:
| patch         | string (required) |
| force         | boolean           |
| dry run       | boolean           |
| field manager | string            |

I proxy get <scheme>://<reference>:<port><path>

Create a proxy connection to the referenced pod resource and attempts a http(s) GET for the port and path. Step will fail if the reference was not defined in a previous step.

Given a resource called pod:
"""yaml
apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: default
spec:
  restartPolicy: Never
  containers:
  - command: ["busybox", "httpd", "-f", "-p", "8000"]
    image: busybox:latest
    name: server
"""
When I create pod
And within 1m pod jsonpath '{.status.phase}' should equal Running
And I proxy get http://app:8000/fake
Then pod response code should equal 404
<scheme>: The scheme of a URL.
Must be either http or https.
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
<port>: Port.
The port number to request. Acceptable range is 0 - 65536.
<path>: The path of a URL.
Anything that comes after port.

Additional Step Arguments: (optional) A freeform table of additional query parameters to send with the request.



ProxyGet Options:
| string | string |

<reference> logs (should|should not) say <text>

Asserts that the referenced resource will log something within the specified duration

Given a resource called testernetes:
  """
  apiVersion: v1
  kind: Pod
  metadata:
    name: testernetes
    namespace: default
  spec:
    restartPolicy: Never
    containers:
    - command:
      - /bdk
      - --help
      image: ghcr.io/testernetes/bdk:d408c829f019f2052badcb93282ee6bd3cdaf8d0
      name: bdk
  """
When I create testernetes
Then testernetes logs should say Behaviour Driven Kubernetes
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
(should|should not): A positive or negative assertion.
“to” can also be used instead of “should”.
<text>: A freeform amount of text.
This will match anything.

Additional Step Arguments: (optional) A table of additional client pod log options.

https://pkg.go.dev/k8s.io/api/core/v1#PodLogOptions

Pod Log Options:
| container     | string  |
| follow        | boolean |
| previous      | boolean |
| since seconds | number  |
| timestamps    | boolean |
| tail lines    | number  |
| limit bytes   | number  |

<assertion> <duration> <reference> logs (should|should not) say <text>

Asserts that the referenced resource will log something within the specified duration

Given a resource called testernetes:
  """
  apiVersion: v1
  kind: Pod
  metadata:
    name: testernetes
    namespace: default
  spec:
    restartPolicy: Never
    containers:
    - command:
      - /bdk
      - --help
      image: ghcr.io/testernetes/bdk:d408c829f019f2052badcb93282ee6bd3cdaf8d0
      name: bdk
  """
When I create testernetes
Then within 1m testernetes logs should say Behaviour Driven Kubernetes
  | container | bdk   |
  | follow    | false |
<assertion>: An assertion that state should be achieved or maintained.
Eventually assertions can be made with: ["" “within” “in less than” “in under” “in no more than”] Consistently assertions can be made with: [“for at least” “for no less than”]
<duration>: Duration from when the step starts.
https://pkg.go.dev/time#ParseDuration A duration is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as “300ms”, “1.5m” or “2h45m”. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
(should|should not): A positive or negative assertion.
“to” can also be used instead of “should”.
<text>: A freeform amount of text.
This will match anything.

Additional Step Arguments: (optional) A table of additional client pod log options.

https://pkg.go.dev/k8s.io/api/core/v1#PodLogOptions

Pod Log Options:
| container     | string  |
| follow        | boolean |
| previous      | boolean |
| since seconds | number  |
| timestamps    | boolean |
| tail lines    | number  |
| limit bytes   | number  |

<reference> jsonpath <jsonpath> (should|should not) <matcher>

Asserts that the referenced resource will satisfy the matcher

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  """
And I create cm
Then cm jsonpath '{.metadata.uid}' should not be empty
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
<jsonpath>: A JSON Path to a field in the referenced resource.
https://kubernetes.io/docs/reference/kubectl/jsonpath/ e.g. ‘{.metadata.name}’.
(should|should not): A positive or negative assertion.
“to” can also be used instead of “should”.
<matcher>: Used in conjunction with an assertion to assert that the actual matches the expected.
To list available matchers run ‘bdk matchers’.

<assertion> <duration> <reference> jsonpath <jsonpath> (should|should not) <matcher>

Asserts that the referenced resource will satisfy the matcher in the specified duration

Given a resource called cm:
  """
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example
    namespace: default
  """
And I create cm
Then within 1s cm jsonpath '{.metadata.uid}' should not be empty
<assertion>: An assertion that state should be achieved or maintained.
Eventually assertions can be made with: ["" “within” “in less than” “in under” “in no more than”] Consistently assertions can be made with: [“for at least” “for no less than”]
<duration>: Duration from when the step starts.
https://pkg.go.dev/time#ParseDuration A duration is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as “300ms”, “1.5m” or “2h45m”. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
<reference>: A short hand name for a resource.
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ A resource can be assigned to this reference in a Context step and later referred to in an Action or Outcome step. The reference must a name that can be used as a DNS subdomain name as defined in RFC 1123. This is the same Kubernetes requirement for names, i.e. lowercase alphanumeric characters.
<jsonpath>: A JSON Path to a field in the referenced resource.
https://kubernetes.io/docs/reference/kubectl/jsonpath/ e.g. ‘{.metadata.name}’.
(should|should not): A positive or negative assertion.
“to” can also be used instead of “should”.
<matcher>: Used in conjunction with an assertion to assert that the actual matches the expected.
To list available matchers run ‘bdk matchers’.

2 - Matchers

Matcher definitions that can be used in assertion steps.

Heading

Edit this template to create your new page.

  • Give it a good name, ending in .md - e.g. getting-started.md
  • Edit the “front matter” section at the top of the page (weight controls how its ordered amongst other pages in the same directory; lowest number first).
  • Add a good commit message at the bottom of the page (<80 characters; use the extended description field for more detail).
  • Create a new branch so you can preview your new file and request a review via Pull Request.