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

Update tests to add rand attribute #68

Merged
merged 6 commits into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion test/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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*
19 changes: 14 additions & 5 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package test
import (
"encoding/base64"
"fmt"
"math/rand"
"strconv"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -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
Expand All @@ -89,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)
osterman marked this conversation as resolved.
Show resolved Hide resolved

// 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")
Expand All @@ -119,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{
Expand Down