From c5d6fd15d74f48513a042db37e3ba755e60dadaf Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Thu, 27 Jun 2024 09:24:41 +0200 Subject: [PATCH] Split acceptance tests up --- acceptance-tests/apply_test.go | 31 ++++++++++++++++++ acceptance-tests/export_test.go | 30 ++++++++++++++++++ acceptance-tests/help_test.go | 54 -------------------------------- acceptance-tests/helpers_test.go | 17 ++++++++++ 4 files changed, 78 insertions(+), 54 deletions(-) create mode 100644 acceptance-tests/apply_test.go create mode 100644 acceptance-tests/export_test.go create mode 100644 acceptance-tests/helpers_test.go diff --git a/acceptance-tests/apply_test.go b/acceptance-tests/apply_test.go new file mode 100644 index 000000000..ffbc5fa7f --- /dev/null +++ b/acceptance-tests/apply_test.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestApplyEnvironment(t *testing.T) { + tmpDir := t.TempDir() + os.Chdir(tmpDir) + runCmd(t, "tk", "init") + runCmd(t, "tk", "env", "set", "environments/default", "--server=https://kubernetes:6443") + content := ` + { + config: { + apiVersion: "v1", + kind: "ConfigMap", + metadata : { + name: "demo", + }, + data: {}, + }, + } +` + require.NoError(t, os.WriteFile("environments/default/main.jsonnet", []byte(content), 0600)) + runCmd(t, "tk", "apply", "environments/default", "--auto-approve", "always") + // Now that the configmap should be there, let's verify it + runCmd(t, "kubectl", "--namespace", "default", "get", "configmap", "demo") +} diff --git a/acceptance-tests/export_test.go b/acceptance-tests/export_test.go new file mode 100644 index 000000000..87470ff0e --- /dev/null +++ b/acceptance-tests/export_test.go @@ -0,0 +1,30 @@ +package main + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestExportEnvironment(t *testing.T) { + tmpDir := t.TempDir() + os.Chdir(tmpDir) + runCmd(t, "tk", "init") + runCmd(t, "tk", "env", "set", "environments/default", "--server=https://kubernetes:6443") + content := ` + { + config: { + apiVersion: "v1", + kind: "ConfigMap", + metadata : { + name: "demo", + }, + data: {}, + }, + } +` + require.NoError(t, os.WriteFile("environments/default/main.jsonnet", []byte(content), 0600)) + runCmd(t, "tk", "export", "export", "environments/default") + require.FileExists(t, "export/v1.ConfigMap-demo.yaml") +} diff --git a/acceptance-tests/help_test.go b/acceptance-tests/help_test.go index e9d6eee99..05223feed 100644 --- a/acceptance-tests/help_test.go +++ b/acceptance-tests/help_test.go @@ -1,7 +1,6 @@ package main import ( - "os" "os/exec" "testing" @@ -13,56 +12,3 @@ func TestHelp(t *testing.T) { require.NoError(t, err) require.Contains(t, string(output), "Usage") } - -func TestApplyEnvironment(t *testing.T) { - tmpDir := t.TempDir() - os.Chdir(tmpDir) - runCmd(t, "tk", "init") - runCmd(t, "tk", "env", "set", "environments/default", "--server=https://kubernetes:6443") - content := ` - { - config: { - apiVersion: "v1", - kind: "ConfigMap", - metadata : { - name: "demo", - }, - data: {}, - }, - } -` - require.NoError(t, os.WriteFile("environments/default/main.jsonnet", []byte(content), 0600)) - runCmd(t, "tk", "apply", "environments/default", "--auto-approve", "always") - // Now that the configmap should be there, let's verify it - runCmd(t, "kubectl", "--namespace", "default", "get", "configmap", "demo") -} - -func TestExportEnvironment(t *testing.T) { - tmpDir := t.TempDir() - os.Chdir(tmpDir) - runCmd(t, "tk", "init") - runCmd(t, "tk", "env", "set", "environments/default", "--server=https://kubernetes:6443") - content := ` - { - config: { - apiVersion: "v1", - kind: "ConfigMap", - metadata : { - name: "demo", - }, - data: {}, - }, - } -` - require.NoError(t, os.WriteFile("environments/default/main.jsonnet", []byte(content), 0600)) - runCmd(t, "tk", "export", "export", "environments/default") - require.FileExists(t, "export/v1.ConfigMap-demo.yaml") -} - -func runCmd(t *testing.T, cmd string, args ...string) { - c := exec.Command(cmd, args...) - c.Stdout = os.Stdout - c.Stderr = os.Stderr - err := c.Run() - require.NoError(t, err) -} diff --git a/acceptance-tests/helpers_test.go b/acceptance-tests/helpers_test.go new file mode 100644 index 000000000..0b325bbf8 --- /dev/null +++ b/acceptance-tests/helpers_test.go @@ -0,0 +1,17 @@ +package main + +import ( + "os" + "os/exec" + "testing" + + "github.com/stretchr/testify/require" +) + +func runCmd(t *testing.T, cmd string, args ...string) { + c := exec.Command(cmd, args...) + c.Stdout = os.Stdout + c.Stderr = os.Stderr + err := c.Run() + require.NoError(t, err) +}