diff --git a/Makefile b/Makefile index e2624db6c4..a6e1b57f46 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ integration-test-dev: build ## Run the integration tests without cluster teardow @./eksctl utils write-kubeconfig \ --auto-kubeconfig \ --name=$(TEST_CLUSTER) - @go test -tags integration -v -timeout 21m ./tests/integration/... \ + @go test -tags integration -v -timeout 21m ./integration/... \ -args \ -eksctl.cluster=$(TEST_CLUSTER) \ -eksctl.create=false \ @@ -56,7 +56,7 @@ delete-integration-test-dev-cluster: build ## Delete the test cluster for use wh .PHONY: integration-test integration-test: build ## Run the integration tests (with cluster creation and cleanup) - @go test -tags integration -v -timeout 21m ./tests/integration/... + @go test -tags integration -v -timeout 21m ./integration/... ##@ Code Generation diff --git a/tests/integration/create_get_delete/integration_test.go b/integration/creategetdelete_test.go similarity index 80% rename from tests/integration/create_get_delete/integration_test.go rename to integration/creategetdelete_test.go index f4b16073c7..166c5b3565 100644 --- a/tests/integration/create_get_delete/integration_test.go +++ b/integration/creategetdelete_test.go @@ -1,14 +1,12 @@ // +build integration -package create_get_delete +package integration_test import ( - "flag" "fmt" "io/ioutil" "os" "os/exec" - "testing" "time" awseks "github.com/aws/aws-sdk-go/service/eks" @@ -26,30 +24,6 @@ import ( "github.com/weaveworks/eksctl/pkg/utils" ) -const ( - createTimeout = 20 - deleteTimeout = 10 - getTimeout = 1 - region = "us-west-2" -) - -var ( - eksctlPath string - - // Flags to help with the development of the integration tests - clusterName string - doCreate bool - doDelete bool - kubeconfigPath string - - kubeconfigTemp bool -) - -func TestCreateIntegration(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Integration - Create Suite") -} - type tInterface interface { GinkgoTInterface Helper() @@ -73,7 +47,7 @@ func newKubeTest() (*harness.Test, error) { return h.NewTest(t), nil } -var _ = Describe("Create (Integration)", func() { +var _ = Describe("(Integration) Create, Get & Delete", func() { BeforeSuite(func() { kubeconfigTemp = false @@ -107,7 +81,7 @@ var _ = Describe("Create (Integration)", func() { args := []string{"create", "cluster", "--name", clusterName, - "--tags", "Purpose=ekscltIntegrationTest", + "--tags", "eksctl.cluster.k8s.io/v1alpha1/description=eksctl integration test", "--node-type", "t2.medium", "--nodes", "1", "--region", region, @@ -121,7 +95,7 @@ var _ = Describe("Create (Integration)", func() { Fail(fmt.Sprintf("error starting process: %v", err), 1) } - cmdSession.Wait(createTimeout * time.Minute) + cmdSession.Wait(createTimeout) Expect(cmdSession.ExitCode()).Should(Equal(0)) }) @@ -193,8 +167,6 @@ var _ = Describe("Create (Integration)", func() { var err error args := []string{"get", "clusters", "--region", region} - fmt.Printf("wtf[eksctlPath]: '%s'", eksctlPath) - command := exec.Command(eksctlPath, args...) cmdSession, err = gexec.Start(command, GinkgoWriter, GinkgoWriter) @@ -202,7 +174,7 @@ var _ = Describe("Create (Integration)", func() { Fail(fmt.Sprintf("error starting process: %v", err), 1) } - cmdSession.Wait(getTimeout * time.Minute) + cmdSession.Wait(getTimeout) Expect(cmdSession.ExitCode()).Should(Equal(0)) }) @@ -217,7 +189,11 @@ var _ = Describe("Create (Integration)", func() { Skip("will not delete cluster " + clusterName) } - args := []string{"delete", "cluster", "--name", clusterName, "--region", region, "--wait"} + args := []string{"delete", "cluster", + "--name", clusterName, + "--region", region, + "--wait", + } command := exec.Command(eksctlPath, args...) cmdSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) @@ -226,7 +202,7 @@ var _ = Describe("Create (Integration)", func() { Fail(fmt.Sprintf("error starting process: %v", err), 1) } - cmdSession.Wait(deleteTimeout * time.Minute) + cmdSession.Wait(deleteTimeout) Expect(cmdSession.ExitCode()).Should(Equal(0)) }) @@ -251,13 +227,3 @@ var _ = Describe("Create (Integration)", func() { }) }) }) - -func init() { - flag.StringVar(&eksctlPath, "eksctl.path", "../../../eksctl", "Path to eksctl") - - // Flags to help with the development of the integration tests - flag.StringVar(&clusterName, "eksctl.cluster", "", "Cluster name (default: generate one)") - flag.BoolVar(&doCreate, "eksctl.create", true, "Skip the creation tests. Useful for debugging the tests") - flag.BoolVar(&doDelete, "eksctl.delete", true, "Skip the cleanup after the tests have run") - flag.StringVar(&kubeconfigPath, "eksctl.kubeconfig", "", "Path to kubeconfig (default: create it a temporary file)") -} diff --git a/integration/integration_test.go b/integration/integration_test.go new file mode 100644 index 0000000000..5df565bb6f --- /dev/null +++ b/integration/integration_test.go @@ -0,0 +1,48 @@ +// +build integration + +package integration_test + +import ( + "flag" + "testing" + "time" + + "github.com/weaveworks/eksctl/pkg/eks/api" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +const ( + createTimeout = 25 * time.Minute + deleteTimeout = 15 * time.Minute + getTimeout = 1 * time.Minute + region = api.DefaultEKSRegion +) + +var ( + eksctlPath string + + // Flags to help with the development of the integration tests + clusterName string + doCreate bool + doDelete bool + kubeconfigPath string + + kubeconfigTemp bool +) + +func init() { + flag.StringVar(&eksctlPath, "eksctl.path", "../eksctl", "Path to eksctl") + + // Flags to help with the development of the integration tests + flag.StringVar(&clusterName, "eksctl.cluster", "", "Cluster name (default: generate one)") + flag.BoolVar(&doCreate, "eksctl.create", true, "Skip the creation tests. Useful for debugging the tests") + flag.BoolVar(&doDelete, "eksctl.delete", true, "Skip the cleanup after the tests have run") + flag.StringVar(&kubeconfigPath, "eksctl.kubeconfig", "", "Path to kubeconfig (default: create it a temporary file)") +} + +func TestCreateIntegration(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "(Integration) Create, Get & Delete") +} diff --git a/tests/integration/create_get_delete/podinfo.yaml b/integration/podinfo.yaml similarity index 100% rename from tests/integration/create_get_delete/podinfo.yaml rename to integration/podinfo.yaml diff --git a/pkg/testutils/aws/eks.go b/pkg/testutils/aws/eks.go deleted file mode 100644 index 8c243e8251..0000000000 --- a/pkg/testutils/aws/eks.go +++ /dev/null @@ -1,30 +0,0 @@ -package aws - -import ( - "strings" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - awseks "github.com/aws/aws-sdk-go/service/eks" -) - -// ClusterExists checks if an EKS cluster exists in AWS -func ClusterExists(clusterName string, session *session.Session) (bool, error) { - eks := awseks.New(session) - - input := &awseks.DescribeClusterInput{ - Name: aws.String(clusterName), - } - _, err := eks.DescribeCluster(input) - - if err != nil { - // Check if its a not found error: ResourceNotFoundException - if !strings.Contains(err.Error(), awseks.ErrCodeResourceNotFoundException) { - return false, err - } - - return false, nil - } - - return true, nil -} diff --git a/pkg/testutils/matchers/have_cfn_stack_matcher.go b/pkg/testutils/matchers/have_cfn_stack_matcher.go index 3f5e4fc2d2..35c744ac11 100644 --- a/pkg/testutils/matchers/have_cfn_stack_matcher.go +++ b/pkg/testutils/matchers/have_cfn_stack_matcher.go @@ -12,15 +12,15 @@ import ( // HaveExistingStack returns a GoMega matcher that will check for the existence of an cloudformation stack func HaveExistingStack(expectedStackName string) types.GomegaMatcher { - return &ExistingStack{expectedStackName: expectedStackName} + return &existingStack{expectedStackName: expectedStackName} } -type ExistingStack struct { +type existingStack struct { expectedStackName string stackNotFound bool } -func (m *ExistingStack) Match(actual interface{}) (success bool, err error) { +func (m *existingStack) Match(actual interface{}) (success bool, err error) { if actual == nil { return false, errors.New("input is nil") } @@ -39,10 +39,10 @@ func (m *ExistingStack) Match(actual interface{}) (success bool, err error) { return found, nil } -func (m *ExistingStack) FailureMessage(actual interface{}) (message string) { +func (m *existingStack) FailureMessage(actual interface{}) (message string) { return fmt.Sprintf("Expected to find a Cloudformation stack named %s but it wasn't found", m.expectedStackName) } -func (m *ExistingStack) NegatedFailureMessage(_ interface{}) (message string) { +func (m *existingStack) NegatedFailureMessage(_ interface{}) (message string) { return fmt.Sprintf("Expected NOT to find a Cloudformation stack named %s but it found", m.expectedStackName) } diff --git a/tests/integration/cleanup.go b/tests/integration/cleanup.go deleted file mode 100644 index 6d2d4a0adb..0000000000 --- a/tests/integration/cleanup.go +++ /dev/null @@ -1,20 +0,0 @@ -package integration - -// // CleanupStacks cleans up the created AWS infrastructure -// func CleanupStacks(clusterName string, region string) { -// session := aws.NewSession(region) - -// stackName := fmt.Sprintf("eksctl-%s-cluster", clusterName) -// if found, _ := aws.StackExists(stackName, session); found { -// if err := aws.DeleteStackWait(stackName, session); err != nil { -// logger.Debug("Cluster stack couldn't be deleted: %v", err) -// } -// } - -// stackName = fmt.Sprintf("eksctl-%s-nodegroup-%d", clusterName, 0) -// if found, _ := aws.StackExists(stackName, session); found { -// if err := aws.DeleteStack(stackName, session); err != nil { -// logger.Debug("NodeGroup stack couldn't be deleted: %v", err) -// } -// } -// }