From 7868764e6a15134c7a766c71093b3d63e2e7bac9 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Fri, 3 Jul 2020 13:30:35 -0700 Subject: [PATCH 1/4] Update tests to add rand attribute --- test/src/Makefile | 2 +- test/src/examples_complete_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/src/Makefile b/test/src/Makefile index f8423a95..aa2aa726 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -27,4 +27,4 @@ docker/test: .PHONY : clean ## Clean up files clean: - rm -rf $(TF_DATA_DIR) + rm -rf $(TF_DATA_DIR) ../../examples/complete/*.tfstate* diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index 651e47f3..bc728741 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -3,6 +3,8 @@ package test import ( "encoding/base64" "fmt" + "math/rand" + "strconv" "sync/atomic" "testing" "time" @@ -57,12 +59,19 @@ func newClientset(cluster *eks.Cluster) (*kubernetes.Clientset, error) { func TestExamplesComplete(t *testing.T) { t.Parallel() + rand.Seed(time.Now().UnixNano()) + + attributes := []string{strconv.Itoa(rand.Intn(100000))} + terraformOptions := &terraform.Options{ // The path to where our Terraform code is located TerraformDir: "../../examples/complete", Upgrade: true, // Variables to pass to our Terraform code using -var-file options VarFiles: []string{"fixtures.us-east-2.tfvars"}, + Vars: map[string]interface{}{ + "attributes": attributes, + }, } // At the end of the test, run `terraform destroy` to clean up any resources that were created From c846c715e4b78b916de3baeee8ab298e539f49d3 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Fri, 3 Jul 2020 14:21:31 -0700 Subject: [PATCH 2/4] fix checks --- test/src/examples_complete_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index bc728741..e894ec77 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -98,22 +98,22 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable eksClusterId := terraform.Output(t, terraformOptions, "eks_cluster_id") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-cluster", eksClusterId) + assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster", eksClusterId) // Run `terraform output` to get the value of an output variable eksClusterSecurityGroupName := terraform.Output(t, terraformOptions, "eks_cluster_security_group_name") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-cluster", eksClusterSecurityGroupName) + assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster", eksClusterSecurityGroupName) // Run `terraform output` to get the value of an output variable eksNodeGroupId := terraform.Output(t, terraformOptions, "eks_node_group_id") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-cluster:eg-test-eks-workers", eksNodeGroupId) + assert.Equal(t, "eg-test-eks-cluster:eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupId) // Run `terraform output` to get the value of an output variable eksNodeGroupRoleName := terraform.Output(t, terraformOptions, "eks_node_group_role_name") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-workers", eksNodeGroupRoleName) + assert.Equal(t, "eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupRoleName) // Run `terraform output` to get the value of an output variable eksNodeGroupStatus := terraform.Output(t, terraformOptions, "eks_node_group_status") @@ -128,7 +128,7 @@ func TestExamplesComplete(t *testing.T) { // https://stackoverflow.com/questions/60547409/unable-to-obtain-kubeconfig-of-an-aws-eks-cluster-in-go-code/60573982#60573982 fmt.Println("Waiting for worker nodes to join the EKS cluster") - clusterName := "eg-test-eks-cluster" + clusterName := "eg-test-eks-" + attributes[0] + "-cluster" region := "us-east-2" sess := session.Must(session.NewSession(&aws.Config{ From a9484b253b08cf5cf6e63616dd801bdb8e7cdbbe Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Fri, 3 Jul 2020 15:49:29 -0700 Subject: [PATCH 3/4] fix test --- test/src/examples_complete_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index e894ec77..9f870f13 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -108,7 +108,7 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable eksNodeGroupId := terraform.Output(t, terraformOptions, "eks_node_group_id") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-cluster:eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupId) + assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster:eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupId) // Run `terraform output` to get the value of an output variable eksNodeGroupRoleName := terraform.Output(t, terraformOptions, "eks_node_group_role_name") From 5f659a7f2692e077fce86fe88532bdb49baa5c21 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Fri, 3 Jul 2020 15:52:15 -0700 Subject: [PATCH 4/4] use randId variable --- test/src/examples_complete_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index 9f870f13..4bc7f91a 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -61,7 +61,8 @@ func TestExamplesComplete(t *testing.T) { rand.Seed(time.Now().UnixNano()) - attributes := []string{strconv.Itoa(rand.Intn(100000))} + randId := strconv.Itoa(rand.Intn(100000)) + attributes := []string{randId} terraformOptions := &terraform.Options{ // The path to where our Terraform code is located @@ -98,22 +99,22 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable eksClusterId := terraform.Output(t, terraformOptions, "eks_cluster_id") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster", eksClusterId) + assert.Equal(t, "eg-test-eks-"+randId+"-cluster", eksClusterId) // Run `terraform output` to get the value of an output variable eksClusterSecurityGroupName := terraform.Output(t, terraformOptions, "eks_cluster_security_group_name") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster", eksClusterSecurityGroupName) + assert.Equal(t, "eg-test-eks-"+randId+"-cluster", eksClusterSecurityGroupName) // Run `terraform output` to get the value of an output variable eksNodeGroupId := terraform.Output(t, terraformOptions, "eks_node_group_id") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-"+attributes[0]+"-cluster:eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupId) + assert.Equal(t, "eg-test-eks-"+randId+"-cluster:eg-test-eks-"+randId+"-workers", eksNodeGroupId) // Run `terraform output` to get the value of an output variable eksNodeGroupRoleName := terraform.Output(t, terraformOptions, "eks_node_group_role_name") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-eks-"+attributes[0]+"-workers", eksNodeGroupRoleName) + assert.Equal(t, "eg-test-eks-"+randId+"-workers", eksNodeGroupRoleName) // Run `terraform output` to get the value of an output variable eksNodeGroupStatus := terraform.Output(t, terraformOptions, "eks_node_group_status") @@ -128,7 +129,7 @@ func TestExamplesComplete(t *testing.T) { // https://stackoverflow.com/questions/60547409/unable-to-obtain-kubeconfig-of-an-aws-eks-cluster-in-go-code/60573982#60573982 fmt.Println("Waiting for worker nodes to join the EKS cluster") - clusterName := "eg-test-eks-" + attributes[0] + "-cluster" + clusterName := "eg-test-eks-" + randId + "-cluster" region := "us-east-2" sess := session.Must(session.NewSession(&aws.Config{