Skip to content

Commit

Permalink
Add helper to run acceptance tests with secrets (#308)
Browse files Browse the repository at this point in the history
* Add helper to run acceptance tests with secrets

Adds a helper to run the acceptance tests by grabbing the required
environment variables from a 1Password vault entry.

Related to https://linear.app/prefect/issue/PLA-690/cycle-6-catch-all

* Add gotestsum tool dependency

* Add 1password CLI tool dependency
  • Loading branch information
mitchnielsen authored Nov 25, 2024
1 parent 9bab0ca commit d71231d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[tools]
1password = '2.30.3'
golang = '1.21.10'
golangci-lint = '1.61.0'
goreleaser = '1.26.2'
gotestsum = '1.12.0'
pre-commit = '3.7.1'
terraform = '1.9.8'

Expand Down
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
NAME=prefect
BINARY=terraform-provider-${NAME}

TESTS?=""
LOG_LEVEL?="INFO"

default: build
.PHONY: default

Expand All @@ -9,14 +12,15 @@ help:
@echo ""
@echo "This project defines the following build targets:"
@echo ""
@echo " build - compiles source code to build/"
@echo " clean - removes built artifacts"
@echo " lint - run static code analysis"
@echo " test - run automated unit tests"
@echo " testacc - run automated acceptance tests"
@echo " docs - builds Terraform documentation"
@echo " dev-new - creates a new dev testfile (args: resource=<resource> name=<name>)"
@echo " dev-clean - cleans up dev directory"
@echo " build - compiles source code to build/"
@echo " clean - removes built artifacts"
@echo " lint - run static code analysis"
@echo " test - run automated unit tests"
@echo " testacc - run automated acceptance tests"
@echo " testacc-dev - run automated acceptance tests from a local machine (args TESTS=<tests> LOG_LEVEL=<level>)"
@echo " docs - builds Terraform documentation"
@echo " dev-new - creates a new dev testfile (args: resource=<resource> name=<name>)"
@echo " dev-clean - cleans up dev directory"
.PHONY: help

build: $(BINARY)
Expand Down Expand Up @@ -45,6 +49,10 @@ testacc:
TF_ACC=1 make test
.PHONY: testacc

testacc-dev:
./scripts/testacc-dev $(TESTS) $(LOG_LEVEL)
.PHONY: testacc-dev

docs:
mkdir -p docs
rm -rf ./docs/images
Expand Down
36 changes: 36 additions & 0 deletions scripts/testacc-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -e

# This script runs the acceptance tests from a local machine.
#
# It collects the required environment variables from 1Password
# using its CLI: https://developer.1password.com/docs/cli/secrets-scripts
#
# To run specific tests, add the test name as the first argument:
# ./scripts/testacc-dev TestAccResource_deployment
#
# To adjust the log level, specify it as the second argument:
# ./scripts/testacc-dev TestAccResource_deployment DEBUG
#
# Log levels are listed here:
# https://developer.hashicorp.com/terraform/internals/debugging

vault_entry='op://Platform/Terraform provider acceptance test secrets'

tests=${1:-""}
log_level=${2:-"INFO"}

run_arg=""
if [ "${tests}" == "" ]; then
echo "no specific test configured, running all"
else
echo "specific test(s) configured: ${tests}"
run_arg="-run ${tests}"
fi

TF_ACC=1 \
TF_LOG=${log_level} \
PREFECT_API_URL=$(op read "${vault_entry}/PREFECT_API_URL") \
PREFECT_API_KEY=$(op read "${vault_entry}/PREFECT_API_KEY") \
PREFECT_CLOUD_ACCOUNT_ID=$(op read "${vault_entry}/PREFECT_CLOUD_ACCOUNT_ID") \
gotestsum --max-fails=50 ./... -count=1 -v ${run_arg}

0 comments on commit d71231d

Please sign in to comment.