|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + "strings" |
| 7 | + helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper" |
| 8 | + "github.com/cloudposse/test-helpers/pkg/atmos" |
| 9 | + "github.com/cloudposse/test-helpers/pkg/helm" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/gruntwork-io/terratest/modules/random" |
| 12 | +) |
| 13 | + |
| 14 | +type ComponentSuite struct { |
| 15 | + helper.TestSuite |
| 16 | +} |
| 17 | + |
| 18 | +func (s *ComponentSuite) TestBasic() { |
| 19 | + const component = "eks/echo-server/basic" |
| 20 | + const stack = "default-test" |
| 21 | + const awsRegion = "us-east-2" |
| 22 | + |
| 23 | + randomID := strings.ToLower(random.UniqueId()) |
| 24 | + |
| 25 | + dnsDelegatedOptions := s.GetAtmosOptions("dns-delegated", stack, nil) |
| 26 | + delegatedDomainName := atmos.Output(s.T(), dnsDelegatedOptions, "default_domain_name") |
| 27 | + |
| 28 | + domainTemplate := fmt.Sprintf("echo-%s.%s.%s", randomID, "%[3]v.%[2]v.%[1]v", delegatedDomainName) |
| 29 | + |
| 30 | + namespace := fmt.Sprintf("echo-%s", randomID) |
| 31 | + |
| 32 | + inputs := map[string]interface{}{ |
| 33 | + "kubernetes_namespace": namespace, |
| 34 | + "hostname_template": domainTemplate, |
| 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 | + metadata := helm.Metadata{} |
| 42 | + |
| 43 | + atmos.OutputStruct(s.T(), options, "metadata", &metadata) |
| 44 | + |
| 45 | + assert.Equal(s.T(), metadata.AppVersion, "0.8.0") |
| 46 | + assert.Equal(s.T(), metadata.Chart, "echo-server") |
| 47 | + assert.NotNil(s.T(), metadata.FirstDeployed) |
| 48 | + assert.NotNil(s.T(), metadata.LastDeployed) |
| 49 | + assert.Equal(s.T(), metadata.Name, "echo-server") |
| 50 | + assert.Equal(s.T(), metadata.Namespace, namespace) |
| 51 | + assert.NotNil(s.T(), metadata.Values) |
| 52 | + assert.Equal(s.T(), metadata.Version, "0.4.0") |
| 53 | + |
| 54 | + hostname := atmos.Output(s.T(), options, "hostname") |
| 55 | + assert.NotNil(s.T(), hostname) |
| 56 | + |
| 57 | + s.DriftTest(component, stack, &inputs) |
| 58 | +} |
| 59 | + |
| 60 | +func (s *ComponentSuite) TestEnabledFlag() { |
| 61 | + const component = "eks/echo-server/disabled" |
| 62 | + const stack = "default-test" |
| 63 | + s.VerifyEnabledFlag(component, stack, nil) |
| 64 | +} |
| 65 | + |
| 66 | +func (s *ComponentSuite) SetupSuite() { |
| 67 | + s.TestSuite.InitConfig() |
| 68 | + s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/echo-server" |
| 69 | + s.TestSuite.SetupSuite() |
| 70 | +} |
| 71 | + |
| 72 | +func TestRunSuite(t *testing.T) { |
| 73 | + suite := new(ComponentSuite) |
| 74 | + suite.AddDependency(t, "vpc", "default-test", nil) |
| 75 | + suite.AddDependency(t, "eks/cluster", "default-test", nil) |
| 76 | + suite.AddDependency(t, "eks/alb-controller", "default-test", nil) |
| 77 | + |
| 78 | + subdomain := strings.ToLower(random.UniqueId()) |
| 79 | + inputs := map[string]interface{}{ |
| 80 | + "zone_config": []map[string]interface{}{ |
| 81 | + { |
| 82 | + "subdomain": subdomain, |
| 83 | + "zone_name": "components.cptest.test-automation.app", |
| 84 | + }, |
| 85 | + }, |
| 86 | + } |
| 87 | + suite.AddDependency(t, "dns-delegated", "default-test", &inputs) |
| 88 | + helper.Run(t, suite) |
| 89 | +} |
0 commit comments