|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + "fmt" |
| 7 | + "strings" |
| 8 | + helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper" |
| 9 | + awsHelper "github.com/cloudposse/test-helpers/pkg/aws" |
| 10 | + "github.com/cloudposse/test-helpers/pkg/atmos" |
| 11 | + // "github.com/gruntwork-io/terratest/modules/aws" |
| 12 | + "github.com/stretchr/testify/assert" |
| 13 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 14 | + "github.com/gruntwork-io/terratest/modules/random" |
| 15 | +) |
| 16 | + |
| 17 | +type ComponentSuite struct { |
| 18 | + helper.TestSuite |
| 19 | +} |
| 20 | + |
| 21 | +func (s *ComponentSuite) TestBasic() { |
| 22 | + const component = "eks/alb-controller-ingress-class/basic" |
| 23 | + const stack = "default-test" |
| 24 | + const awsRegion = "us-east-2" |
| 25 | + |
| 26 | + randomID := strings.ToLower(random.UniqueId()) |
| 27 | + class_name := fmt.Sprintf("alb-%s", randomID) |
| 28 | + group_name := fmt.Sprintf("group-%s", randomID) |
| 29 | + |
| 30 | + inputs := map[string]interface{}{ |
| 31 | + "class_name": class_name, |
| 32 | + "group": group_name, |
| 33 | + "ip_address_type": "ipv4", |
| 34 | + "scheme": "internet-facing", |
| 35 | + } |
| 36 | + |
| 37 | + defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs) |
| 38 | + options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs) |
| 39 | + assert.NotNil(s.T(), options) |
| 40 | + |
| 41 | + clusterOptions := s.GetAtmosOptions("eks/cluster", stack, nil) |
| 42 | + clusrerId := atmos.Output(s.T(), clusterOptions, "eks_cluster_id") |
| 43 | + cluster := awsHelper.GetEksCluster(s.T(), context.Background(), awsRegion, clusrerId) |
| 44 | + clientset, err := awsHelper.NewK8SClientset(cluster) |
| 45 | + assert.NoError(s.T(), err) |
| 46 | + assert.NotNil(s.T(), clientset) |
| 47 | + |
| 48 | + ingressClass, err := clientset.NetworkingV1().IngressClasses().Get(context.Background(), class_name, metav1.GetOptions{}) |
| 49 | + assert.NoError(s.T(), err) |
| 50 | + assert.Equal(s.T(), ingressClass.ObjectMeta.Name, class_name) |
| 51 | + assert.Equal(s.T(), ingressClass.Spec.Controller, "ingress.k8s.aws/alb") |
| 52 | + |
| 53 | + s.DriftTest(component, stack, &inputs) |
| 54 | +} |
| 55 | + |
| 56 | +func (s *ComponentSuite) TestEnabledFlag() { |
| 57 | + const component = "eks/alb-controller-ingress-class/disabled" |
| 58 | + const stack = "default-test" |
| 59 | + s.VerifyEnabledFlag(component, stack, nil) |
| 60 | +} |
| 61 | + |
| 62 | +func (s *ComponentSuite) SetupSuite() { |
| 63 | + s.TestSuite.InitConfig() |
| 64 | + s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/alb-controller-ingress-class" |
| 65 | + s.TestSuite.SetupSuite() |
| 66 | +} |
| 67 | + |
| 68 | +func TestRunSuite(t *testing.T) { |
| 69 | + suite := new(ComponentSuite) |
| 70 | + suite.AddDependency(t, "vpc", "default-test", nil) |
| 71 | + suite.AddDependency(t, "eks/cluster", "default-test", nil) |
| 72 | + suite.AddDependency(t, "eks/alb-controller", "default-test", nil) |
| 73 | + helper.Run(t, suite) |
| 74 | +} |
0 commit comments