Skip to content

Commit

Permalink
Integration test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
r2d4 committed Sep 8, 2017
1 parent c793299 commit b92a23e
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 77 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ test-iso:

.PHONY: integration
integration: out/minikube
go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS)" --minikube-args="$(MINIKUBE_ARGS)"
go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS)" $(TEST_ARGS)

.PHONY: integration-none-driver
integration-none-driver: e2e-linux-amd64 out/minikube-linux-amd64
sudo -E out/e2e-linux-amd64 -testdata-dir "test/integration/testdata" -minikube-args="--vm-driver=none --alsologtostderr" -test.v -test.timeout=30m -binary=out/minikube-linux-amd64

.PHONY: integration-versioned
integration-versioned: out/minikube
go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS) versioned" --minikube-args="$(MINIKUBE_ARGS)"
go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS) versioned" $(TEST_ARGS)

.PHONY: test
test: pkg/minikube/assets/assets.go
Expand Down
2 changes: 1 addition & 1 deletion hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ find ~/.minikube || true

# Allow this to fail, we'll switch on the return code below.
set +e
${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-args="--vm-driver=${VM_DRIVER} --v=10 --logtostderr ${EXTRA_ARGS}" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH}
${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-start-args="--vm-driver=${VM_DRIVER}" -minikube-args="--v=10 --logtostderr ${EXTRA_ARGS}" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH}
result=$?
set -e

