Skip to content

Commit

Permalink
DXCDT-501: auth0 tf generate end-to-end tests (#848)
Browse files Browse the repository at this point in the history
* Allowing relationship resources to be included in resource argument flag

* Changing provider version to 1.0.0-beta.4

* Removing auth0_log_stream from default list

* Adding experimental designation

* Adding reference to guide, examples

* Updating changelog

* Doc tweaks

* Fixing example indentation

* Fixing flaky unit test

* Changing note to warning

* Removing export alias, adding abbreviated args

* Adding script, updating tests

* Adding tests, scripts

* Making test script executable

* Making test script executable

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
willvedd and willvedd authored Sep 19, 2023
1 parent ada09d8 commit 9cc4f17
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/integration/scripts/assert-tf-generate-files-exist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

if [[ $1 == *partial_success* ]]; then
files=(
"tmp-tf-gen/auth0_import.tf"
"tmp-tf-gen/auth0_main.tf"
)
else
files=(
"tmp-tf-gen/auth0_generated.tf"
"tmp-tf-gen/auth0_import.tf"
"tmp-tf-gen/auth0_main.tf"
"tmp-tf-gen/terraform"
"tmp-tf-gen/.terraform.lock.hcl"
)
fi

has_error=false

for file in "${files[@]}"; do
if [ -e "$file" ]; then
if ! [ -s "$file" ]; then
echo "$file exists but is empty"
has_error=true
fi
else
echo "$file does not exist"
has_error=true
fi
done

if [ "$has_error" = true ]; then
exit 1
fi
2 changes: 2 additions & 0 deletions test/integration/scripts/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://exampl
rm -rf integration-test-app-qs

rm -rf test/integration/identifiers

rm -rdf tmp-tf-gen
66 changes: 66 additions & 0 deletions test/integration/terraform-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
config:
inherit-env: true
retries: 1
env:
AUTH0_DOMAIN: $AUTH0_CLI_CLIENT_DOMAIN
AUTH0_CLIENT_ID: $AUTH0_CLI_CLIENT_ID
AUTH0_CLIENT_SECRET: $AUTH0_CLI_CLIENT_SECRET
tests:
001.0 - setup:
command: rm -rdf tmp-tf-gen
exit-code: 0
001.1 - it successfully runs for a single resource:
command: auth0 tf generate --output-dir tmp-tf-gen -r auth0_tenant
exit-code: 0
stderr:
contains:
- "Terraform resource config files generated successfully in: tmp-tf-gen"
- Review the config and generate the terraform state by running
- cd tmp-tf-gen && ./terraform apply
- Once Terraform files are auto-generated, the terraform binary and auth0_import.tf files can be deleted.
001.2 - it successfully generates the expected files for a single resource:
command: ./test/integration/scripts/assert-tf-generate-files-exist.sh
exit-code: 0
001.3 - cleanup:
command: rm -rdf tmp-tf-gen

002.0 - setup:
command: rm -rdf tmp-tf-gen
exit-code: 0
002.1 - it successfully runs for all default resources:
command: auth0 tf generate --output-dir tmp-tf-gen
exit-code: 0
stderr:
contains:
- "Terraform resource config files generated successfully in: tmp-tf-gen"
- Review the config and generate the terraform state by running
- cd tmp-tf-gen && ./terraform apply
- Once Terraform files are auto-generated, the terraform binary and auth0_import.tf files can be deleted.
002.2 - it successfully generates the expected files for all default resources:
command: ./test/integration/scripts/assert-tf-generate-files-exist.sh
exit-code: 0
002.3 - cleanup:
command: rm -rdf tmp-tf-gen

003.1 - it partially succeeds if Terraform credentials not provided:
command: unset AUTH0_DOMAIN && auth0 tf generate --output-dir tmp-tf-gen
exit-code: 0
stderr:
contains:
- "Terraform provider credentials not detected"
- "Refer to following guide on how to create a dedicated Auth0 client and configure credentials: https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/quickstart"
- "After provider credentials are set, run:"
- "cd tmp-tf-gen && terraform init && terraform plan -generate-config-out=auth0_generated.tf && terraform apply"
- "Once the Terraform file is auto-generated, the auth0_import.tf file can be deleted."
003.2 - it successfully generates the expected files for a partial success:
command: ./test/integration/scripts/assert-tf-generate-files-exist.sh partial_success
exit-code: 0
003.3 - cleanup:
command: rm -rdf tmp-tf-gen

004 - it does not run if invalid resource provided:
command: auth0 tf generate -r auth0_computer
exit-code: 1
stderr:
contains:
- "unsupported resource type: auth0_computer"

0 comments on commit 9cc4f17

Please sign in to comment.