Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
Signed-off-by: chjmil <[email protected]>
  • Loading branch information
saschjmil committed Feb 28, 2025
1 parent 27a100e commit 46a9adc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/default_plan_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
-e TF_VAR_tenant_id=$TF_VAR_tenant_id \
-e TF_VAR_client_id=$TF_VAR_client_id \
-e TF_VAR_client_secret=$TF_VAR_client_secret \
-v $(pwd):/viya4-iac-azure \
viya4-iac-azure:terratest -v
env:
# TF ENVIRONMENT
Expand Down
61 changes: 28 additions & 33 deletions docs/user/TerratestDockerUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Now each time you invoke the container, specify the file with the [`--env-file`]
### Docker Volume Mounts

Add volume mounts to the `docker run` command for all files and directories that must be accessible from inside the container.
- `--volume=$(pwd):/viya4-iac-azure/test` to overwrite the docker image's /viya4-iac-azure/test directory with your own. This will let you test out any local test changes without having to rebuild the docker image.
- `--volume=$(pwd):/viya4-iac-azure` the project must be mounted to the /viya4-iac-azure directory.

## Command Line Arguments

The `terratest_docker_entrypoint.sh` script supports several command line arguments to customize the test execution. Here are the available options:

* `-p, --package=PACKAGE`: The package to test. Default is './...'
* `-n, --testname=TEST`: The name of the test to run. Default is '.*'.
* `-r, --run=TEST`: The name of the test to run. Default is '.\*Plan.\*'.
* `-v, --verbose`: Run the tests in verbose mode.
* `-h, --help`: Display the help message.

Expand All @@ -46,35 +46,38 @@ The `terratest_docker_entrypoint.sh` script supports several command line argume
To run the default suite of unit tests (only terraform plan), run the following docker command:

```bash
docker run --rm --group-add root \
  --user "$(id -u):$(id -g)" \
  --env-file=$HOME/.azure_docker_creds.env \
  viya4-iac-azure-terratest
# Run from the ./viya4-iac-azure directory
docker run --rm \
--env-file=$HOME/.azure_docker_creds.env \
--volume $(pwd):/viya4-iac-azure \
viya4-iac-azure-terratest
```

### Running a specific Go Test

To run a specific test, run the following docker command with the -n command line argument:
To run a specific test, run the following docker command with the -r command line argument:

```bash
docker run --rm --group-add root \
  --user "$(id -u):$(id -g)" \
  --env-file=$HOME/.azure_docker_creds.env \
  viya4-iac-azure-terratest \
  -n="YourTest"
# Run from the ./viya4-iac-azure directory
docker run --rm \
--env-file=$HOME/.azure_docker_creds.env \
--volume $(pwd):/viya4-iac-azure \
viya4-iac-azure-terratest \
  -r="YourTest"
```
To run multiple tests, pass in a regex to the -n argument - "TestName1|TestName2|TestName3"
To run multiple tests, pass in a regex to the -r argument - "TestName1|TestName2|TestName3"

### Running a specific Go Package and Test

If you want to specify the Go package and test name, run the following docker command with the following arguments:

```bash
docker run --rm --group-add root \
  --user "$(id -u):$(id -g)" \
  --env-file=$HOME/.azure_docker_creds.env \
  viya4-iac-azure-terratest \
  -n="YourTest" \
# Run from the ./viya4-iac-azure directory
docker run --rm \
--env-file=$HOME/.azure_docker_creds.env \
--volume $(pwd):/viya4-iac-azure \
viya4-iac-azure-terratest \
  -r="YourTest" \
  -p="YourPackage"
```

Expand All @@ -83,21 +86,13 @@ docker run --rm --group-add root \
If you want to run the tests with verbose mode, run the docker image with the -v flag:

```bash
docker run --rm --group-add root \
  --user "$(id -u):$(id -g)" \
  --env-file=$HOME/.azure_docker_creds.env \
  viya4-iac-azure-terratest -v
# Run from the ./viya4-iac-azure directory
docker run --rm \
--env-file=$HOME/.azure_docker_creds.env \
--volume $(pwd):/viya4-iac-azure \
viya4-iac-azure-terratest -v
```

### Testing changes locally and accessing test run logs
### Accessing test run logs

After making additions or changes to the tests, you can mount the test directory to /viya4-iac-azure/test. This will overwrite the docker image's tests with your latest changes. It will also allow you to access and view the test run xml and logs located in the /test/test_output directory generated by the terrratest_log_parser. To do that, run the following docker command:

```bash
# Run from the /viya4-iac-azure root
docker run --rm --group-add root \
  --user "$(id -u):$(id -g)" \
  --env-file=$HOME/.azure_docker_creds.env \
  -v=$(pwd)/test:/viya4-iac-azure/test
  viya4-iac-azure-terratest
```
After running the docker container, log files will be created in the ./viya4-iac-azure/test/test_output directory. These will allow you to view the test results in xml as well as test logs generated by the terrratest_log_parser.
4 changes: 2 additions & 2 deletions test/terratest_docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export TF_VAR_subscription_id=$TF_VAR_subscription_id

# Run the tests
echo "Running 'go test $VERBOSE $PACKAGE -run $TEST -timeout 60m'"
exec go test $VERBOSE $PACKAGE -run $TEST -timeout 60m | tee test_output.log
exec go test $VERBOSE $PACKAGE -run $TEST -timeout 60m | tee ./test_output/test_output.log

# Parse the results
terratest_log_parser -testlog test_output.log -outputdir test_output
cd test_output
terratest_log_parser -testlog test_output.log -outputdir .
go run parse_results.go

0 comments on commit 46a9adc

Please sign in to comment.