From 99d8ba2e0c83908cef564c03c7366ca7ec01825c Mon Sep 17 00:00:00 2001 From: Tanner Doshier Date: Fri, 3 Jan 2025 10:35:22 -0500 Subject: [PATCH] Add "e2e" test scripts They don't actually assert things are correct, just that the commands run without error, which for a start is useful. Could, and maybe should, be a pytest test suite long-term, but at least for now wanted something that just needed the tool installed to run. --- Makefile | 3 ++ bin/test-e2e | 8 +++ tests-e2e/common.sh | 16 ++++++ tests-e2e/lib.sh | 7 +++ tests-e2e/test | 78 +++++++++++++++++++++++++++++ tests-e2e/test-local-templates | 59 ++++++++++++++++++++++ tests-e2e/test-no-initial-directory | 39 +++++++++++++++ 7 files changed, 210 insertions(+) create mode 100755 bin/test-e2e create mode 100644 tests-e2e/common.sh create mode 100644 tests-e2e/lib.sh create mode 100755 tests-e2e/test create mode 100755 tests-e2e/test-local-templates create mode 100755 tests-e2e/test-no-initial-directory diff --git a/Makefile b/Makefile index 7c396d3..54065f3 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,9 @@ lint-poetry: ## Run poetry checks test: ## Run tests $(PY_RUN) pytest $(args) +test-e2e: ## Run tests + ./bin/test-e2e $(args) + help: ## Display this help screen @grep -Eh '^[[:print:]]+:.*?##' $(MAKEFILE_LIST) | \ sort -d | \ diff --git a/bin/test-e2e b/bin/test-e2e new file mode 100755 index 0000000..d7b8f9b --- /dev/null +++ b/bin/test-e2e @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -e + +for test_script in tests-e2e/test*; do + echo "::group::${test_script}" + ./"${test_script}" + echo "::endgroup::" +done diff --git a/tests-e2e/common.sh b/tests-e2e/common.sh new file mode 100644 index 0000000..d4630a9 --- /dev/null +++ b/tests-e2e/common.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +source "$(realpath "$(dirname "${BASH_SOURCE[0]}")")/lib.sh" + +export CMD="${CMD:-nava-platform}" + +export PROJECT_NAME="${PROJECT_DIR:-foo}" +export PROJECT_DIR=${PROJECT_DIR:-$(mk_temp_dir "test-platform-project")} + +init_project_dir() { + rm -rf "${PROJECT_DIR}" + # vast majority of the time we are expecting to be working against an existing + # project (or at least an empty, but git-initialized project directory) + mkdir -p "${PROJECT_DIR}" + git init "${PROJECT_DIR}" +} diff --git a/tests-e2e/lib.sh b/tests-e2e/lib.sh new file mode 100644 index 0000000..d5e6c1e --- /dev/null +++ b/tests-e2e/lib.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +mk_temp_dir() { + local name="${1:-platform-cli-test-e2e}" + # macOS returns a symlink for $TMPDIR, so resolve to the actual path + realpath "$(mktemp -d "${TMPDIR:-/tmp}/${name}.XXXXXXXXX")" +} diff --git a/tests-e2e/test b/tests-e2e/test new file mode 100755 index 0000000..566ee37 --- /dev/null +++ b/tests-e2e/test @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# +# Simple, but more-or-less complete run through of core functionality. Doesn't +# really check that things are *correct*, just that they run without unexpected +# errors. + +set -xeuo pipefail + +####################### +# Setup +####################### + +source "$(realpath "$(dirname "${BASH_SOURCE[0]}")")/common.sh" + +init_project_dir + +####################### +# Test +####################### + +$CMD --help + +# TODO: add --data-file support to CLI and have as many of these +# settings in more maintainable separate file +$CMD infra install \ + --commit \ + --data base_project_name="${PROJECT_NAME}" \ + --data base_owner=platform-admins \ + --data base_code_repository_url=https://foo.example \ + --data base_default_region=us-east-1 \ + --data app_name=rails \ + --data app_local_port=3000 \ + --data app_has_dev_env_setup=true \ + "${PROJECT_DIR}" + +$CMD infra info "${PROJECT_DIR}" + +$CMD infra update "${PROJECT_DIR}" + +{ yes || true; } | $CMD app install \ + --template-uri https://github.com/navapbc/template-application-rails \ + --version platform-cli \ + --commit \ + "${PROJECT_DIR}" \ + rails \ + --data app_local_port=3000 + +$CMD app update \ + --template-uri https://github.com/navapbc/template-application-rails \ + --version platform-cli \ + "${PROJECT_DIR}" \ + rails + +for app_template in flask nextjs; do + $CMD infra add-app \ + --commit \ + --data app_name="${app_template}" \ + --data app_local_port=3000 \ + --data app_has_dev_env_setup=true \ + "${PROJECT_DIR}" \ + ${app_template} + + { yes || true; } | $CMD app install \ + --template-uri https://github.com/navapbc/template-application-"${app_template}" \ + --version platform-cli \ + --commit \ + "${PROJECT_DIR}" \ + "${app_template}" \ + --data app_local_port=3000 + + $CMD app update \ + --template-uri https://github.com/navapbc/template-application-"${app_template}" \ + --version platform-cli \ + "${PROJECT_DIR}" \ + "${app_template}" +done + +$CMD infra info "${PROJECT_DIR}" diff --git a/tests-e2e/test-local-templates b/tests-e2e/test-local-templates new file mode 100755 index 0000000..feafc8d --- /dev/null +++ b/tests-e2e/test-local-templates @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# +# Test that local templates work + +set -xeuo pipefail + +####################### +# Setup +####################### + +source "$(realpath "$(dirname "${BASH_SOURCE[0]}")")/common.sh" + +init_project_dir + +####################### +# Test +####################### + +infra_template_dir=$(mk_temp_dir) +git clone https://github.com/navapbc/template-infra.git "${infra_template_dir}" +git -C "${infra_template_dir}" checkout lorenyu/platform-cli + +# TODO: add --data-file support to CLI and have as many of these +# settings in more maintainable separate file +$CMD infra install \ + --template-uri "${infra_template_dir}" \ + --commit \ + --data base_project_name="${PROJECT_NAME}" \ + --data base_owner=platform-admins \ + --data base_code_repository_url=https://foo.example \ + --data base_default_region=us-east-1 \ + --data app_name=app \ + --data app_local_port=3000 \ + --data app_has_dev_env_setup=true \ + "${PROJECT_DIR}" + +$CMD infra update \ + --template-uri "${infra_template_dir}" \ + "${PROJECT_DIR}" + +rails_template_dir=$(mk_temp_dir) +git clone https://github.com/navapbc/template-application-rails "${rails_template_dir}" +git -C "${rails_template_dir}" checkout platform-cli + +{ yes || true; } | $CMD app install \ + --template-uri "${rails_template_dir}" \ + --version platform-cli \ + --template-name template-application-rails \ + --commit \ + "${PROJECT_DIR}" \ + app \ + --data app_local_port=3000 + +$CMD app update \ + --template-uri "${rails_template_dir}" \ + --version platform-cli \ + --template-name template-application-rails \ + "${PROJECT_DIR}" \ + app diff --git a/tests-e2e/test-no-initial-directory b/tests-e2e/test-no-initial-directory new file mode 100755 index 0000000..d5202e8 --- /dev/null +++ b/tests-e2e/test-no-initial-directory @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# Test that `install` commands will create the project directory when it doesn't +# already exist + +set -xeuo pipefail + +####################### +# Setup +####################### + +source "$(realpath "$(dirname "${BASH_SOURCE[0]}")")/common.sh" + +####################### +# Test +####################### + +rm -rf "${PROJECT_DIR}" + +# TODO: add --data-file support to CLI and have as many of these +# settings in more maintainable separate file +$CMD infra install \ + --data base_project_name="${PROJECT_NAME}" \ + --data base_owner=platform-admins \ + --data base_code_repository_url=https://foo.example \ + --data base_default_region=us-east-1 \ + --data app_name=app \ + --data app_local_port=3000 \ + --data app_has_dev_env_setup=true \ + "${PROJECT_DIR}" + +rm -rf "${PROJECT_DIR}" + +$CMD app install \ + --template-uri https://github.com/navapbc/template-application-rails \ + --version platform-cli \ + --data app_local_port=3000 \ + "${PROJECT_DIR}" \ + app