-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Integration tests #171
Merged
Merged
Integration tests #171
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5a3ad09
Initial checkin on integration test
richardcase 8a5d762
Added gomega matchers to hide away some of the aws plumbing
richardcase 2c91351
Added additional stack tests. Added make file target for tests
richardcase 82004a3
Added cleanup and did some refactoring
richardcase 44cf76d
Added deployment test
richardcase 0b1dd9e
Update vendor
errordeveloper d2673f9
Wrap up integration tests
errordeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
) | ||
|
||
const ( | ||
errorMerssageTemplate = "Stack with id %s does not exist" | ||
) | ||
|
||
// StackExists checks to see if a CloudFormation stack exists | ||
func StackExists(stackName string, session *session.Session) (bool, error) { | ||
cfn := cloudformation.New(session) | ||
|
||
input := &cloudformation.ListStackResourcesInput{ | ||
StackName: aws.String(stackName), | ||
} | ||
_, err := cfn.ListStackResources(input) | ||
|
||
if err != nil { | ||
// Check if its a not found error | ||
errorMessage := fmt.Sprintf(errorMerssageTemplate, stackName) | ||
if !strings.Contains(err.Error(), errorMessage) { | ||
return false, err | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// DeleteStack deletes a cloudformation stack | ||
func DeleteStack(stackName string, session *session.Session) error { | ||
cfn := cloudformation.New(session) | ||
|
||
input := &cloudformation.DeleteStackInput{ | ||
StackName: aws.String(stackName), | ||
} | ||
|
||
_, err := cfn.DeleteStack(input) | ||
|
||
return err | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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" | ||
) | ||
|
||
// EksClusterExists checks if an EKS cluster exists in AWS | ||
func EksClusterExists(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 | ||
} | ||
|
||
// EksClusterDelete deletes a EKS cluster with a given name | ||
func EksClusterDelete(clusterName string, session *session.Session) error { | ||
eks := awseks.New(session) | ||
|
||
input := &awseks.DeleteClusterInput{ | ||
Name: aws.String(clusterName), | ||
} | ||
|
||
_, err := eks.DeleteCluster(input) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
func NewSession(region string) *session.Session { | ||
config := aws.NewConfig() | ||
config = config.WithRegion(region) | ||
opts := session.Options{ | ||
Config: *config, | ||
} | ||
return session.Must(session.NewSessionWithOptions(opts)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package matchers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/onsi/gomega/types" | ||
"github.com/weaveworks/eksctl/pkg/testutils/aws" | ||
) | ||
|
||
const ( | ||
errorMerssageTemplate = "Stack with id %s does not exist" | ||
) | ||
|
||
// HaveCfnStack returns a GoMega matcher that will check for the existence of an cloudformatioin stack | ||
func HaveCfnStack(expectedStackName string) types.GomegaMatcher { | ||
return &haveCfnStackMatcher{expectedStackName: expectedStackName} | ||
} | ||
|
||
type haveCfnStackMatcher struct { | ||
expectedStackName string | ||
stackNotFound bool | ||
} | ||
|
||
func (m *haveCfnStackMatcher) Match(actual interface{}) (success bool, err error) { | ||
if actual == nil { | ||
return false, errors.New("input is nil") | ||
} | ||
|
||
if reflect.TypeOf(actual).String() != "*session.Session" { | ||
return false, errors.New("not a AWS session") | ||
} | ||
|
||
found, err := aws.StackExists(m.expectedStackName, actual.(*session.Session)) | ||
|
||
if err != nil { | ||
return false, err | ||
} | ||
|
||
m.stackNotFound = !found | ||
return found, nil | ||
} | ||
|
||
func (m *haveCfnStackMatcher) 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 *haveCfnStackMatcher) NegatedFailureMessage(_ interface{}) (message string) { | ||
return fmt.Sprintf("Expected NOT to find a Cloudformation stack named %s but it found", m.expectedStackName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package matchers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/onsi/gomega/types" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
awseks "github.com/aws/aws-sdk-go/service/eks" | ||
) | ||
|
||
// HaveEksCluster returns a GoMega matcher that will check for the existence of an EKS cluster | ||
func HaveEksCluster(expectedName string, expectedStatus string, expectedversion string) types.GomegaMatcher { | ||
return &haveEksClusterMatcher{expectedName: expectedName, expectedStatus: expectedStatus, expectedVersion: expectedversion} | ||
} | ||
|
||
type haveEksClusterMatcher struct { | ||
expectedName string | ||
expectedStatus string | ||
expectedVersion string | ||
|
||
clusterNotFound bool | ||
versionMismatch bool | ||
statusMismatch bool | ||
|
||
actualVersion string | ||
actualStatus string | ||
|
||
region string | ||
} | ||
|
||
func (m *haveEksClusterMatcher) Match(actual interface{}) (success bool, err error) { | ||
if actual == nil { | ||
return false, errors.New("input is nil") | ||
} | ||
|
||
if reflect.TypeOf(actual).String() != "*session.Session" { | ||
return false, errors.New("not a AWS session") | ||
} | ||
|
||
eks := awseks.New(actual.(*session.Session)) | ||
|
||
input := &awseks.DescribeClusterInput{ | ||
Name: aws.String(m.expectedName), | ||
} | ||
output, 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 | ||
} | ||
|
||
m.clusterNotFound = true | ||
return false, nil | ||
} | ||
|
||
m.actualStatus = *output.Cluster.Status | ||
if m.actualStatus != m.expectedStatus { | ||
m.statusMismatch = true | ||
return false, nil | ||
} | ||
|
||
m.actualVersion = *output.Cluster.Version | ||
if m.actualVersion != m.expectedVersion { | ||
m.versionMismatch = true | ||
return false, nil | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func (m *haveEksClusterMatcher) FailureMessage(actual interface{}) (message string) { | ||
if m.statusMismatch { | ||
return fmt.Sprintf("Expected EKS cluster status: %s to equal actual EKS cluster status: %s", m.expectedStatus, m.actualStatus) | ||
} | ||
if m.versionMismatch { | ||
return fmt.Sprintf("Expected EKS cluster version: %s to equal actual EKS cluster version: %s", m.expectedVersion, m.actualVersion) | ||
} | ||
|
||
return fmt.Sprintf("Expected to find a cluster named %s but it wasn't found", m.expectedName) | ||
} | ||
|
||
func (m *haveEksClusterMatcher) NegatedFailureMessage(_ interface{}) (message string) { | ||
if m.statusMismatch { | ||
return fmt.Sprintf("Expected EKS cluster status: %s NOT to equal actual EKS cluster status: %s", m.expectedStatus, m.actualStatus) | ||
} | ||
if m.versionMismatch { | ||
return fmt.Sprintf("Expected EKS cluster version: %s NOT to equal actual EKS cluster version: %s", m.expectedVersion, m.actualVersion) | ||
} | ||
|
||
return fmt.Sprintf("Expected NOT to find a cluster named %s but it found", m.expectedName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/weaveworks/eksctl/pkg/testutils/aws" | ||
) | ||
|
||
func CleanupAws(clusterName string, region string) { | ||
session := aws.NewSession(region) | ||
|
||
if found, _ := aws.EksClusterExists(clusterName, session); found { | ||
aws.EksClusterDelete(clusterName, session) | ||
} | ||
|
||
stackName := fmt.Sprintf("EKS-%s-DefaultNodeGroup", clusterName) | ||
if found, _ := aws.StackExists(stackName, session); found { | ||
aws.DeleteStack(stackName, session) | ||
} | ||
|
||
stackName = fmt.Sprintf("EKS-%s-VPC", clusterName) | ||
if found, _ := aws.StackExists(stackName, session); found { | ||
aws.DeleteStack(stackName, session) | ||
} | ||
|
||
stackName = fmt.Sprintf("EKS-%s-ControlPlane", clusterName) | ||
if found, _ := aws.StackExists(stackName, session); found { | ||
aws.DeleteStack(stackName, session) | ||
} | ||
|
||
stackName = fmt.Sprintf("EKS-%s-ServiceRole", clusterName) | ||
if found, _ := aws.StackExists(stackName, session); found { | ||
aws.DeleteStack(stackName, session) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.