diff --git a/pkg/driver/kubernetes_integration_test.go b/pkg/driver/kubernetes_integration_test.go new file mode 100644 index 00000000..64e689f3 --- /dev/null +++ b/pkg/driver/kubernetes_integration_test.go @@ -0,0 +1,62 @@ +// +build integration + +package driver + +import ( + "bytes" + "testing" + + "github.com/deislabs/cnab-go/driver" + "github.com/stretchr/testify/assert" +) + +func TestKubernetesRun(t *testing.T) { + namespace := "default" + k := &KubernetesDriver{} + k.SetConfig(map[string]string{ + "KUBE_NAMESPACE": namespace, + }) + k.ActiveDeadlineSeconds = 60 + + cases := []struct { + name string + op *driver.Operation + output string + err error + }{ + { + name: "install", + op: &driver.Operation{ + Installation: "example", + Action: "install", + Image: "cnab/helloworld:latest", + Environment: map[string]string{ + "PORT": "3000", + }, + }, + output: "Port parameter was set to 3000\nInstall action\nAction install complete for example\n", + err: nil, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var output bytes.Buffer + tc.op.Out = &output + if tc.op.Environment == nil { + tc.op.Environment = map[string]string{} + } + tc.op.Environment["CNAB_ACTION"] = tc.op.Action + tc.op.Environment["CNAB_INSTALLATION_NAME"] = tc.op.Installation + + err := k.Run(tc.op) + + if tc.err != nil { + assert.EqualError(t, err, tc.err.Error()) + } else { + assert.NoError(t, err) + } + assert.Equal(t, tc.output, output.String()) + }) + } +}