From 10f612f998a40204d80100424a931bf2406ff964 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 5 Sep 2023 13:03:38 +0200 Subject: [PATCH] test: more integration tests --- tests/integration/autocomplete.bats | 35 +++++++++++++++++++ tests/integration/catalogue.bats | 21 +++++++++++ tests/integration/install.bats | 38 ++++++++++++++++++++ tests/integration/recipe.bats | 54 +++++++++++++++++++++++++++++ tests/integration/upgrade.bats | 40 +++++++++++++++++++++ tests/integration/version.bats | 17 +++++++++ tests/manual/autocomplete.sh | 12 ------- tests/manual/catalogue.sh | 8 ----- tests/manual/install.sh | 12 ------- tests/manual/recipe.sh | 14 -------- 10 files changed, 205 insertions(+), 46 deletions(-) create mode 100644 tests/integration/autocomplete.bats create mode 100644 tests/integration/catalogue.bats create mode 100644 tests/integration/install.bats create mode 100644 tests/integration/upgrade.bats create mode 100644 tests/integration/version.bats delete mode 100755 tests/manual/autocomplete.sh delete mode 100755 tests/manual/catalogue.sh delete mode 100755 tests/manual/install.sh delete mode 100755 tests/manual/recipe.sh diff --git a/tests/integration/autocomplete.bats b/tests/integration/autocomplete.bats new file mode 100644 index 00000000..6d33bf4f --- /dev/null +++ b/tests/integration/autocomplete.bats @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env +} + +@test "bash autocompletion" { + run $ABRA autocomplete bash + assert_success + assert [ -f "$ABRA_DIR/autocompletion/bash" ] +} + +@test "zsh autocompletion" { + run $ABRA autocomplete zsh + assert_success + assert [ -f "$ABRA_DIR/autocompletion/zsh" ] +} + +@test "fish autocompletion" { + run $ABRA autocomplete fish + assert_success + assert [ -f "$ABRA_DIR/autocompletion/fish" ] +} + +@test "fizsh autocompletion" { + run $ABRA autocomplete fizsh + assert_success + assert [ -f "$ABRA_DIR/autocompletion/zsh" ] +} + +teardown(){ + _default_teardown +} diff --git a/tests/integration/catalogue.bats b/tests/integration/catalogue.bats new file mode 100644 index 00000000..c98ab365 --- /dev/null +++ b/tests/integration/catalogue.bats @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env +} + +@test "catalogue generate" { + run $ABRA catalogue generate + assert_success +} + +@test "catalogue generate specific recipe" { + run $ABRA catalogue generate gitea + assert_success +} + +teardown(){ + _default_teardown +} diff --git a/tests/integration/install.bats b/tests/integration/install.bats new file mode 100644 index 00000000..6385e11f --- /dev/null +++ b/tests/integration/install.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env + + if [[ -f "$HOME/.local/bin/abra" ]]; then + mv "$HOME/.local/bin/abra" "$HOME/.local/bin/abra_before_test" + fi +} + +@test "install from script" { + run bash -c 'curl https://install.abra.coopcloud.tech | bash' + assert_success + + assert [ -f "$HOME/.local/bin/abra" ] + run $HOME/.local/bin/abra -v + assert_output --partial 'beta' +} + +@test "install release candidate from script" { + run bash -c 'curl https://install.abra.coopcloud.tech | bash -s -- --rc' + assert_success + + assert [ -f "$HOME/.local/bin/abra" ] + run $HOME/.local/bin/abra -v + assert_output --partial '-rc' +} + +teardown(){ + _default_teardown + + if [[ -f "$HOME/.local/bin/abra_before_test" ]]; then + rm -rf "$HOME/.local/bin/abra" + mv "$HOME/.local/bin/abra_before_test" "$HOME/.local/bin/abra" + fi +} diff --git a/tests/integration/recipe.bats b/tests/integration/recipe.bats index c8d1bcb9..833ace07 100644 --- a/tests/integration/recipe.bats +++ b/tests/integration/recipe.bats @@ -24,6 +24,60 @@ setup() { assert_output --partial 'A new foobar app has been created!' } +@test "recipe fetch" { + run $ABRA recipe fetch matrix-synapse + assert_success + assert [ -d "$ABRA_DIR/recipes/matrix-synapse" ] +} + +@test "recipe sync allows unstaged changes" { + run $ABRA recipe fetch matrix-synapse + assert_success + + run echo "unstaged changes" >> "$ABRA_DIR/recipes/matrix-synapse/foo" + assert_success + + run $ABRA recipe sync matrix-synapse --patch + assert_success +} + +@test "recipe sync detects unstaged label changes" { + run $ABRA recipe fetch matrix-synapse + assert_success + + run $ABRA recipe sync matrix-synapse --patch + assert_success + + run $ABRA recipe sync matrix-synapse --patch + assert_success + assert_output --partial 'is already set, nothing to do?' +} + +@test "recipe list" { + run $ABRA recipe list + assert_success + NUM_RECIPES=$(jq length "$ABRA_DIR/catalogue/recipes.json") + assert_output --partial "total recipes: $NUM_RECIPES" +} + +@test "recipe list with pattern" { + run $ABRA recipe list --pattern cloud + assert_success + assert_output --partial 'nextcloud' + refute_output --partial 'matrix-synapse' +} + +@test "recipe lint" { + run $ABRA recipe lint gitea + assert_success +} + +@test "recipe versions" { + run $ABRA recipe versions gitea + assert_success + assert_output --partial '2.3.2+1.20.3-rootless' +} + teardown() { _default_teardown diff --git a/tests/integration/upgrade.bats b/tests/integration/upgrade.bats new file mode 100644 index 00000000..6022cfde --- /dev/null +++ b/tests/integration/upgrade.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env + + if [[ -f "$HOME/.local/bin/abra" ]]; then + mv "$HOME/.local/bin/abra" "$HOME/.local/bin/abra_before_test" + fi +} + +@test "abra upgrade" { + run $ABRA upgrade + assert_success + assert_output --partial 'Public interest infrastructure' + + assert [ -f "$HOME/.local/bin/abra" ] + run $HOME/.local/bin/abra -v + assert_output --partial 'beta' +} + +@test "abra upgrade release candidate" { + run $ABRA upgrade --rc + assert_success + assert_output --partial 'Public interest infrastructure' + + assert [ -f "$HOME/.local/bin/abra" ] + run $HOME/.local/bin/abra -v + assert_output --partial '-rc' +} + +teardown(){ + _default_teardown + + if [[ -f "$HOME/.local/bin/abra_before_test" ]]; then + rm -rf "$HOME/.local/bin/abra" + mv "$HOME/.local/bin/abra_before_test" "$HOME/.local/bin/abra" + fi +} diff --git a/tests/integration/version.bats b/tests/integration/version.bats new file mode 100644 index 00000000..dcc77a08 --- /dev/null +++ b/tests/integration/version.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + source "$DIR/helpers.sh" + _setup_env +} + +@test "abra version" { + run $ABRA -v + assert_success + assert_output --partial 'dev' +} + +teardown(){ + _default_teardown +} diff --git a/tests/manual/autocomplete.sh b/tests/manual/autocomplete.sh deleted file mode 100755 index 4ea2ef88..00000000 --- a/tests/manual/autocomplete.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -source ./testfunctions.sh -source ./common.sh - -run_test '$ABRA autocomplete bash' - -run_test '$ABRA autocomplete fizsh' - -run_test '$ABRA autocomplete zsh' - -run_test '$ABRA autocomplete fish' diff --git a/tests/manual/catalogue.sh b/tests/manual/catalogue.sh deleted file mode 100755 index cadecfb3..00000000 --- a/tests/manual/catalogue.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -source ./testfunctions.sh -source ./common.sh - -run_test '$ABRA catalogue generate' - -run_test '$ABRA catalogue generate gitea' diff --git a/tests/manual/install.sh b/tests/manual/install.sh deleted file mode 100755 index 0f3897ac..00000000 --- a/tests/manual/install.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -source ./testfunctions.sh -source ./common.sh - -run_test 'wget -O- https://install.abra.autonomic.zone | bash; ~/.local/bin/abra -v' - -run_test 'wget -O- https://install.abra.autonomic.zone | bash -s -- --rc; ~/.local/bin/abra -v' - -run_test '$ABRA upgrade; ~/.local/bin/abra -v' - -run_test '$ABRA upgrade --rc; ~/.local/bin/abra -v' diff --git a/tests/manual/recipe.sh b/tests/manual/recipe.sh deleted file mode 100755 index 7ac3b129..00000000 --- a/tests/manual/recipe.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -source ./testfunctions.sh -source ./common.sh - -run_test '$ABRA recipe new testrecipe' - -run_test '$ABRA recipe list' - -run_test '$ABRA recipe list --pattern cloud' - -run_test '$ABRA recipe versions peertube' - -run_test '$ABRA recipe lint gitea'