Skip to content

Commit

Permalink
Tests simplification (#3365)
Browse files Browse the repository at this point in the history
* Tofu engine update

* engine fixes

* Fixed text package name

* Constants update

* engine update

* GCP tests extraction

* Separated GCP serial tests

* imports update

* extracted locals test

* Add GCP tag execution

* Test update

* Test GCP

* Test simplification

* Locals update

* GCP Test only

* Updated GCP test names

* run flag

* AWS tests

* AWS Provider test

* AWS tests update

* Updated order

* imports update

* AWS policy tests

* Extracted common tests

* imports update

* Hooks execution

* Extracted auto retry tests

* AWS tests update

* Integration test update

* Tests update

* lint fix

* dynamo db import

* Imports update

* AWS s3 tests

* Aws tests update

* Test AWS update

* Extracted tests execution

* Separated tests execution for tofu and terraform

* Separated functions tests

* AWS tests update

* Tofu simplification

* Functions tests update

* Graph separation

* JSON test

* Separated regressions tests

* JSON tests update

* Added tests with latest terraform

* Functions tests update

* Destroy tests

* AWS constants update
  • Loading branch information
denis256 authored Aug 30, 2024
1 parent 61ae89b commit 4430999
Show file tree
Hide file tree
Showing 38 changed files with 7,078 additions and 6,732 deletions.
195 changes: 178 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ install_tofu: &install_tofu
rm -rf tofu.zip
popd
tofu --version
export TERRAGRUNT_TFPATH=tofu
sudo rm -f $(which terraform)
install_tflint: &install_tflint
name: Install TFlint
Expand Down Expand Up @@ -82,6 +84,24 @@ run_integration_test: &run_integration_test
run-go-tests --packages "$(go list ./... | grep /test | tr '\n' ' ')" | tee logs/test-results.log
no_output_timeout: 30m

run_integration_gcp_test: &run_integration_gcp_test
name: Run integration tests GCP
command: |
run-go-tests --packages "-tags=gcp -run ^TestGcp ./..." | tee logs/test-results.log
no_output_timeout: 30m

run_integration_aws_test: &run_integration_aws_test
name: Run integration tests AWS
command: |
run-go-tests --packages "-tags=aws -run ^TestAws ./..." | tee logs/test-results.log
no_output_timeout: 30m

run_integration_engine_test: &run_integration_engine_test
name: Run integration tests engine
command: |
run-go-tests --packages "-tags=engine -run ^TestEngine ./test" | tee logs/test-results.log
no_output_timeout: 30m

run_tflint_test: &run_tflint_test
name: Run TFlint tests
command: |
Expand Down Expand Up @@ -271,9 +291,6 @@ jobs:
<<: *install_tflint
- run:
<<: *setup_test_environment
- run:
# Remove terraform
sudo rm -f $(which terraform)
- run:
<<: *run_integration_test
environment:
Expand All @@ -296,9 +313,6 @@ jobs:
<<: *install_tflint
- run:
<<: *setup_test_environment
- run:
# Remove terraform
sudo rm -f $(which terraform)
- run:
<<: *run_integration_test
environment:
Expand All @@ -324,15 +338,111 @@ jobs:
- run:
<<: *setup_test_environment
- run:
# Remove terraform
sudo rm -f $(which terraform)
<<: *run_integration_engine_test
- run:
name: Run engine integration tests
command: |
run-go-tests --packages "-tags=engine -run ^TestEngine ./test" | tee logs/test-results.log
no_output_timeout: 30m
environment:
TERRAGRUNT_TFPATH: tofu
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_tofu_gcp:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *install_tofu
- run:
<<: *setup_test_environment
- run:
<<: *run_integration_gcp_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_terraform_gcp:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *setup_test_environment
- run:
<<: *run_integration_gcp_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_terraform_latest_gcp:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *setup_test_environment
- run:
<<: *install_terraform_latest
- run:
<<: *run_integration_gcp_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_tofu_aws:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *install_tofu
- run:
<<: *setup_test_environment
- run:
<<: *run_integration_aws_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_terraform_aws:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *setup_test_environment
- run:
<<: *run_integration_aws_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
path: logs
- store_test_results:
path: logs

integration_test_terraform_latest_aws:
<<: *defaults
<<: *env
steps:
- checkout
- run:
<<: *setup_test_environment
- run:
<<: *install_terraform_latest
- run:
<<: *run_integration_aws_test
- run:
<<: *run_terratest_log_parser
- store_artifacts:
Expand All @@ -350,9 +460,6 @@ jobs:
<<: *install_tofu
- run:
<<: *setup_test_environment
- run:
# Remove terraform
sudo rm -f $(which terraform)
- run:
name: generate mocks
command: |
Expand Down Expand Up @@ -589,6 +696,60 @@ workflows:
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_tofu_gcp:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_terraform_gcp:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_terraform_latest_gcp:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_tofu_aws:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_terraform_aws:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- integration_test_terraform_latest_aws:
filters:
tags:
only: /^v.*/
context:
- AWS__PHXDEVOPS__circle-ci-test
- GCP__automated-tests
- GITHUB__PAT__gruntwork-ci
- APPLE__OSX__code-signing
- run_markdownlint:
filters:
tags:
Expand Down
4 changes: 3 additions & 1 deletion aws_helper/config_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build aws

package aws_helper_test

import (
Expand All @@ -11,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestTerragruntIsAddedInUserAgent(t *testing.T) {
func TestAwsIsAddedInUserAgent(t *testing.T) {
t.Parallel()

sess, err := aws_helper.CreateAwsSession(nil, options.NewTerragruntOptions())
Expand Down
6 changes: 4 additions & 2 deletions aws_helper/policy_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build aws

package aws_helper_test

import (
Expand Down Expand Up @@ -51,7 +53,7 @@ const arraysPolicy = `
}
`

func TestUnmarshalStringActionResource(t *testing.T) {
func TestAwsUnmarshalStringActionResource(t *testing.T) {
t.Parallel()

bucketPolicy, err := aws_helper.UnmarshalPolicy(simplePolicy)
Expand Down Expand Up @@ -80,7 +82,7 @@ func TestUnmarshalStringActionResource(t *testing.T) {
assert.NotContains(t, string(out), "null")
}

func TestUnmarshalActionResourceList(t *testing.T) {
func TestAwsUnmarshalActionResourceList(t *testing.T) {
t.Parallel()
bucketPolicy, err := aws_helper.UnmarshalPolicy(arraysPolicy)
require.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion docs/_docs/02_features/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Specify a local absolute path as the source:
```hcl
engine {
source = "/home/users/iac-engines/terragrunt-iac-engine-opentofu_v0.0.1"
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions dynamodb/counting_semaphore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gruntwork-io/terragrunt/dynamodb"
)

func TestCountingSemaphoreHappyPath(t *testing.T) {
func TestAwsCountingSemaphoreHappyPath(t *testing.T) {
t.Parallel()

semaphore := dynamodb.NewCountingSemaphore(1)
Expand All @@ -23,7 +23,7 @@ func TestCountingSemaphoreHappyPath(t *testing.T) {
// and then firing up M >> N goroutines that all try to Acquire the semaphore. As each goroutine executes, it uses an
// atomic increment operation to record how many goroutines are running simultaneously. We check the number of running
// goroutines to ensure that it goes up to N, but does not exceed it.
func TestCountingSemaphoreConcurrency(t *testing.T) {
func TestAwsCountingSemaphoreConcurrency(t *testing.T) {
t.Parallel()

permits := 10
Expand Down
12 changes: 7 additions & 5 deletions dynamodb/dynamo_lock_table_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build aws

package dynamodb_test

import (
Expand All @@ -16,15 +18,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestCreateLockTableIfNecessaryTableDoesntAlreadyExist(t *testing.T) {
func TestAwsCreateLockTableIfNecessaryTableDoesntAlreadyExist(t *testing.T) {
t.Parallel()

withLockTable(t, func(tableName string, client *awsDynamodb.DynamoDB) {
assertCanWriteToTable(t, tableName, client)
})
}

func TestCreateLockTableConcurrency(t *testing.T) {
func TestAwsCreateLockTableConcurrency(t *testing.T) {
t.Parallel()

mockOptions, err := options.NewTerragruntOptionsForTest("dynamo_lock_test_utils")
Expand Down Expand Up @@ -55,7 +57,7 @@ func TestCreateLockTableConcurrency(t *testing.T) {
waitGroup.Wait()
}

func TestWaitForTableToBeActiveTableDoesNotExist(t *testing.T) {
func TestAwsWaitForTableToBeActiveTableDoesNotExist(t *testing.T) {
t.Parallel()

mockOptions, err := options.NewTerragruntOptionsForTest("dynamo_lock_test_utils")
Expand All @@ -72,7 +74,7 @@ func TestWaitForTableToBeActiveTableDoesNotExist(t *testing.T) {
assert.True(t, errors.IsError(err, dynamodb.TableActiveRetriesExceeded{TableName: tableName, Retries: retries}), "Unexpected error of type %s: %s", reflect.TypeOf(err), err)
}

func TestCreateLockTableIfNecessaryTableAlreadyExists(t *testing.T) {
func TestAwsCreateLockTableIfNecessaryTableAlreadyExists(t *testing.T) {
t.Parallel()

mockOptions, err := options.NewTerragruntOptionsForTest("dynamo_lock_test_utils")
Expand All @@ -90,7 +92,7 @@ func TestCreateLockTableIfNecessaryTableAlreadyExists(t *testing.T) {
})
}

func TestTableTagging(t *testing.T) {
func TestAwsTableTagging(t *testing.T) {
t.Parallel()

mockOptions, err := options.NewTerragruntOptionsForTest("dynamo_lock_test_utils")
Expand Down
6 changes: 4 additions & 2 deletions dynamodb/dynamo_lock_test_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build aws

package dynamodb_test

import (
Expand All @@ -13,7 +15,7 @@ import (
)

// For simplicity, do all testing in the us-east-1 region
const DEFAULT_TEST_REGION = "us-east-1"
const defaultTestRegion = "us-east-1"

// Create a DynamoDB client we can use at test time. If there are any errors creating the client, fail the test.
func createDynamoDbClientForTest(t *testing.T) *awsDynamodb.DynamoDB {
Expand All @@ -25,7 +27,7 @@ func createDynamoDbClientForTest(t *testing.T) *awsDynamodb.DynamoDB {
}

sessionConfig := &aws_helper.AwsSessionConfig{
Region: DEFAULT_TEST_REGION,
Region: defaultTestRegion,
}

client, err := dynamodb.CreateDynamoDbClient(sessionConfig, mockOptions)
Expand Down
Loading

0 comments on commit 4430999

Please sign in to comment.