Skip to content

save and restore gdt variables in gdt-kube tests#23

Merged
a-hilaly merged 1 commit intogdt-dev:mainfrom
jaypipes:save-arbitrary
Sep 12, 2025
Merged

save and restore gdt variables in gdt-kube tests#23
a-hilaly merged 1 commit intogdt-dev:mainfrom
jaypipes:save-arbitrary

Conversation

@jaypipes
Copy link
Copy Markdown
Member

@jaypipes jaypipes commented Sep 12, 2025

Adds the gdt variable system functionality to the gdt-kube plugin, allowing test authors to define variables that should be populated from inspecting the results of the kube.get output and extracting an element using a JSONPath expression.

You can mix and match gdt test specs and the gdt variable system to pass values between test specs, allowing for a really extensible testing framework, like this example shows:

name: curl-pod-ip
description: scenario showing how to create two NGinx Pods and test connectivity to internal Pod IP addresses
fixtures:
  - kind
defaults:
  kube:
    namespace: curl-pod-ip
tests:
  - name: create-server
    kube:
      create: testdata/manifests/nginx-server.yaml

  - name: get-server-pod-ip
    kube:
      get: pods/server
    assert:
      conditions:
        ready:
          status: true
    var:
      SERVER_IP:
        from: $.status.podIP

  - name: create-connect-tester
    kube:
      create: testdata/manifests/nginx-connect-test.yaml

  - name: wait-connect-test-ready
    kube:
      get: pods/connect-test
    assert:
      conditions:
        ready:
          status: true

  - name: curl-server-from-connect-tester
    exec: kubectl exec -n curl-pod-ip pods/connect-test -- curl -s -I -v $$SERVER_IP
    timeout: 2s
    assert:
      out:
        contains: "200 OK"
      # curl -v causes output to be sent to stderr that looks like this:
      # * Connected to 10.244.0.17 (10.244.0.17) port 80 (#0)
      # > GET / HTTP/1.1
      # > Host: 10.244.0.17
      # > User-Agent: curl/7.88.1
      # > Accept: */*
      # >
      # < HTTP/1.1 200 OK
      err:
        contains: "Host: $$SERVER_IP"

  - name: delete-connect-tester
    kube:
      delete: pods/connect-test

  - name: delete-server
    kube:
      delete: pods/server

Issue gdt-dev/gdt#51

Adds the gdt variable system functionality to the gdt-kube plugin,
allowing test authors to define variables that should be populated from
inspecting the results of the kube.get output and extracting an element
using a JSONPath expression.

You can mix and match gdt test specs and the gdt variable system to pass
values between test specs, allowing for a really extensible testing
framework, like this example shows:

```
name: curl-pod-ip
description: scenario showing how to create two NGinx Pods and test connectivity to internal Pod IP addresses
fixtures:
  - kind
defaults:
  kube:
    namespace: curl-pod-ip
tests:
  - name: create-server
    kube:
      create: testdata/manifests/nginx-server.yaml

  - name: get-server-pod-ip
    kube:
      get: pods/server
    assert:
      conditions:
        ready:
          status: true
    var:
      SERVER_IP:
        from: $.status.podIP

  - name: create-connect-tester
    kube:
      create: testdata/manifests/nginx-connect-test.yaml

  - name: wait-connect-test-ready
    kube:
      get: pods/connect-test
    assert:
      conditions:
        ready:
          status: true

  - name: curl-server-from-connect-tester
    exec: kubectl exec -n curl-pod-ip pods/connect-test -- curl -s -I -v $$SERVER_IP
    timeout: 2s
    assert:
      out:
        contains: "200 OK"
      # curl -v causes output to be sent to stderr that looks like this:
      # * Connected to 10.244.0.17 (10.244.0.17) port 80 (#0)
      # > GET / HTTP/1.1
      # > Host: 10.244.0.17
      # > User-Agent: curl/7.88.1
      # > Accept: */*
      # >
      # < HTTP/1.1 200 OK
      err:
        contains: "Host: $$SERVER_IP"

  - name: delete-connect-tester
    kube:
      delete: pods/connect-test

  - name: delete-server
    kube:
      delete: pods/server
```

Issue gdt-dev/gdt#51

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
Copy link
Copy Markdown
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noiiice!

@a-hilaly a-hilaly merged commit a03c7e5 into gdt-dev:main Sep 12, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants