Skip to content

Commit

Permalink
Imporve integration test helpers
Browse files Browse the repository at this point in the history
- move misc integration test matchers into subpackage
- create command runner abstraction with matchers
  • Loading branch information
errordeveloper committed Aug 23, 2019
1 parent fdd77d4 commit 44cad01
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"^pkg\/testutils\/(ginkgo|client).go",
"^pkg\/testutils\/mockprovider\/mock_provider.go",
"^pkg\/cfn\/template\/matchers\/matchers.go",
"^integration\/matchers\/matchers.go",
"^integration\/runner\/runner.go",
"^pkg\/drain",
"^vendor\/github.com\/awslabs\/goformation"
],
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ unit-test-race: ## Run unit test with race detection

.PHONY: build-integration-test
build-integration-test: $(GENERATED_GO_FILES) ## Build integration test binary
time go test -tags integration ./integration/... -c -o eksctl-integration-test
time go test -tags integration ./integration/ -c -o eksctl-integration-test

.PHONY: integration-test
integration-test: build build-integration-test ## Run the integration tests (with cluster creation and cleanup)
Expand Down
63 changes: 0 additions & 63 deletions integration/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
package integration_test

import (
"fmt"
"os"
"os/exec"
"time"

harness "github.com/dlespiau/kube-test-harness"
"github.com/dlespiau/kube-test-harness/logger"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

type tHelper struct{ GinkgoTInterface }
Expand All @@ -35,59 +28,3 @@ func newKubeTest() (*harness.Test, error) {
test.Setup()
return test, nil
}

type params struct {
Args []string
Env []string
}

func eksctl(params params) *gexec.Session {
command := exec.Command(eksctlPath, params.Args...)
params.Env = append(params.Env, "EKSCTL_EXPERIMENTAL=true")
command.Env = append(os.Environ(), params.Env...)
fmt.Fprintf(GinkgoWriter, "calling %q with %v and %v\n", eksctlPath, params.Env, params.Args)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).To(BeNil())

t := time.Minute
switch params.Args[0] {
case "create":
t *= 25
case "delete":
t *= 15
case "get":
t *= 1
case "scale":
t *= 5
default:
t *= 30
}
session.Wait(t)
return session
}

func eksctlSuccess(args ...string) *gexec.Session {
return eksctlSuccessWith(params{Args: args})
}

func eksctlSuccessWith(params params) *gexec.Session {
session := eksctl(params)
Expect(session.ExitCode()).To(BeZero())
return session
}

func eksctlFail(args ...string) *gexec.Session {
session := eksctl(params{Args: args})
Expect(session.ExitCode()).ToNot(BeZero())
return session
}

//eksctlStart starts running an eksctl command but doesn't wait for it to finish the command
//This is primarily so that we can run eksctl create and then subsequently call eksctl delete
//on the same cluster, but might be useful for other test scenarios as well.
func eksctlStart(args ...string) {
fmt.Fprintf(GinkgoWriter, "calling %q with %v\n", eksctlPath, args)
cmd := exec.Command(eksctlPath, args...)
err := cmd.Start()
Expect(err).To(BeNil())
}
21 changes: 12 additions & 9 deletions integration/createdeletebeforeactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/weaveworks/eksctl/integration/matchers"
. "github.com/weaveworks/eksctl/integration/runner"

"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/testutils/aws"
. "github.com/weaveworks/eksctl/pkg/testutils/matchers"
)

const (
Expand All @@ -33,7 +34,8 @@ var _ = Describe("(Integration) Create & Delete before Active", func() {

Context("when creating a new cluster", func() {
It("should not return an error", func() {
eksctlStart("create", "cluster",
cmd := eksctlCreateCmd.WithArgs(
"cluster",
"--verbose", "4",
"--name", delBeforeActiveName,
"--tags", "alpha.eksctl.io/description=eksctl delete before active test",
Expand All @@ -44,28 +46,29 @@ var _ = Describe("(Integration) Create & Delete before Active", func() {
"--region", region,
"--version", version,
)
cmd.Start()
})

It("should eventually show up as creating", func() {
awsSession := aws.NewSession(region)
awsSession := NewSession(region)
Eventually(awsSession, timeOut, pollInterval).Should(
HaveExistingCluster(delBeforeActiveName, awseks.ClusterStatusCreating, version))
})
})

Context("when deleting the cluster in process of being created", func() {
It("deleting cluster should have a zero exitcode", func() {
eksctlSuccess("delete", "cluster",
"--verbose", "4",
cmd := eksctlDeleteClusterCmd.WithArgs(
"--name", delBeforeActiveName,
"--region", region,
)
Expect(cmd).To(RunSuccessfully())
})
})

Context("after the delete of the cluster in progress has been initiated", func() {
It("should eventually delete the EKS cluster and both CloudFormation stacks", func() {
awsSession := aws.NewSession(region)
awsSession := NewSession(region)
Eventually(awsSession, timeOut, pollInterval).ShouldNot(
HaveExistingCluster(delBeforeActiveName, awseks.ClusterStatusActive, version))
Eventually(awsSession, timeOut, pollInterval).ShouldNot(
Expand All @@ -77,11 +80,11 @@ var _ = Describe("(Integration) Create & Delete before Active", func() {

Context("when trying to delete the cluster again", func() {
It("should return an a non-zero exit code", func() {
eksctlFail("delete", "cluster",
"--verbose", "4",
cmd := eksctlDeleteClusterCmd.WithArgs(
"--name", delBeforeActiveName,
"--region", region,
)
Expect(cmd).To(RunSuccessfully())
})
})
})
Loading

0 comments on commit 44cad01

Please sign in to comment.