From 0a765794f23d71f63ebf8ef328e0d50eb7a5f6af Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 5 Sep 2023 11:12:21 +0200 Subject: [PATCH] test: write initial automatic integration tests --- tests/integration/dirs.bats | 39 +++++++++++++++++++++++++++++++++++ tests/integration/helpers.sh | 36 ++++++++++++++++++++++++++++++++ tests/integration/recipe.bats | 33 +++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/integration/dirs.bats create mode 100644 tests/integration/helpers.sh create mode 100644 tests/integration/recipe.bats diff --git a/tests/integration/dirs.bats b/tests/integration/dirs.bats new file mode 100644 index 00000000..bc326652 --- /dev/null +++ b/tests/integration/dirs.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env +} + +@test "ensure abra directories created" { + run $ABRA app ls + + # no servers yet, so will fail. however, it will run the required code which + # checks if it should create these base directories and that is what we want + assert_failure + + assert [ -d "$ABRA_TEST_DIR" ] + assert [ -d "$ABRA_TEST_DIR/servers" ] + assert [ -d "$ABRA_TEST_DIR/recipes" ] + assert [ -d "$ABRA_TEST_DIR/backups" ] + assert [ -d "$ABRA_TEST_DIR/vendor" ] + assert [ -d "$ABRA_TEST_DIR/catalogue" ] +} + +@test "ensure catalogue recipe is a git repository" { + run $ABRA app ls + + # no servers yet, so will fail. however, it will run the required code which + # checks if it should create these base directories and that is what we want + assert_failure + + assert_output --partial 'local recipe catalogue is missing' + + assert [ -d "$ABRA_TEST_DIR/catalogue" ] + assert [ -d "$ABRA_TEST_DIR/catalogue/.git" ] +} + +teardown(){ + _default_teardown +} diff --git a/tests/integration/helpers.sh b/tests/integration/helpers.sh new file mode 100644 index 00000000..19836a22 --- /dev/null +++ b/tests/integration/helpers.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +_build_abra() { + if [[ ! -e "$ROOT/abra" ]]; then + cd "$ROOT" && make build-dev + return 0 + fi + return 0 +} + +_build_kadabra() { + if [[ ! -e "$ROOT/kadabra" ]]; then + cd "$ROOT" && make build-dev + return 0 + fi + return 0 +} + +_setup_env(){ + load '/usr/lib/bats/bats-support/load' + load '/usr/lib/bats/bats-assert/load' + + ROOT="$DIR/../.." + ABRA="$ROOT/abra" + KADABRA="$ROOT/kadabra" + + ABRA_TEST=true + ABRA_TEST_DIR="$HOME/.abra_test" + + _build_abra + _build_kadabra +} + +_default_teardown(){ + rm -rf "$ABRA_TEST_DIR" +} diff --git a/tests/integration/recipe.bats b/tests/integration/recipe.bats new file mode 100644 index 00000000..c8d1bcb9 --- /dev/null +++ b/tests/integration/recipe.bats @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env + + mkdir -p "$HOME/.abra_test/servers/example.com" + if ! grep -R -q "example.com" "$HOME/.docker"; then + docker context create --docker host=ssh://foo@example.com:222 example.com + fi +} + +@test "create new recipe" { + run $ABRA recipe new foobar + assert_success + assert_output --partial 'Your new foobar recipe has been created' + + run $ABRA app new foobar \ + --no-input \ + --server example.com \ + --domain foobar.example.com + assert_success + assert_output --partial 'A new foobar app has been created!' +} + +teardown() { + _default_teardown + + if grep -R -q "example.com" "$HOME/.docker"; then + docker context rm example.com + fi +}