Expand Down
11 changes: 2 additions & 9 deletions test/integration/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ func testAddons(t *testing.T) {

func testDashboard(t *testing.T) {
t.Parallel()
minikubeRunner := util.MinikubeRunner{
BinaryPath: *binaryPath,
Args: *args,
T: t,
}
minikubeRunner := NewMinikubeRunner(t)

if err := util.WaitForDashboardRunning(t); err != nil {
t.Fatalf("waiting for dashboard to be up: %s", err)
Expand All @@ -74,10 +70,7 @@ func testDashboard(t *testing.T) {

func testServicesList(t *testing.T) {
t.Parallel()
minikubeRunner := util.MinikubeRunner{
BinaryPath: *binaryPath,
Args: *args,
T: t}
minikubeRunner := NewMinikubeRunner(t)

checkServices := func() error {
output := minikubeRunner.RunCommand("service list", false)
Expand Down
18 changes: 16 additions & 2 deletions test/integration/cluster_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strings"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkgutil "k8s.io/minikube/pkg/util"

"k8s.io/minikube/test/integration/util"
)

Expand All @@ -33,9 +36,12 @@ func testClusterDNS(t *testing.T) {
}

kubectlRunner := util.NewKubectlRunner(t)
podName := "busybox"
podPath := filepath.Join(*testdataDir, "busybox.yaml")
defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath})

client, err := pkgutil.GetClient()
if err != nil {
t.Fatalf("Error getting kubernetes client %s", err)
}

if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
t.Fatalf("creating busybox pod: %s", err)
Expand All @@ -44,6 +50,14 @@ func testClusterDNS(t *testing.T) {
if err := util.WaitForBusyboxRunning(t, "default"); err != nil {
t.Fatalf("Waiting for busybox pod to be up: %s", err)
}
listOpts := metav1.ListOptions{LabelSelector: "integration-test=busybox"}
pods, err := client.CoreV1().Pods("default").List(listOpts)
if len(pods.Items) == 0 {
t.Fatal("Expected a busybox pod to be running")
}

podName := pods.Items[0].Name
defer kubectlRunner.RunCommand([]string{"delete", "po", podName})

dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName,
"nslookup", "kubernetes"})
Expand Down
5 changes: 1 addition & 4 deletions test/integration/cluster_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import (
func testClusterEnv(t *testing.T) {
t.Parallel()

minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

dockerEnvVars := minikubeRunner.RunCommand("docker-env", true)
if err := minikubeRunner.SetEnvFromEnvCmdOutput(dockerEnvVars); err != nil {
Expand Down
9 changes: 2 additions & 7 deletions test/integration/cluster_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ package integration
import (
"strings"
"testing"

"k8s.io/minikube/test/integration/util"
)

func testClusterLogs(t *testing.T) {
t.Parallel()
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)
minikubeRunner.EnsureRunning()
logsCmdOutput := minikubeRunner.GetLogs()

logsCmdOutput := minikubeRunner.RunCommand("logs", true)
//check for # of lines or check for strings
logWords := []string{"minikube", ".go"}
for _, logWord := range logWords {
Expand Down
8 changes: 1 addition & 7 deletions test/integration/cluster_ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ package integration
import (
"strings"
"testing"

"k8s.io/minikube/test/integration/util"
)

func testClusterSSH(t *testing.T) {
t.Parallel()
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}

minikubeRunner := NewMinikubeRunner(t)
expectedStr := "hello"
sshCmdOutput := minikubeRunner.RunCommand("ssh echo "+expectedStr, true)
if !strings.Contains(sshCmdOutput, expectedStr) {
Expand Down
9 changes: 2 additions & 7 deletions test/integration/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@ import (
"fmt"
"strings"
"testing"

"k8s.io/minikube/test/integration/util"
)

func TestDocker(t *testing.T) {
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

if strings.Contains(*args, "--vm-driver=none") {
t.Skip("skipping test as none driver does not bundle docker")
}

minikubeRunner.RunCommand("delete", false)
startCmd := fmt.Sprintf("start %s %s", minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
startCmd := fmt.Sprintf("start %s %s %s", minikubeRunner.StartArgs, minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
minikubeRunner.RunCommand(startCmd, true)
minikubeRunner.EnsureRunning()

Expand Down
12 changes: 12 additions & 0 deletions test/integration/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"flag"
"os"
"testing"

"k8s.io/minikube/test/integration/util"
)

func TestMain(m *testing.M) {
Expand All @@ -29,4 +31,14 @@ func TestMain(m *testing.M) {

var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary")
var args = flag.String("minikube-args", "", "Arguments to pass to minikube")
var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start")
var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives")

func NewMinikubeRunner(t *testing.T) util.MinikubeRunner {
return util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
StartArgs: *startArgs,
T: t,
}
}
6 changes: 1 addition & 5 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ import (

"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/test/integration/util"
)

func TestFunctional(t *testing.T) {
minikubeRunner := util.MinikubeRunner{
BinaryPath: *binaryPath,
Args: *args,
T: t}
minikubeRunner := NewMinikubeRunner(t)
minikubeRunner.EnsureRunning()
integrationTestImages := []string{"busybox:glibc"}
if err := machine.CacheImages(integrationTestImages, constants.ImageCacheDir); err != nil {
Expand Down
22 changes: 4 additions & 18 deletions test/integration/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ import (
"fmt"
"strings"
"testing"

"k8s.io/minikube/test/integration/util"
)

func TestISO(t *testing.T) {

minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

minikubeRunner.RunCommand("delete", true)
minikubeRunner.Start()
Expand All @@ -42,10 +37,7 @@ func TestISO(t *testing.T) {
}

func testMountPermissions(t *testing.T) {
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)
// test mount permissions
mountPoints := []string{"/Users", "/hosthome"}
perms := "drwxr-xr-x"
Expand All @@ -67,10 +59,7 @@ func testMountPermissions(t *testing.T) {
}

func testPackages(t *testing.T) {
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

packages := []string{
"git",
Expand All @@ -92,10 +81,7 @@ func testPackages(t *testing.T) {
}

func testPersistence(t *testing.T) {
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

for _, dir := range []string{
"/data",
Expand Down
5 changes: 1 addition & 4 deletions test/integration/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func testMounting(t *testing.T) {
if strings.Contains(*args, "--vm-driver=none") {
t.Skip("skipping test for none driver as it does not need mount")
}
minikubeRunner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
minikubeRunner := NewMinikubeRunner(t)

tempDir, err := ioutil.TempDir("", "mounttest")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestPersistence(t *testing.T) {
minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
minikubeRunner := NewMinikubeRunner(t)
minikubeRunner.EnsureRunning()

kubectlRunner := util.NewKubectlRunner(t)
Expand Down
5 changes: 1 addition & 4 deletions test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import (

func TestStartStop(t *testing.T) {

runner := util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
T: t}
runner := NewMinikubeRunner(t)
runner.RunCommand("delete", false)
runner.CheckStatus(state.None.String())

Expand Down
9 changes: 7 additions & 2 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type MinikubeRunner struct {
T *testing.T
BinaryPath string
Args string
StartArgs string
}

func (m *MinikubeRunner) Run(cmd string) error {
Expand Down Expand Up @@ -103,7 +104,7 @@ func (m *MinikubeRunner) SSH(command string) (string, error) {
}

func (m *MinikubeRunner) Start() {
m.RunCommand(fmt.Sprintf("start %s", m.Args), true)
m.RunCommand(fmt.Sprintf("start %s %s", m.StartArgs, m.Args), true)
}

func (m *MinikubeRunner) EnsureRunning() {
Expand All @@ -129,7 +130,11 @@ func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
}

func (m *MinikubeRunner) GetStatus() string {
return m.RunCommand("status --format={{.MinikubeStatus}}", true)
return m.RunCommand(fmt.Sprintf("status --format={{.MinikubeStatus}} %s", m.Args), true)
}

func (m *MinikubeRunner) GetLogs() string {
return m.RunCommand(fmt.Sprintf("logs %s", m.Args), true)
}

func (m *MinikubeRunner) CheckStatus(desired string) {
Expand Down
5 changes: 1 addition & 4 deletions test/integration/versioned_functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ func TestVersionedFunctional(t *testing.T) {
var minikubeRunner util.MinikubeRunner
for _, version := range k8sVersions {
vArgs := fmt.Sprintf("%s --kubernetes-version %s", *args, version.Version)
minikubeRunner = util.MinikubeRunner{
BinaryPath: *binaryPath,
Args: vArgs,
T: t}
minikubeRunner = NewMinikubeRunner(t)
minikubeRunner.EnsureRunning()

t.Run("Status", testClusterStatus)
Expand Down

0 comments on commit b92a23e

Please sign in to comment.