Skip to content

Commit

Permalink
fix: move test folder to not be copied anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Langleu committed Feb 27, 2025
1 parent b23f4d1 commit 713e606
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aws_ec2_golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ jobs:
comment-footer: |
Check the delta diff in the [workflow run](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) for a detailed comparison.
If the changes are expected, you can use the uploaded artifact on the workflow to update the golden file on your branch.
Alternatively run `just regenerate-aws-ec2-golden-file` locally to update the golden file.
Alternatively run `just aws-ec2-regenerate-golden-file` locally to update the golden file.
2 changes: 1 addition & 1 deletion .github/workflows/aws_eks_tests_terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
export TESTS_CLUSTER_ID="${{ needs.configure-tests.outputs.cluster_id }}"
export TESTS_CLUSTER_REGION="${{ env.AWS_REGION }}"
export TESTS_TF_BINARY_NAME="${{ env.TESTS_TF_BINARY_NAME }}"
just test ${{ matrix.test_function }} "--junitfile ${{ matrix.test_function }}_unit-tests.xml"
just aws-tf-modules-test ${{ matrix.test_function }} "--junitfile ${{ matrix.test_function }}_unit-tests.xml"
# this is a workaround for test report not working as expected due to https://github.com/test-summary/action/issues/5
- name: Filter logger.go from the test report (too large)
Expand Down
File renamed without changes.
26 changes: 15 additions & 11 deletions aws/modules/test/README.md → aws/modules/.test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ Test with:

```bash
# Launch all the tests
just test
just aws-tf-modules-test

# if you want the live output
just tests-verbose
just aws-tf-modules-tests-verbose

# or just test one case
just test-verbose TestUpgradeEKSTestSuite
just aws-tf-modules-test-verbose TestUpgradeEKSTestSuite
```

When you run the test, terratest will create a copy of the module to be tested in the `tests/states` directory.
When you run the test, terratest will create a copy of the module to be tested in the `./.test/states` directory.
You can later navigate to the directory and use its content to manipulate the cluster.

The `.test` folder is called this way as we keep it close to the modules due to the monorepo structure and additionally we're making use of a terratest function that copies the modules folder to allow running tests in parallel on the same machine. By "hiding" the folder, the function does not copy the test folder anymore otherwise it would result in an endless path and crash the test.

**Local development note:**
You can set the `SKIP_XXX` variable to prevent unique IDs of tests from being generated each time, thus using the same resources instead of deploying new resources with terraform.

Expand All @@ -96,13 +98,15 @@ May not be up-to-date, please verify with `just --list`:
```text
╰─λ just --list 130 (10.968s) < 15:28:36
Available recipes:
asdf-install # Install tools using asdf
asdf-plugins # Install asdf plugins
install-tooling # Install all the tooling
test TEST # Launch a single test using gotestsum
test-verbose TEST # Launch a single test using go test in verbose mode
tests # Launch the tests in parallel using gotestsum
tests-verbose # Launch the tests in parallel using go test in verbose mode
asdf-install # Install tools using asdf
asdf-plugins # Install asdf plugins
aws-ec2-regenerate-golden-file # Generate the AWS golden file for the EC2 tf files
aws-tf-modules-install-tests-go-mod # Install go dependencies from test/src/go.mod
aws-tf-modules-test testname gts_options="" # Launch a single test using gotestsum
aws-tf-modules-test-verbose testname # Launch a single test using go test in verbose mode
aws-tf-modules-tests gts_options="" # Launch the tests in parallel using gotestsum
aws-tf-modules-tests-verbose # Launch the tests in parallel using go test in verbose mode
install-tooling # Install all the tooling
```

## Troubleshooting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package test
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/aws/aws-sdk-go-v2/service/iam"
Expand All @@ -20,11 +26,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"path/filepath"
"strings"
"testing"
"time"
)

type CustomEKSOpenSearchTestSuite struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (suite *CustomEKSOpenSearchTestSuite) SetupTest() {
suite.expectedNodes = 1
var errAbsPath error
suite.tfStateS3Bucket = utils.GetEnv("TF_STATE_BUCKET", fmt.Sprintf("tests-eks-tf-state-%s", suite.bucketRegion))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../../test/states/tf-data-%s", suite.clusterName))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../states/tf-data-%s", suite.clusterName))
suite.Require().NoError(errAbsPath)
suite.kubeConfigPath = fmt.Sprintf("%s/kubeconfig-opensearch-eks", suite.tfDataDir)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (suite *CustomEKSRDSTestSuite) SetupTest() {
suite.expectedNodes = 1
var errAbsPath error
suite.tfStateS3Bucket = utils.GetEnv("TF_STATE_BUCKET", fmt.Sprintf("tests-eks-tf-state-%s", suite.bucketRegion))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../../test/states/tf-data-%s", suite.clusterName))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../states/tf-data-%s", suite.clusterName))
suite.Require().NoError(errAbsPath)
suite.kubeConfigPath = fmt.Sprintf("%s/kubeconfig-rds-eks", suite.tfDataDir)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
"context"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
"github.com/aws/aws-sdk-go-v2/service/ec2"
Expand All @@ -19,12 +26,6 @@ import (
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"
)

