From fd8652e26dbc0ef38e1cccfc010f3cd255d1ccb1 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 24 Jul 2024 16:08:09 +0200 Subject: [PATCH] fix: --chaos/--offline for `abra app ps` See https://git.coopcloud.tech/coop-cloud/organising/issues/628 See https://git.coopcloud.tech/coop-cloud/organising/issues/629 --- cli/app/ps.go | 11 ++--- tests/integration/app_ps.bats | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/cli/app/ps.go b/cli/app/ps.go index b094eafd..c8149b2c 100644 --- a/cli/app/ps.go +++ b/cli/app/ps.go @@ -30,12 +30,14 @@ var appPsCommand = cli.Command{ Flags: []cli.Flag{ internal.MachineReadableFlag, internal.DebugFlag, + internal.ChaosFlag, + internal.OfflineFlag, }, Before: internal.SubCommandBefore, BashComplete: autocomplete.AppNameComplete, Action: func(c *cli.Context) error { app := internal.ValidateApp(c) - if err := app.Recipe.Ensure(false, false); err != nil { + if err := app.Recipe.Ensure(internal.Chaos, internal.Offline); err != nil { log.Fatal(err) } @@ -56,12 +58,7 @@ var appPsCommand = cli.Command{ chaosVersion := config.CHAOS_DEFAULT statuses, err := appPkg.GetAppStatuses([]appPkg.App{app}, true) if statusMeta, ok := statuses[app.StackName()]; ok { - isChaos, exists := statusMeta["chaos"] - if exists && isChaos == "false" { - if _, err := app.Recipe.EnsureVersion(deployMeta.Version); err != nil { - log.Fatal(err) - } - } else { + if isChaos, exists := statusMeta["chaos"]; exists && isChaos == "true" { chaosVersion, err = app.Recipe.ChaosVersion() if err != nil { log.Fatal(err) diff --git a/tests/integration/app_ps.bats b/tests/integration/app_ps.bats index b0f64f51..fad17c78 100644 --- a/tests/integration/app_ps.bats +++ b/tests/integration/app_ps.bats @@ -31,6 +31,84 @@ teardown(){ assert_output --partial 'cannot find app' } +# bats test_tags=slow +@test "retrieve recipe if missing" { + _deploy_app + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" + assert_success + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" + + run $ABRA app ps "$TEST_APP_DOMAIN" + assert_success + + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" +} + +# bats test_tags=slow +@test "bail if unstaged changes and no --chaos" { + _deploy_app + + run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app ps "$TEST_APP_DOMAIN" + 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" +} + +# bats test_tags=slow +@test "do not bail if unstaged changes and --chaos" { + _deploy_app + + run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app ps --chaos "$TEST_APP_DOMAIN" + assert_success + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" +} + +# bats test_tags=slow +@test "ensure recipe up to date if no --offline" { + _deploy_app + + 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 ps "$TEST_APP_DOMAIN" + assert_success + + assert_equal $(_get_head_hash) $(_get_current_hash) +} + +@test "ensure recipe not up to date if --offline" { + _deploy_app + + _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 ps --offline "$TEST_APP_DOMAIN" + assert_success + + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l + refute_output --partial "$latestRelease" +} + @test "error if not deployed" { run $ABRA app ps "$TEST_APP_DOMAIN" assert_failure