|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + "os" |
| 8 | + helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper" |
| 9 | + // "github.com/cloudposse/test-helpers/pkg/atmos" |
| 10 | + awsTerratest "github.com/gruntwork-io/terratest/modules/aws" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | + "github.com/gruntwork-io/terratest/modules/random" |
| 13 | +) |
| 14 | + |
| 15 | +type ComponentSuite struct { |
| 16 | + helper.TestSuite |
| 17 | + |
| 18 | + githubOrg string |
| 19 | + githubToken string |
| 20 | + randomID string |
| 21 | + awsRegion string |
| 22 | +} |
| 23 | + |
| 24 | +func (s *ComponentSuite) TestEnabledFlag() { |
| 25 | + const component = "eks/argocd/disabled" |
| 26 | + const stack = "default-test" |
| 27 | + const awsRegion = "us-east-2" |
| 28 | + |
| 29 | + randomID := strings.ToLower(random.UniqueId()) |
| 30 | + namespace := fmt.Sprintf("argocd-%s", randomID) |
| 31 | + |
| 32 | + secretPath := fmt.Sprintf("/argocd/%s/github/api_key", randomID) |
| 33 | + defer func() { |
| 34 | + awsTerratest.DeleteParameter(s.T(), awsRegion, secretPath) |
| 35 | + }() |
| 36 | + awsTerratest.PutParameter(s.T(), s.awsRegion, secretPath, "Github API Key", s.githubToken) |
| 37 | + |
| 38 | + inputs := map[string]interface{}{ |
| 39 | + "kubernetes_namespace": namespace, |
| 40 | + "ssm_github_api_key": secretPath, |
| 41 | + } |
| 42 | + |
| 43 | + s.VerifyEnabledFlag(component, stack, &inputs) |
| 44 | +} |
| 45 | + |
| 46 | +func (s *ComponentSuite) TestBasic() { |
| 47 | + const component = "eks/argocd/basic" |
| 48 | + const stack = "default-test" |
| 49 | + const awsRegion = "us-east-2" |
| 50 | + |
| 51 | + randomID := strings.ToLower(random.UniqueId()) |
| 52 | + namespace := fmt.Sprintf("argocd-%s", randomID) |
| 53 | + |
| 54 | + secretPath := fmt.Sprintf("/argocd/%s/github/api_key", randomID) |
| 55 | + defer func() { |
| 56 | + awsTerratest.DeleteParameter(s.T(), awsRegion, secretPath) |
| 57 | + }() |
| 58 | + awsTerratest.PutParameter(s.T(), s.awsRegion, secretPath, "Github API Key", s.githubToken) |
| 59 | + |
| 60 | + inputs := map[string]interface{}{ |
| 61 | + "kubernetes_namespace": namespace, |
| 62 | + "ssm_github_api_key": secretPath, |
| 63 | + } |
| 64 | + |
| 65 | + defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs) |
| 66 | + options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs) |
| 67 | + assert.NotNil(s.T(), options) |
| 68 | + |
| 69 | + options, _ = s.DeployAtmosComponent(s.T(), component, stack, &inputs) |
| 70 | + assert.NotNil(s.T(), options) |
| 71 | + |
| 72 | + s.DriftTest(component, stack, &inputs) |
| 73 | +} |
| 74 | + |
| 75 | +func (s *ComponentSuite) SetupSuite() { |
| 76 | + s.TestSuite.InitConfig() |
| 77 | + s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/argocd" |
| 78 | + |
| 79 | + s.githubOrg = "cloudposse-tests" |
| 80 | + s.githubOrg = "cloudposse-tests" |
| 81 | + s.githubToken = os.Getenv("GITHUB_TOKEN") |
| 82 | + if s.githubToken == "" { |
| 83 | + s.T().Fatal("GITHUB_TOKEN environment variable must be set") |
| 84 | + } |
| 85 | + s.randomID = strings.ToLower(random.UniqueId()) |
| 86 | + s.awsRegion = "us-east-2" |
| 87 | + |
| 88 | + if !s.Config.SkipDeployDependencies { |
| 89 | + deployKeyPath := fmt.Sprintf("/argocd/deploy_keys/%s/%s", s.randomID, "%s") |
| 90 | + repoName := fmt.Sprintf("argocd-github-repo-%s", s.randomID) |
| 91 | + secretPath := fmt.Sprintf("/argocd/%s/github/api_key", s.randomID) |
| 92 | + awsTerratest.PutParameter(s.T(), s.awsRegion, secretPath, "Github API Key", s.githubToken) |
| 93 | + |
| 94 | + inputs := map[string]interface{}{ |
| 95 | + "ssm_github_deploy_key_format": deployKeyPath, |
| 96 | + "ssm_github_api_key": secretPath, |
| 97 | + "name": repoName, |
| 98 | + "github_organization": s.githubOrg, |
| 99 | + } |
| 100 | + s.AddDependency(s.T(), "argocd-github-repo", "default-test", &inputs) |
| 101 | + } |
| 102 | + |
| 103 | + s.TestSuite.SetupSuite() |
| 104 | +} |
| 105 | + |
| 106 | +func (s *ComponentSuite) TearDownSuite() { |
| 107 | + s.TestSuite.TearDownSuite() |
| 108 | + if !s.Config.SkipDestroyDependencies { |
| 109 | + secretPath := fmt.Sprintf("/argocd/%s/github/api_key", s.randomID) |
| 110 | + awsTerratest.DeleteParameter(s.T(), s.awsRegion, secretPath) |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +func TestRunSuite(t *testing.T) { |
| 115 | + suite := new(ComponentSuite) |
| 116 | + suite.AddDependency(t, "vpc", "default-test", nil) |
| 117 | + suite.AddDependency(t, "eks/cluster", "default-test", nil) |
| 118 | + |
| 119 | + subdomain := strings.ToLower(random.UniqueId()) |
| 120 | + inputs := map[string]interface{}{ |
| 121 | + "zone_config": []map[string]interface{}{ |
| 122 | + { |
| 123 | + "subdomain": subdomain, |
| 124 | + "zone_name": "components.cptest.test-automation.app", |
| 125 | + }, |
| 126 | + }, |
| 127 | + } |
| 128 | + suite.AddDependency(t, "dns-delegated", "default-test", &inputs) |
| 129 | + helper.Run(t, suite) |
| 130 | +} |
0 commit comments