generated from cloudposse-terraform-components/template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Added tests #18
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
Merged
Added tests #18
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3116cc
Added tests
goruha f2d65fb
Added tests
goruha 7a45fab
Added tests
goruha 58136dd
Added tests
goruha 25c1131
Added tests
goruha b5785a7
Update test/component_test.go
goruha 4d5ae6c
Update provider-helm.tf
goruha 98750d4
Update test/component_test.go
goruha 86c307e
Update test/component_test.go
goruha f596c1b
Update test/component_test.go
goruha 6218d6b
Update test/component_test.go
goruha d1ba8bb
Added tests
goruha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| state/ | ||
| .cache | ||
| test/test-suite.json | ||
| .atmos | ||
| test_suite.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| package test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "strings" | ||
| "fmt" | ||
| "time" | ||
| helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper" | ||
| awsHelper "github.com/cloudposse/test-helpers/pkg/aws" | ||
| "github.com/gruntwork-io/terratest/modules/random" | ||
| "github.com/cloudposse/test-helpers/pkg/atmos" | ||
| "github.com/stretchr/testify/assert" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| networkingv1 "k8s.io/api/networking/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
|
|
||
| "k8s.io/client-go/informers" | ||
| "k8s.io/client-go/tools/cache" | ||
| ) | ||
|
|
||
| type ComponentSuite struct { | ||
| helper.TestSuite | ||
| } | ||
|
|
||
| func (s *ComponentSuite) TestBasic() { | ||
| const component = "eks/alb-controller/basic" | ||
| const stack = "default-test" | ||
| const awsRegion = "us-east-2" | ||
|
|
||
| randomID := strings.ToLower(random.UniqueId()) | ||
|
|
||
| controllerNamespace := fmt.Sprintf("alb-controller-%s", randomID) | ||
|
|
||
| input := map[string]interface{}{ | ||
| "kubernetes_namespace": controllerNamespace, | ||
| } | ||
goruha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| defer s.DestroyAtmosComponent(s.T(), component, stack, &input) | ||
| options, _ := s.DeployAtmosComponent(s.T(), component, stack, &input) | ||
goruha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.NotNil(s.T(), options) | ||
|
|
||
| type Metadata struct { | ||
| AppVersion string `json:"app_version"` | ||
| Chart string `json:"chart"` | ||
| FirstDeployed float64 `json:"first_deployed"` | ||
| LastDeployed float64 `json:"last_deployed"` | ||
| Name string `json:"name"` | ||
| Namespace string `json:"namespace"` | ||
| Notes string `json:"notes"` | ||
| Revision int `json:"revision"` | ||
| Values string `json:"values"` | ||
| Version string `json:"version"` | ||
| } | ||
|
|
||
| metadataArray := []Metadata{} | ||
|
|
||
| atmos.OutputStruct(s.T(), options, "metadata", &metadataArray) | ||
|
|
||
| metadata := metadataArray[0] | ||
|
|
||
| assert.Equal(s.T(), metadata.AppVersion, "v2.7.1") | ||
| assert.Equal(s.T(), metadata.Chart, "aws-load-balancer-controller") | ||
| assert.NotNil(s.T(), metadata.FirstDeployed) | ||
| assert.NotNil(s.T(), metadata.LastDeployed) | ||
| assert.Equal(s.T(), metadata.Name, "aws-load-balancer-controller") | ||
| assert.Equal(s.T(), metadata.Namespace, controllerNamespace) | ||
| assert.Equal(s.T(), metadata.Notes, "AWS Load Balancer controller installed!\n") | ||
| assert.Equal(s.T(), metadata.Revision, 1) | ||
| assert.NotNil(s.T(), metadata.Values) | ||
| assert.Equal(s.T(), metadata.Version, "1.7.1") | ||
|
|
||
| clusterOptions := s.GetAtmosOptions("eks/cluster", stack, nil) | ||
| clusrerId := atmos.Output(s.T(), clusterOptions, "eks_cluster_id") | ||
| cluster := awsHelper.GetEksCluster(s.T(), context.Background(), awsRegion, clusrerId) | ||
| clientset, err := awsHelper.NewK8SClientset(cluster) | ||
| assert.NoError(s.T(), err) | ||
| assert.NotNil(s.T(), clientset) | ||
|
|
||
| deployment, err := clientset.AppsV1().Deployments(controllerNamespace).Get(context.Background(), "aws-load-balancer-controller", metav1.GetOptions{}) | ||
| assert.NoError(s.T(), err) | ||
| assert.NotNil(s.T(), deployment) | ||
| assert.Equal(s.T(), deployment.Name, "aws-load-balancer-controller") | ||
| assert.Equal(s.T(), deployment.Namespace, controllerNamespace) | ||
| assert.Equal(s.T(), *deployment.Spec.Replicas, int32(2)) | ||
|
|
||
|
|
||
| ingressNamespace := fmt.Sprintf("example-%s", randomID) | ||
| ingressName := fmt.Sprintf("example-ingress-%s", randomID) | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| defer func() { | ||
| if err := clientset.CoreV1().Namespaces().Delete(context.Background(), ingressNamespace, metav1.DeleteOptions{}); err != nil { | ||
| fmt.Printf("Error deleting namespace %s: %v\n", ingressNamespace, err) | ||
| } | ||
| }() | ||
| _, err = clientset.CoreV1().Namespaces().Create(context.Background(), &corev1.Namespace{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: ingressNamespace, | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
| assert.NoError(s.T(), err) | ||
|
|
||
|
|
||
| pathType := networkingv1.PathTypeImplementationSpecific | ||
|
|
||
| ingress := &networkingv1.Ingress{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: ingressName, | ||
| Annotations: map[string]string{ | ||
| "alb.ingress.kubernetes.io/load-balancer-name": ingressName, | ||
| "alb.ingress.kubernetes.io/group.name": "example-group", | ||
| "external-dns.alpha.kubernetes.io/hostname": "example.com", | ||
| }, | ||
| }, | ||
| Spec: networkingv1.IngressSpec{ | ||
| DefaultBackend: &networkingv1.IngressBackend{ | ||
| Service: &networkingv1.IngressServiceBackend{ | ||
| Name: "default", | ||
| Port: networkingv1.ServiceBackendPort{ | ||
| Name: "use-annotation", | ||
| }, | ||
| }, | ||
| }, | ||
| TLS: []networkingv1.IngressTLS{ | ||
| { | ||
| Hosts: []string{"example.com"}, | ||
| }, | ||
| }, | ||
| Rules: []networkingv1.IngressRule{ | ||
| { | ||
| Host: "example.com", | ||
| IngressRuleValue: networkingv1.IngressRuleValue{ | ||
| HTTP: &networkingv1.HTTPIngressRuleValue{ | ||
| Paths: []networkingv1.HTTPIngressPath{ | ||
| { | ||
| Path: "/", | ||
| PathType: &pathType, | ||
| Backend: networkingv1.IngressBackend{ | ||
| Service: &networkingv1.IngressServiceBackend{ | ||
| Name: "default", | ||
| Port: networkingv1.ServiceBackendPort{ | ||
| Number: 80, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| defer func() { | ||
| if err := clientset.NetworkingV1().Ingresses(ingressNamespace).Delete(context.Background(), ingressName, metav1.DeleteOptions{}); err != nil { | ||
| fmt.Printf("Error deleting ingress %s: %v\n", ingressName, err) | ||
| } | ||
| }() | ||
| _, err = clientset.NetworkingV1().Ingresses(ingressNamespace).Create(context.Background(), ingress, metav1.CreateOptions{}) | ||
| assert.NoError(s.T(), err) | ||
| assert.NotNil(s.T(), ingress) | ||
|
|
||
| // Wait for the Ingress to be updated with the LoadBalancer metadata | ||
| factory := informers.NewSharedInformerFactory(clientset, 0) | ||
| informer := factory.Networking().V1().Ingresses().Informer() | ||
|
|
||
| stopChannel := make(chan struct{}) | ||
|
|
||
| informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
| UpdateFunc: func(oldObj, newObj interface{}) { | ||
| _, ok := oldObj.(*networkingv1.Ingress) | ||
| if !ok { | ||
| return | ||
| } | ||
| newIngress, ok := newObj.(*networkingv1.Ingress) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| // Check if the Ingress's LoadBalancer status has been populated | ||
| if len(newIngress.Status.LoadBalancer.Ingress) > 0 && len(newIngress.Status.LoadBalancer.Ingress[0].Hostname) > 0 { | ||
| fmt.Printf("Ingress %s is ready\n", newIngress.Name) | ||
| close(stopChannel) | ||
| } else { | ||
| fmt.Printf("Ingress %s is not ready yet\n", newIngress.Name) | ||
| } | ||
| }, | ||
| }) | ||
goruha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| go informer.Run(stopChannel) | ||
|
|
||
| select { | ||
| case <-stopChannel: | ||
| msg := "All ingress have joined the EKS cluster" | ||
| fmt.Println(msg) | ||
| case <-time.After(1 * time.Minute): | ||
| msg := "Not all worker nodes have joined the EKS cluster" | ||
| fmt.Println(msg) | ||
| } | ||
|
|
||
| ingressStatus, err := clientset.NetworkingV1().Ingresses(ingressNamespace).Get(context.Background(), ingressName, metav1.GetOptions{}) | ||
| assert.NoError(s.T(), err) | ||
| assert.Equal(s.T(), ingressStatus.Name, ingressName) | ||
| assert.NotEmpty(s.T(), ingressStatus.Status.LoadBalancer.Ingress[0].Hostname) | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| s.DriftTest(component, stack, nil) | ||
| } | ||
|
|
||
| func (s *ComponentSuite) TestEnabledFlag() { | ||
| const component = "eks/alb-controller/disabled" | ||
| const stack = "default-test" | ||
| s.VerifyEnabledFlag(component, stack, nil) | ||
| } | ||
|
|
||
| func (s *ComponentSuite) SetupSuite() { | ||
| s.TestSuite.InitConfig() | ||
| s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/alb-controller" | ||
| s.TestSuite.SetupSuite() | ||
| } | ||
|
|
||
| func TestRunSuite(t *testing.T) { | ||
| suite := new(ComponentSuite) | ||
| suite.AddDependency(t, "vpc", "default-test", nil) | ||
| suite.AddDependency(t, "eks/cluster", "default-test", nil) | ||
| helper.Run(t, suite) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # CLI config is loaded from the following locations (from lowest to highest priority): | ||
| # system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows) | ||
| # home dir (~/.atmos) | ||
| # current directory | ||
| # ENV vars | ||
| # Command-line arguments | ||
| # | ||
| # It supports POSIX-style Globs for file names/paths (double-star `**` is supported) | ||
| # https://en.wikipedia.org/wiki/Glob_(programming) | ||
|
|
||
| # Base path for components, stacks and workflows configurations. | ||
| # Can also be set using `ATMOS_BASE_PATH` ENV var, or `--base-path` command-line argument. | ||
| # Supports both absolute and relative paths. | ||
| # If not provided or is an empty string, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path` | ||
| # are independent settings (supporting both absolute and relative paths). | ||
| # If `base_path` is provided, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path` | ||
| # are considered paths relative to `base_path`. | ||
| base_path: "" | ||
|
|
||
| components: | ||
| terraform: | ||
| # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_BASE_PATH` ENV var, or `--terraform-dir` command-line argument | ||
| # Supports both absolute and relative paths | ||
| base_path: "components/terraform" | ||
| # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE` ENV var | ||
| apply_auto_approve: true | ||
| # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT` ENV var, or `--deploy-run-init` command-line argument | ||
| deploy_run_init: true | ||
| # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE` ENV var, or `--init-run-reconfigure` command-line argument | ||
| init_run_reconfigure: true | ||
| # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE` ENV var, or `--auto-generate-backend-file` command-line argument | ||
| auto_generate_backend_file: true | ||
|
|
||
| stacks: | ||
| # Can also be set using `ATMOS_STACKS_BASE_PATH` ENV var, or `--config-dir` and `--stacks-dir` command-line arguments | ||
| # Supports both absolute and relative paths | ||
| base_path: "stacks" | ||
| # Can also be set using `ATMOS_STACKS_INCLUDED_PATHS` ENV var (comma-separated values string) | ||
| # Since we are distinguishing stacks based on namespace, and namespace is not part | ||
| # of the stack name, we have to set `included_paths` via the ENV var in the Dockerfile | ||
| included_paths: | ||
| - "orgs/**/*" | ||
|
|
||
| # Can also be set using `ATMOS_STACKS_EXCLUDED_PATHS` ENV var (comma-separated values string) | ||
| excluded_paths: | ||
| - "**/_defaults.yaml" | ||
|
|
||
| # Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var | ||
| name_pattern: "{tenant}-{stage}" | ||
|
|
||
| workflows: | ||
| # Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments | ||
| # Supports both absolute and relative paths | ||
| base_path: "stacks/workflows" | ||
|
|
||
| # https://github.com/cloudposse/atmos/releases/tag/v1.33.0 | ||
| logs: | ||
| file: "/dev/stdout" | ||
| # Supported log levels: Trace, Debug, Info, Warning, Off | ||
| level: Info | ||
|
|
||
| settings: | ||
| # Can also be set using 'ATMOS_SETTINGS_LIST_MERGE_STRATEGY' environment variable, or '--settings-list-merge-strategy' command-line argument | ||
| list_merge_strategy: replace | ||
|
|
||
| # `Go` templates in Atmos manifests | ||
| # https://atmos.tools/core-concepts/stacks/templating | ||
| # https://pkg.go.dev/text/template | ||
| templates: | ||
| settings: | ||
| enabled: true | ||
| # https://masterminds.github.io/sprig | ||
| sprig: | ||
| enabled: true | ||
| # https://docs.gomplate.ca | ||
| gomplate: | ||
| enabled: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| components: | ||
| terraform: | ||
| account-map: | ||
| metadata: | ||
| terraform_workspace: core-gbl-root | ||
| vars: | ||
| tenant: core | ||
| environment: gbl | ||
| stage: root | ||
|
|
||
| # This remote state is only for Cloud Posse internal use. | ||
| # It references the Cloud Posse test organizations actual infrastructure. | ||
| # remote_state_backend: | ||
| # s3: | ||
| # bucket: cptest-core-ue2-root-tfstate-core | ||
| # dynamodb_table: cptest-core-ue2-root-tfstate-core-lock | ||
| # role_arn: arn:aws:iam::822777368227:role/cptest-core-gbl-root-tfstate-core-ro | ||
| # encrypt: true | ||
| # key: terraform.tfstate | ||
| # acl: bucket-owner-full-control | ||
| # region: us-east-2 | ||
|
|
||
| remote_state_backend_type: static | ||
| remote_state_backend: | ||
| # This static backend is used for tests that only need to use the account map iam-roles module | ||
| # to find the role to assume for Terraform operations. It is configured to use whatever | ||
| # the current user's role is, but the environment variable `TEST_ACCOUNT_ID` must be set to | ||
| # the account ID of the account that the user is currently assuming a role in. | ||
| # | ||
| # For some components, this backend is missing important data, and those components | ||
| # will need that data added to the backend configuration in order to work properly. | ||
| static: | ||
| account_info_map: {} | ||
| all_accounts: [] | ||
| aws_partition: aws | ||
| full_account_map: {} | ||
| iam_role_arn_templates: {} | ||
| non_eks_accounts: [] | ||
| profiles_enabled: false | ||
| root_account_aws_name: root | ||
| terraform_access_map: {} | ||
| terraform_dynamic_role_enabled: false | ||
| terraform_role_name_map: | ||
| apply: terraform | ||
| plan: planner | ||
| terraform_roles: {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.