v1.0.0
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)
}