diff --git a/tests/integration/README.md b/tests/integration/README.md index e1447840..feefe70b 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -2,3 +2,10 @@ - `cp .envrc.sample .envrc` (fill out values && `direnv allow`) - `TARGET=install.sh make` (ensure `docker context use default`) + +`testfunctions.sh` contains the functions necessary to save and manipulate logs +run `test_all.sh logdir` to run tests specified in that file and save the logs to `logdir` +when creating new tests, make sure the test command is a one-liner (you can use `;` to separate commands). include `testfunctions.sh` and then write your tests like this: +`run_test '$ABRA other stuff here'` + +by default, the testing script will ask after every command if the execution succeeded. If you reply `n`, it will log the test in the `logdir`. If you want all tests to run without questions, run `export logall=yes` before executing the test script diff --git a/tests/integration/app.sh b/tests/integration/app.sh index 851d9b49..5921dfd3 100755 --- a/tests/integration/app.sh +++ b/tests/integration/app.sh @@ -1,15 +1,16 @@ #!/bin/bash +source ./testfunctions.sh source ./common.sh echo "all apps, all servers" -$ABRA app ls +run_test '$ABRA app ls' printf "\\n\\n\\n" echo "all wordpress apps, all servers" -$ABRA app ls --type wordpress +run_test '$ABRA app ls --type wordpress' printf "\\n\\n\\n" echo "all wordpress apps, only server2" -$ABRA app ls --type wordpress --server server2 +run_test '$ABRA app ls --type wordpress --server server2' printf "\\n\\n\\n" diff --git a/tests/integration/autocomplete.sh b/tests/integration/autocomplete.sh index e0770ca9..ebac80de 100755 --- a/tests/integration/autocomplete.sh +++ b/tests/integration/autocomplete.sh @@ -1,9 +1,10 @@ #!/bin/bash +source ./testfunctions.sh source ./common.sh -$ABRA autocomplete bash +run_test '$ABRA autocomplete bash' -$ABRA autocomplete fizsh +run_test '$ABRA autocomplete fizsh' -$ABRA autocomplete zsh +run_test '$ABRA autocomplete zsh' diff --git a/tests/integration/catalogue.sh b/tests/integration/catalogue.sh index 5522f12e..9513f604 100755 --- a/tests/integration/catalogue.sh +++ b/tests/integration/catalogue.sh @@ -1,7 +1,8 @@ #!/bin/bash +source ./testfunctions.sh source ./common.sh -$ABRA catalogue generate --debug +run_test '$ABRA --debug catalogue generate' -$ABRA catalogue generate gitea --debug +run_test '$ABRA --debug catalogue generate gitea' diff --git a/tests/integration/install.sh b/tests/integration/install.sh index a0c31a39..0f3897ac 100755 --- a/tests/integration/install.sh +++ b/tests/integration/install.sh @@ -1,15 +1,12 @@ #!/bin/bash +source ./testfunctions.sh source ./common.sh -wget -O- https://install.abra.autonomic.zone | bash -~/.local/bin/abra -v +run_test 'wget -O- https://install.abra.autonomic.zone | bash; ~/.local/bin/abra -v' -wget -O- https://install.abra.autonomic.zone | bash -s -- --rc -~/.local/bin/abra -v +run_test 'wget -O- https://install.abra.autonomic.zone | bash -s -- --rc; ~/.local/bin/abra -v' -$ABRA upgrade -~/.local/bin/abra -v +run_test '$ABRA upgrade; ~/.local/bin/abra -v' -$ABRA upgrade --rc -~/.local/bin/abra -v +run_test '$ABRA upgrade --rc; ~/.local/bin/abra -v' diff --git a/tests/integration/recipe.sh b/tests/integration/recipe.sh index 76ead9cd..7ef627a0 100755 --- a/tests/integration/recipe.sh +++ b/tests/integration/recipe.sh @@ -1,12 +1,13 @@ #!/bin/bash +source ./testfunctions.sh source ./common.sh -$ABRA recipe new testrecipe +run_test '$ABRA recipe new testrecipe' -$ABRA recipe list -$ABRA recipe list -p cloud +run_test '$ABRA recipe list' +run_test '$ABRA recipe list -p cloud' -$ABRA recipe versions peertube +run_test '$ABRA recipe versions peertube' -$ABRA recipe lint gitea +run_test '$ABRA recipe lint gitea' diff --git a/tests/integration/test_all.sh b/tests/integration/test_all.sh new file mode 100755 index 00000000..3a6a1a9a --- /dev/null +++ b/tests/integration/test_all.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ -z $1 ]; then + echo "usage: ./test_all.sh logdir" + exit +fi + +res_dir=$1/ +if [[ ! -d "$res_dir" ]]; then + mkdir "$res_dir" +fi + +# Usage: run_test [number] [name] [command] +run_test () { + logfile="$res_dir/$1-$2.log" + echo $logfile +} + +testScripts=("app.sh" "recipe.sh" "install.sh") + +for i in "${testScripts[@]}"; do + cmd="./$i $res_dir${i/sh/log}" + eval $cmd +done diff --git a/tests/integration/testfunctions.sh b/tests/integration/testfunctions.sh new file mode 100644 index 00000000..39b1ae72 --- /dev/null +++ b/tests/integration/testfunctions.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +if [ -z $1 ]; then + logfile=/dev/null +else + logfile=$1 +fi + +if [ -z $logall ]; then + logall=no +fi + +run_test () { + if [ -z "$@" ]; then + echo "run_test needs a command to run" + else + tempLogfile=$(mktemp) + cmd=$(eval echo "$@") + echo "------------ INPUT -------------------" | tee -a $tempLogfile + echo "$" "$cmd" | tee -a $tempLogfile + echo "------------ OUTPUT ------------------" | tee -a $tempLogfile + eval $cmd 2>&1 | tee -a $tempLogfile + if [ $logall = "yes" ]; then + cat $tempLogfile >> $logfile + echo -e "\\n\\n" >> $logfile + else + read -N 1 -p "Did the test pass? [y/n]: " pass + if [ $pass = 'n' ]; then + cat $tempLogfile >> $logfile + echo -e "\\n\\n" >> $logfile + fi + fi + rm $tempLogfile + fi +}