Skip to content

Commit

Permalink
Add "e2e" test scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
doshitan committed Jan 3, 2025
1 parent 725338f commit 99d8ba2
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand Down
8 changes: 8 additions & 0 deletions bin/test-e2e
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions tests-e2e/common.sh
Original file line number Diff line number Diff line change
@@ -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}"
}
7 changes: 7 additions & 0 deletions tests-e2e/lib.sh
Original file line number Diff line number Diff line change
@@ -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")"
}
78 changes: 78 additions & 0 deletions tests-e2e/test
Original file line number Diff line number Diff line change
@@ -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}"
59 changes: 59 additions & 0 deletions tests-e2e/test-local-templates
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions tests-e2e/test-no-initial-directory
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 99d8ba2

Please sign in to comment.