-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
atlasaction: setup testscript for github action (#225)
- Loading branch information
Showing
6 changed files
with
247 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
# TEST_BATCH provide the directory containts all | ||
# outputs for multiple runs. The path should be absolulate | ||
# or related to current working directory. | ||
if [[ "$TEST_BATCH" != "" ]]; then | ||
COUNTER_FILE=$TEST_BATCH/counter | ||
COUNTER=$(cat $COUNTER_FILE 2>/dev/null) | ||
COUNTER=$((COUNTER+1)) | ||
DIR_CUR="$TEST_BATCH/$COUNTER" | ||
if [ ! -d "$DIR_CUR" ]; then | ||
>&2 echo -n "$DIR_CUR does not exist, quitting..." | ||
exit 1 | ||
fi | ||
# Save counter for the next runs | ||
echo -n $COUNTER > $COUNTER_FILE | ||
if [ -f "$DIR_CUR/args" ]; then | ||
TEST_ARGS=$(cat $DIR_CUR/args) | ||
fi | ||
if [ -f "$DIR_CUR/stderr" ]; then | ||
TEST_STDERR=$(cat $DIR_CUR/stderr) | ||
fi | ||
if [ -f "$DIR_CUR/stdout" ]; then | ||
TEST_STDOUT=$(cat $DIR_CUR/stdout) | ||
fi | ||
fi | ||
|
||
if [[ "$TEST_ARGS" != "$@" ]]; then | ||
>&2 echo "Receive unexpected args: $@" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$TEST_STDOUT" != "" ]]; then | ||
echo -n $TEST_STDOUT | ||
if [[ "$TEST_STDERR" == "" ]]; then | ||
exit 0 # No stderr | ||
fi | ||
# In some cases, Atlas will write the error in stderr | ||
# when if the command is partially successful. | ||
# eg. Run the apply commands with multiple environments. | ||
>&2 echo -n $TEST_STDERR | ||
exit 1 | ||
fi | ||
|
||
TEST_STDERR="${TEST_STDERR:-Missing stderr either stdout input for the test}" | ||
>&2 echo -n $TEST_STDERR | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Mock the atlas command outputs | ||
mock-atlas $WORK/migrate-test | ||
# Setup the action input variables | ||
env INPUT_CONFIG=file://testdata/config/atlas.hcl | ||
env INPUT_ENV=test | ||
env INPUT_VARS='{"var1":"value1","var2":"value2"}' | ||
env INPUT_DIR=file://testdata/migrations | ||
env INPUT_DEV_URL=sqlite://file?mode=memory | ||
env INPUT_RUN=example | ||
|
||
atlas-action migrate/test | ||
stdout '`atlas migrate test` completed successfully, no issues found' | ||
stdout 'Success' | ||
! output | ||
|
||
! atlas-action migrate/test | ||
stderr '`atlas migrate test` completed with errors:' | ||
stderr 'Failure' | ||
! output | ||
|
||
-- migrate-test/1/args -- | ||
migrate test --env test --config file://testdata/config/atlas.hcl --dir file://testdata/migrations --run example --var var1=value1 --var var2=value2 | ||
-- migrate-test/1/stdout -- | ||
Success | ||
-- migrate-test/2/args -- | ||
migrate test --env test --config file://testdata/config/atlas.hcl --dir file://testdata/migrations --run example --var var1=value1 --var var2=value2 | ||
-- migrate-test/2/stderr -- | ||
Failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Mock the atlas command outputs | ||
mock-atlas $WORK/schema-test | ||
# Setup the action input variables | ||
env INPUT_CONFIG=file://testdata/config/atlas.hcl | ||
env INPUT_ENV=test | ||
env INPUT_VARS='{"var1":"value1","var2":"value2"}' | ||
env INPUT_DEV_URL=sqlite://file?mode=memory | ||
env INPUT_RUN=example | ||
|
||
atlas-action schema/test | ||
stdout '`atlas schema test` completed successfully, no issues found' | ||
stdout 'Success' | ||
! output | ||
|
||
! atlas-action schema/test | ||
stderr '`atlas schema test` completed with errors:' | ||
stderr 'Failure' | ||
! output | ||
|
||
-- schema-test/1/args -- | ||
schema test --env test --config file://testdata/config/atlas.hcl --run example --var var1=value1 --var var2=value2 | ||
-- schema-test/1/stdout -- | ||
Success | ||
-- schema-test/2/args -- | ||
schema test --env test --config file://testdata/config/atlas.hcl --run example --var var1=value1 --var var2=value2 | ||
-- schema-test/2/stderr -- | ||
Failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters