#!/usr/bin/env bash setup_file(){ load "$PWD/tests/integration/helpers/common" _common_setup _add_server _new_app } teardown_file(){ _rm_app _rm_server _reset_recipe } setup(){ load "$PWD/tests/integration/helpers/common" _common_setup } teardown(){ _reset_recipe _reset_tags } @test "validate app argument" { run $ABRA app check assert_failure run $ABRA app check DOESNTEXIST assert_failure } @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 check "$TEST_APP_DOMAIN" assert_success 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 check "$TEST_APP_DOMAIN" assert_failure assert_output --partial 'locally unstaged changes' assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" assert_equal "$(_git_status)" "?? foo" 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 "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"' assert_success assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" run $ABRA app check "$TEST_APP_DOMAIN" --chaos assert_success assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" assert_equal "$(_git_status)" "?? foo" 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" { wantHash=$(_get_n_hash 3) run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 assert_success assert_equal $(_get_current_hash) "$wantHash" run $ABRA app check "$TEST_APP_DOMAIN" assert_success assert_equal $(_get_head_hash) $(_get_current_hash) } @test "ensure recipe not up to date if --offline" { _ensure_env_version "0.1.0+1.20.0" latestRelease=$(_latest_release) run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease" assert_success # NOTE(d1): don't assert success because it might flake run $ABRA app check "$TEST_APP_DOMAIN" --offline run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l refute_output --partial "$latestRelease" } @test "error if missing .env.sample" { run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample" assert_success run $ABRA app check "$TEST_APP_DOMAIN" --chaos assert_failure assert_output --partial 'unable to discover .env.sample' } @test "error if missing env var" { run $ABRA app check "$TEST_APP_DOMAIN" assert_success refute_output --partial '❌' run bash -c 'echo "NEW_VAR=foo" >> "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample"' assert_success run $ABRA app check "$TEST_APP_DOMAIN" --chaos assert_success assert_output --partial '❌' } # bats test_tags=slow @test "respects env version" { tagHash=$(_get_tag_hash "0.1.0+1.20.0") run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks assert_success run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" assert_success run $ABRA app check "$TEST_APP_DOMAIN" assert_success assert_equal $(_get_current_hash) "$tagHash" }