type DefaultEKSTestSuite struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (suite *DefaultEKSTestSuite) SetupTest() {
suite.expectedNodes = 4
var errAbsPath error
suite.tfStateS3Bucket = utils.GetEnv("TF_STATE_BUCKET", fmt.Sprintf("tests-eks-tf-state-%s", suite.bucketRegion))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../../test/states/tf-data-%s", suite.clusterName))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../states/tf-data-%s", suite.clusterName))
suite.Require().NoError(errAbsPath)
suite.kubeConfigPath = fmt.Sprintf("%s/kubeconfig-default-eks", suite.tfDataDir)
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (suite *UpgradeEKSTestSuite) SetupTest() {
suite.kubeVersion = "1.29"
var errAbsPath error
suite.tfStateS3Bucket = utils.GetEnv("TF_STATE_BUCKET", fmt.Sprintf("tests-eks-tf-state-%s", suite.bucketRegion))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../../test/states/tf-data-%s", suite.clusterName))
suite.tfDataDir, errAbsPath = filepath.Abs(fmt.Sprintf("../states/tf-data-%s", suite.clusterName))
suite.Require().NoError(errAbsPath)
suite.kubeConfigPath = fmt.Sprintf("%s/kubeconfig-upgrade-eks", suite.tfDataDir)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 12 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# renovate: datasource=github-releases depName=gotestyourself/gotestsum
gotestsum_version := "v1.12.0"

regenerate-aws-ec2-golden-file:
# Generate the AWS golden file for the EC2 tf files
aws-ec2-regenerate-golden-file:
#!/bin/bash
cd {{justfile_directory()}}/aws/virtual-machine/ec2/terraform
cp {{justfile_directory()}}/aws/virtual-machine/ec2/test/fixtures/provider_override.tf .
Expand All @@ -16,24 +17,24 @@ regenerate-aws-ec2-golden-file:
rm -rf provider_override.tf

# Launch a single test using go test in verbose mode
test-verbose testname: install-tests-go-mod
cd aws/modules/test/src/ && go test -v --timeout=120m -p 1 -run {{testname}}
aws-tf-modules-test-verbose testname: aws-tf-modules-install-tests-go-mod
cd aws/modules/.test/src/ && go test -v --timeout=120m -p 1 -run {{testname}}

# Launch a single test using gotestsum
test testname gts_options="": install-tests-go-mod
cd aws/modules/test/src/ && go run gotest.tools/gotestsum@{{gotestsum_version}} {{gts_options}} -- --timeout=120m -p 1 -run {{testname}}
aws-tf-modules-test testname gts_options="": aws-tf-modules-install-tests-go-mod
cd aws/modules/.test/src/ && go run gotest.tools/gotestsum@{{gotestsum_version}} {{gts_options}} -- --timeout=120m -p 1 -run {{testname}}

# Launch the tests in parallel using go test in verbose mode
tests-verbose: install-tests-go-mod
cd aws/modules/test/src/ && go test -v --timeout=120m -p 1 .
aws-tf-modules-tests-verbose: aws-tf-modules-install-tests-go-mod
cd aws/modules/.test/src/ && go test -v --timeout=120m -p 1 .

# Launch the tests in parallel using gotestsum
tests gts_options="": install-tests-go-mod
cd aws/modules/test/src/ && go run gotest.tools/gotestsum@{{gotestsum_version}} {{gts_options}} -- --timeout=120m -p 1 .
aws-tf-modules-tests gts_options="": aws-tf-modules-install-tests-go-mod
cd aws/modules/.test/src/ && go run gotest.tools/gotestsum@{{gotestsum_version}} {{gts_options}} -- --timeout=120m -p 1 .

# Install go dependencies from test/src/go.mod
install-tests-go-mod:
cd aws/modules/test/src/ && go mod download
aws-tf-modules-install-tests-go-mod:
cd aws/modules/.test/src/ && go mod download

# Install all the tooling
install-tooling: asdf-install
Expand Down

0 comments on commit 713e606

Please sign in to comment.