|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + //"context" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + // "github.com/aws/aws-sdk-go-v2/service/docdb" |
| 10 | + "github.com/cloudposse/test-helpers/pkg/atmos" |
| 11 | + helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper" |
| 12 | + // awshelper "github.com/cloudposse/test-helpers/pkg/aws" |
| 13 | + "github.com/gruntwork-io/terratest/modules/aws" |
| 14 | + "github.com/gruntwork-io/terratest/modules/random" |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +type ComponentSuite struct { |
| 19 | + helper.TestSuite |
| 20 | +} |
| 21 | + |
| 22 | +func (s *ComponentSuite) TestBasic() { |
| 23 | + const component = "elasticsearch/basic" |
| 24 | + const stack = "default-test" |
| 25 | + const awsRegion = "us-east-2" |
| 26 | + |
| 27 | + accountId := aws.GetAccountId(s.T()) |
| 28 | + assert.NotNil(s.T(), accountId) |
| 29 | + |
| 30 | + inputs := map[string]interface{}{} |
| 31 | + |
| 32 | + defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs) |
| 33 | + options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs) |
| 34 | + assert.NotNil(s.T(), options) |
| 35 | + |
| 36 | + securityGroupId := atmos.Output(s.T(), options, "security_group_id") |
| 37 | + assert.True(s.T(), strings.HasPrefix(securityGroupId, "sg-")) |
| 38 | + |
| 39 | + domainArn := atmos.Output(s.T(), options, "domain_arn") |
| 40 | + assert.True(s.T(), strings.HasPrefix(domainArn, fmt.Sprintf("arn:aws:es:%s:%s:domain/eg-default-ue2-test-e-", awsRegion, accountId))) |
| 41 | + |
| 42 | + domainId := atmos.Output(s.T(), options, "domain_id") |
| 43 | + assert.True(s.T(), strings.Contains(domainId, "eg-default-ue2-test-e-")) |
| 44 | + |
| 45 | + domainEndpoint := atmos.Output(s.T(), options, "domain_endpoint") |
| 46 | + assert.True(s.T(), strings.HasPrefix(domainEndpoint, "vpc-eg-default-ue2-test-e-")) |
| 47 | + |
| 48 | + kibanaEndpoint := atmos.Output(s.T(), options, "kibana_endpoint") |
| 49 | + assert.True(s.T(), strings.HasPrefix(kibanaEndpoint, "vpc-eg-default-ue2-test-e-")) |
| 50 | + |
| 51 | + domainHostname := atmos.Output(s.T(), options, "domain_hostname") |
| 52 | + assert.True(s.T(), strings.HasPrefix(domainHostname, "eg-default-ue2-test-e-")) |
| 53 | + |
| 54 | + kibanaHostname := atmos.Output(s.T(), options, "kibana_hostname") |
| 55 | + assert.True(s.T(), strings.HasSuffix(kibanaHostname, "components.cptest.test-automation.app")) |
| 56 | + |
| 57 | + userIamRoleName := atmos.Output(s.T(), options, "elasticsearch_user_iam_role_name") |
| 58 | + assert.Empty(s.T(), userIamRoleName) |
| 59 | + |
| 60 | + userIamRoleArn := atmos.Output(s.T(), options, "elasticsearch_user_iam_role_arn") |
| 61 | + assert.Empty(s.T(), userIamRoleArn) |
| 62 | + |
| 63 | + masterPasswordSSMKey := atmos.Output(s.T(), options, "master_password_ssm_key") |
| 64 | + assert.Equal(s.T(), masterPasswordSSMKey, "/elasticsearch/e/password") |
| 65 | + |
| 66 | + s.DriftTest(component, stack, &inputs) |
| 67 | +} |
| 68 | + |
| 69 | +// func (s *ComponentSuite) TestEnabledFlag() { |
| 70 | +// const component = "elasticsearch/disabled" |
| 71 | +// const stack = "default-test" |
| 72 | +// const awsRegion = "us-east-2" |
| 73 | + |
| 74 | +// s.VerifyEnabledFlag(component, stack, nil) |
| 75 | +// } |
| 76 | + |
| 77 | + |
| 78 | +func TestRunSuite(t *testing.T) { |
| 79 | + suite := new(ComponentSuite) |
| 80 | + |
| 81 | + suite.AddDependency(t, "vpc", "default-test", nil) |
| 82 | + |
| 83 | + subdomain := strings.ToLower(random.UniqueId()) |
| 84 | + inputs := map[string]interface{}{ |
| 85 | + "zone_config": []map[string]interface{}{ |
| 86 | + { |
| 87 | + "subdomain": subdomain, |
| 88 | + "zone_name": "components.cptest.test-automation.app", |
| 89 | + }, |
| 90 | + }, |
| 91 | + } |
| 92 | + suite.AddDependency(t, "dns-delegated", "default-test", &inputs) |
| 93 | + helper.Run(t, suite) |
| 94 | +} |
0 commit comments