fix: unstaged changes handling

See toolshed/organising#651
This commit is contained in:
2024-12-31 11:19:03 +01:00
parent bfed51a69c
commit 5975be6870
26 changed files with 622 additions and 56 deletions

View File

@ -65,7 +65,6 @@ teardown(){
run $ABRA app deploy "$TEST_APP_DOMAIN" \
--chaos --no-input --no-converge-checks
assert_success
assert_output --partial 'NEW CHAOS'
}
# bats test_tags=slow
@ -128,7 +127,6 @@ teardown(){
--no-input --no-converge-checks --chaos
assert_success
assert_output --partial "${wantHash:0:8}"
assert_output --partial 'NEW CHAOS'
}
# bats test_tags=slow
@ -347,3 +345,18 @@ teardown(){
run $ABRA app secret rm "$TEST_APP_DOMAIN" --all
assert_success
}
# bats test_tags=slow
@test "chaos version label includes dirty marker" {
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_success
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
run $ABRA app deploy "$TEST_APP_DOMAIN" \
--no-input --no-converge-checks --chaos
assert_success
run $ABRA app labels "$TEST_APP_DOMAIN" --chaos
assert_success
assert_output --regexp 'chaos-version.*+U'
}

View File

@ -0,0 +1,109 @@
#!/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
_ensure_catalogue
}
teardown(){
_reset_recipe
_reset_app
_undeploy_app
_reset_tags
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
}
@test "validate app argument" {
run $ABRA app labels
assert_failure
run $ABRA app labels DOESNTEXIST
assert_failure
}
@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 git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_success
assert_output --partial 'foo'
run $ABRA app labels "$TEST_APP_DOMAIN" --no-input
assert_failure
}
@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 git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_success
assert_output --partial 'foo'
run $ABRA app labels "$TEST_APP_DOMAIN" --chaos
assert_success
}
@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 labels "$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
run $ABRA app labels "$TEST_APP_DOMAIN" --offline
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
refute_output --partial "$latestRelease"
}
@test "show unknown if no deloyment" {
run $ABRA app labels "$TEST_APP_DOMAIN"
assert_success
assert_output --partial 'unknown'
}
# bats test_tags=slow
@test "show deploy labels when deployed" {
run $ABRA app deploy "$TEST_APP_DOMAIN" \
--no-input --no-converge-checks
assert_success
run $ABRA app labels "$TEST_APP_DOMAIN"
assert_success
assert_output --partial 'com.docker.stack.image'
}

View File

@ -137,3 +137,16 @@ teardown(){
assert_output --partial "$latestRelease"
assert_output --partial "${headHash:0:8}" # is a chaos deploy
}
# bats test_tags=slow
@test "ensure live chaos commit is shown" {
headHash=$(_get_head_hash)
run $ABRA app deploy "$TEST_APP_DOMAIN" "0f5a0570" --no-input
assert_success
run $ABRA app ps "$TEST_APP_DOMAIN"
assert_success
assert_output --partial "0f5a0570" # is not latest HEAD
refute_output --partial "${headHash:0:8}"
}

View File

@ -1,3 +1,3 @@
RECIPE=ecloud
DOMAIN=ecloud.evil.corp
SMTP_AUTHTYPE=login
SMTP_AUTHTYPE=login