Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & cleanup integration test #264

Merged
merged 5 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ run:
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- ^vendor\/
- ^build\/
- ^pkg\/nodebootstrap\/assets.go
- ^pkg\/testutils\/
- ^pkg\/eks\/mocks\/
- ^tests\/
- ^vendor$
- ^build$
- ^pkg\/eks\/mocks$
- \/usr\/local\/go

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
#skip-files:
skip-files:
# - ".*\\.my\\.go$"
# - lib/bad.go
- pkg/nodebootstrap/assets.go


# output configuration options
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 60m ./integration/...

##@ Code Generation

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -24,33 +22,8 @@ import (
"github.com/weaveworks/eksctl/pkg/testutils/aws"
. "github.com/weaveworks/eksctl/pkg/testutils/matchers"
"github.com/weaveworks/eksctl/pkg/utils"
"github.com/weaveworks/eksctl/tests/integration"
)

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()
Expand All @@ -74,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
Expand All @@ -91,17 +64,9 @@ var _ = Describe("Create (Integration)", func() {
if kubeconfigTemp {
os.Remove(kubeconfigPath)
}
if doCreate && doDelete {
integration.CleanupAws(clusterName, region)
}
})

Describe("when creating a cluster with 1 node", func() {
var (
err error
session *gexec.Session
)

It("should not return an error", func() {
if !doCreate {
fmt.Fprintf(GinkgoWriter, "will use existing cluster %s", clusterName)
Expand All @@ -116,34 +81,33 @@ 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,
"--kubeconfig", kubeconfigPath,
}

command := exec.Command(eksctlPath, args...)
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
cmdSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}

session.Wait(createTimeout * time.Minute)
Expect(session.ExitCode()).Should(Equal(0))
cmdSession.Wait(createTimeout)
Expect(cmdSession.ExitCode()).Should(Equal(0))
})

awsSession := aws.NewSession(region)

It("should have created an EKS cluster", func() {
session := aws.NewSession(region)
Expect(session).To(HaveEksCluster(clusterName, awseks.ClusterStatusActive, "1.10"))
Expect(awsSession).To(HaveExistingCluster(clusterName, awseks.ClusterStatusActive, "1.10"))
})

It("should have the required cloudformation stacks", func() {
session := aws.NewSession(region)

Expect(session).To(HaveCfnStack(fmt.Sprintf("eksctl-%s-cluster", clusterName)))
Expect(session).To(HaveCfnStack(fmt.Sprintf("eksctl-%s-nodegroup-%d", clusterName, 0)))
Expect(awsSession).To(HaveExistingStack(fmt.Sprintf("eksctl-%s-cluster", clusterName)))
Expect(awsSession).To(HaveExistingStack(fmt.Sprintf("eksctl-%s-nodegroup-%d", clusterName, 0)))
})

It("should have created a valid kubectl config file", func() {
Expand All @@ -159,7 +123,10 @@ var _ = Describe("Create (Integration)", func() {
})

Context("and we create a deployment using kubectl", func() {
var test *harness.Test
var (
err error
test *harness.Test
)

BeforeEach(func() {
test, err = newKubeTest()
Expand Down Expand Up @@ -193,79 +160,70 @@ var _ = Describe("Create (Integration)", func() {
}
})
})
})

Describe("when listing clusters", func() {
var (
err error
session *gexec.Session
)
Context("and listing clusters", func() {
var cmdSession *gexec.Session
It("should not return an error", func() {
var err error
args := []string{"get", "clusters", "--region", region}

It("should not return an error", func() {
args := []string{"get", "cluster", "--region", region}
command := exec.Command(eksctlPath, args...)
cmdSession, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)

command := exec.Command(eksctlPath, args...)
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}

if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}
cmdSession.Wait(getTimeout)
Expect(cmdSession.ExitCode()).Should(Equal(0))
})

session.Wait(getTimeout * time.Minute)
Expect(session.ExitCode()).Should(Equal(0))
It("should return the previously created cluster", func() {
Expect(string(cmdSession.Buffer().Contents())).To(ContainSubstring(clusterName))
})
})

It("should return the previously created cluster", func() {
Expect(string(session.Buffer().Contents())).To(ContainSubstring(clusterName))
})
})
Context("and deleting the cluster", func() {
It("should not return an error", func() {
if !doDelete {
Skip("will not delete cluster " + clusterName)
}

Describe("when deleting a cluster", func() {
var (
err error
session *gexec.Session
)
args := []string{"delete", "cluster",
"--name", clusterName,
"--region", region,
"--wait",
}

if !doDelete {
fmt.Fprintf(GinkgoWriter, "will not delete cluster %s", clusterName)
return
}
command := exec.Command(eksctlPath, args...)
cmdSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)

It("should not return an error", func() {
args := []string{"delete", "cluster", "--name", clusterName, "--region", region}
if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}

command := exec.Command(eksctlPath, args...)
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
cmdSession.Wait(deleteTimeout)
Expect(cmdSession.ExitCode()).Should(Equal(0))
})

if err != nil {
Fail(fmt.Sprintf("error starting process: %v", err), 1)
}
awsSession := aws.NewSession(region)

session.Wait(deleteTimeout * time.Minute)
Expect(session.ExitCode()).Should(Equal(0))
})
It("should have deleted the EKS cluster", func() {
if !doDelete {
Skip("will not delete cluster " + clusterName)
}

It("should have deleted the EKS cluster", func() {
session := aws.NewSession(region)
Expect(session).ToNot(HaveEksCluster(clusterName, awseks.ClusterStatusActive, "1.10"))
})
Expect(awsSession).ToNot(HaveExistingCluster(clusterName, awseks.ClusterStatusActive, "1.10"))
})

It("should have the required cloudformation stacks", func() {
session := aws.NewSession(region)
It("should have deleted the required cloudformation stacks", func() {
if !doDelete {
Skip("will not delete cluster " + clusterName)
}

Expect(session).ToNot(HaveCfnStack(fmt.Sprintf("eksctl-%s-cluster", clusterName)))
Expect(session).ToNot(HaveCfnStack(fmt.Sprintf("eksctl-%s-nodegroup-%d", clusterName, 0)))
Expect(awsSession).ToNot(HaveExistingStack(fmt.Sprintf("eksctl-%s-cluster", clusterName)))
Expect(awsSession).ToNot(HaveExistingStack(fmt.Sprintf("eksctl-%s-nodegroup-%d", clusterName, 0)))
})
})

})
})

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)")
}
48 changes: 48 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
File renamed without changes.
42 changes: 0 additions & 42 deletions pkg/testutils/aws/eks.go

This file was deleted.

Loading