Skip to content

v1.0.0

Compare
Choose a tag to compare
@jaypipes jaypipes released this 26 Jul 16:25
· 32 commits to main since this release

Migration of github.com/jaypipes/gdt-kube to github.com/gdt-dev/kube.

To use gdt, define your tests in a YAML file or a directory containing YAML files, use the gdt.From() method to create a runnable test suite or scenario and then Run() it:

package mypackage_test

import (
	"context"
	"path/filepath"
	"testing"

	"github.com/gdt-dev/gdt"
	_ "github.com/gdt-dev/http"
	"github.com/stretchr/testify/require"
)

func TestRunASuite(t *testing.T) {
	require := assert.New(t)

	fp := filepath.Join("suite", "testdata", "http")
	s, err := gdt.From(fp)
	require.Nil(err)
	
	s.Run(context.TODO(), t)
}

func TestRunOneScenario(t *testing.T) {
	require := require.New(t)

	fp := filepath.Join("suite", "testdata", "http", "create-then-get-book.yaml")
	s, err := gdt.From(fp)
	require.Nil(err)

	s.Run(context.TODO(), t)
}

Example gdt-kube file: testdata/matches.yaml:

name: matches
description: create a deployment and check the matches condition succeeds
require:
  - kind
tests:
  - name: create-deployment
    kube:
      create: testdata/manifests/nginx-deployment.yaml
  - name: deployment-exists
    kube:
      get: deployments/nginx
      assert:
        matches:
          spec:
            replicas: 2
            template:
              metadata:
                labels:
                  app: nginx
          status:
            readyReplicas: 2
  - name: delete-deployment
    kube:
      delete: deployments/nginx

file: matches_test.go

import (
    "github.com/gdt-dev/gdt"
    _ "github.com/gdt-dev/kube"
    kindfix "github.com/gdt-dev/kube/fixture/kind"
)

func TestMatches(t *testing.T) {
	fp := filepath.Join("testdata", "matches.yaml")

	kfix := kindfix.New()

	s, err := gdt.From(fp)

	ctx := gdt.NewContext(gdt.WithDebug())
	ctx = gdt.RegisterFixture(ctx, "kind", kfix)
	s.Run(ctx, t)
}