Skip to content

Commit

Permalink
Split acceptance tests up
Browse files Browse the repository at this point in the history
  • Loading branch information
zerok committed Jun 27, 2024
1 parent b302008 commit c5d6fd1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 54 deletions.
31 changes: 31 additions & 0 deletions acceptance-tests/apply_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
30 changes: 30 additions & 0 deletions acceptance-tests/export_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
54 changes: 0 additions & 54 deletions acceptance-tests/help_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"os"
"os/exec"
"testing"

Expand All @@ -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)
}
17 changes: 17 additions & 0 deletions acceptance-tests/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c5d6fd1

Please sign in to comment.