183 lines
4.5 KiB
Bash
183 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
setup_file(){
|
|
load "$PWD/tests/integration/helpers/common"
|
|
_common_setup
|
|
_add_server
|
|
_new_app
|
|
}
|
|
|
|
teardown_file(){
|
|
_rm_app
|
|
_rm_server
|
|
}
|
|
|
|
setup(){
|
|
load "$PWD/tests/integration/helpers/common"
|
|
_common_setup
|
|
}
|
|
|
|
teardown(){
|
|
# https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888
|
|
if [[ -z "${BATS_TEST_COMPLETED}" ]]; then
|
|
_undeploy_app
|
|
fi
|
|
}
|
|
|
|
@test "validate app argument" {
|
|
run $ABRA app cmd
|
|
assert_failure
|
|
assert_output --partial 'no app provided'
|
|
|
|
run $ABRA app cmd DOESNTEXIST
|
|
assert_failure
|
|
assert_output --partial 'cannot find app'
|
|
}
|
|
|
|
@test "retrieve recipe if missing" {
|
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
assert_success
|
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
}
|
|
|
|
@test "bail if unstaged changes and no --chaos" {
|
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
assert_success
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local
|
|
assert_failure
|
|
assert_output --partial 'locally unstaged changes'
|
|
|
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
}
|
|
|
|
@test "do not bail if unstaged changes and --chaos" {
|
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
assert_success
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --chaos
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
|
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
}
|
|
|
|
@test "ensure recipe up to date if no --offline" {
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
|
assert_success
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_output --partial 'behind 3'
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
refute_output --partial 'behind 3'
|
|
|
|
_reset_recipe "$TEST_RECIPE"
|
|
}
|
|
|
|
@test "ensure recipe not up to date if --offline" {
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
|
assert_success
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_output --partial 'behind 3'
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --offline
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_output --partial 'behind 3'
|
|
|
|
_reset_recipe "$TEST_RECIPE"
|
|
}
|
|
|
|
@test "error if missing arguments without passing --local" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN"
|
|
assert_failure
|
|
assert_output --partial 'missing arguments'
|
|
}
|
|
|
|
@test "error if missing arguments when passing --local" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" --local
|
|
assert_failure
|
|
assert_output --partial 'missing arguments'
|
|
}
|
|
|
|
@test "cannot use --local and --user at same time" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --user root
|
|
assert_failure
|
|
assert_output --partial 'cannot use --local & --user together'
|
|
}
|
|
|
|
@test "error if missing abra.sh" {
|
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh"
|
|
assert_success
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --chaos
|
|
assert_failure
|
|
assert_output --partial "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh does not exist"
|
|
|
|
_checkout_recipe "$TEST_RECIPE"
|
|
}
|
|
|
|
@test "error if missing command" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" doesnt_exist --local
|
|
assert_failure
|
|
assert_output --partial "doesn't have a doesnt_exist function"
|
|
}
|
|
|
|
@test "run --local command" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
}
|
|
|
|
@test "run command with single arg" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd_arg --local -- bing
|
|
assert_success
|
|
assert_output --partial 'bing'
|
|
}
|
|
|
|
@test "run command with several args" {
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd_args --local -- bong bang
|
|
assert_success
|
|
assert_output --partial 'bong bang'
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "run command on service" {
|
|
_deploy_app
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" app test_cmd
|
|
assert_success
|
|
assert_output --partial 'baz'
|
|
|
|
_undeploy_app
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "error if missing service" {
|
|
_deploy_app
|
|
|
|
run $ABRA app cmd "$TEST_APP_DOMAIN" doesnt_exist test_cmd
|
|
assert_failure
|
|
assert_output --partial 'no service doesnt_exist'
|
|
|
|
_undeploy_app
|
|
}
|