forked from toolshed/abra
		
	fix: --offline/--chaos handlings for backup/check/cmd/restore
This commit is contained in:
		| @ -41,6 +41,7 @@ var appBackupCommand = cli.Command{ | |||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		internal.OfflineFlag, | 		internal.OfflineFlag, | ||||||
|  | 		internal.ChaosFlag, | ||||||
| 	}, | 	}, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| 	BashComplete: autocomplete.AppNameComplete, | 	BashComplete: autocomplete.AppNameComplete, | ||||||
| @ -78,6 +79,22 @@ This single file can be used to restore your app. See "abra app restore" for mor | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if !internal.Chaos { | ||||||
|  | 			if err := recipePkg.EnsureIsClean(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if !internal.Offline { | ||||||
|  | 				if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil { | ||||||
|  | 					logrus.Fatal(err) | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := recipePkg.EnsureLatest(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		backupConfigs := make(map[string]backupConfig) | 		backupConfigs := make(map[string]backupConfig) | ||||||
| 		for _, service := range recipe.Config.Services { | 		for _, service := range recipe.Config.Services { | ||||||
| 			if backupsEnabled, ok := service.Deploy.Labels["backupbot.backup"]; ok { | 			if backupsEnabled, ok := service.Deploy.Labels["backupbot.backup"]; ok { | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/autocomplete" | 	"coopcloud.tech/abra/pkg/autocomplete" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/abra/pkg/recipe" | 	"coopcloud.tech/abra/pkg/recipe" | ||||||
|  | 	recipePkg "coopcloud.tech/abra/pkg/recipe" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli" | 	"github.com/urfave/cli" | ||||||
| ) | ) | ||||||
| @ -20,6 +21,8 @@ var appCheckCommand = cli.Command{ | |||||||
| 	ArgsUsage: "<domain>", | 	ArgsUsage: "<domain>", | ||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
|  | 		internal.ChaosFlag, | ||||||
|  | 		internal.OfflineFlag, | ||||||
| 	}, | 	}, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| 	BashComplete: autocomplete.AppNameComplete, | 	BashComplete: autocomplete.AppNameComplete, | ||||||
| @ -30,6 +33,22 @@ var appCheckCommand = cli.Command{ | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if !internal.Chaos { | ||||||
|  | 			if err := recipePkg.EnsureIsClean(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if !internal.Offline { | ||||||
|  | 				if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil { | ||||||
|  | 					logrus.Fatal(err) | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := recipePkg.EnsureLatest(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		envSamplePath := path.Join(config.RECIPES_DIR, app.Recipe, ".env.sample") | 		envSamplePath := path.Join(config.RECIPES_DIR, app.Recipe, ".env.sample") | ||||||
| 		if _, err := os.Stat(envSamplePath); err != nil { | 		if _, err := os.Stat(envSamplePath); err != nil { | ||||||
| 			if os.IsNotExist(err) { | 			if os.IsNotExist(err) { | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/abra/pkg/recipe" | 	"coopcloud.tech/abra/pkg/recipe" | ||||||
|  | 	recipePkg "coopcloud.tech/abra/pkg/recipe" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli" | 	"github.com/urfave/cli" | ||||||
| ) | ) | ||||||
| @ -39,6 +40,8 @@ Example: | |||||||
| 		internal.LocalCmdFlag, | 		internal.LocalCmdFlag, | ||||||
| 		internal.RemoteUserFlag, | 		internal.RemoteUserFlag, | ||||||
| 		internal.TtyFlag, | 		internal.TtyFlag, | ||||||
|  | 		internal.OfflineFlag, | ||||||
|  | 		internal.ChaosFlag, | ||||||
| 	}, | 	}, | ||||||
| 	BashComplete: autocomplete.AppNameComplete, | 	BashComplete: autocomplete.AppNameComplete, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| @ -49,6 +52,22 @@ Example: | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if !internal.Chaos { | ||||||
|  | 			if err := recipePkg.EnsureIsClean(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if !internal.Offline { | ||||||
|  | 				if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil { | ||||||
|  | 					logrus.Fatal(err) | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := recipePkg.EnsureLatest(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		if internal.LocalCmd && internal.RemoteUser != "" { | 		if internal.LocalCmd && internal.RemoteUser != "" { | ||||||
| 			internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together")) | 			internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together")) | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	containerPkg "coopcloud.tech/abra/pkg/container" | 	containerPkg "coopcloud.tech/abra/pkg/container" | ||||||
| 	"coopcloud.tech/abra/pkg/recipe" | 	"coopcloud.tech/abra/pkg/recipe" | ||||||
|  | 	recipePkg "coopcloud.tech/abra/pkg/recipe" | ||||||
| 	"coopcloud.tech/abra/pkg/upstream/container" | 	"coopcloud.tech/abra/pkg/upstream/container" | ||||||
| 	"github.com/docker/cli/cli/command" | 	"github.com/docker/cli/cli/command" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| @ -35,6 +36,7 @@ var appRestoreCommand = cli.Command{ | |||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		internal.OfflineFlag, | 		internal.OfflineFlag, | ||||||
|  | 		internal.ChaosFlag, | ||||||
| 	}, | 	}, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| 	BashComplete: autocomplete.AppNameComplete, | 	BashComplete: autocomplete.AppNameComplete, | ||||||
| @ -63,6 +65,22 @@ Example: | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if !internal.Chaos { | ||||||
|  | 			if err := recipePkg.EnsureIsClean(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if !internal.Offline { | ||||||
|  | 				if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil { | ||||||
|  | 					logrus.Fatal(err) | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := recipePkg.EnsureLatest(app.Recipe); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		serviceName := c.Args().Get(1) | 		serviceName := c.Args().Get(1) | ||||||
| 		if serviceName == "" { | 		if serviceName == "" { | ||||||
| 			internal.ShowSubcommandHelpAndError(c, errors.New("missing <service>?")) | 			internal.ShowSubcommandHelpAndError(c, errors.New("missing <service>?")) | ||||||
|  | |||||||
| @ -12,7 +12,6 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/abra/pkg/formatter" | 	"coopcloud.tech/abra/pkg/formatter" | ||||||
| 	recipePkg "coopcloud.tech/abra/pkg/recipe" |  | ||||||
| 	"coopcloud.tech/abra/pkg/secret" | 	"coopcloud.tech/abra/pkg/secret" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| 	dockerClient "github.com/docker/docker/client" | 	dockerClient "github.com/docker/docker/client" | ||||||
| @ -43,19 +42,12 @@ var appSecretGenerateCommand = cli.Command{ | |||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		allSecretsFlag, | 		allSecretsFlag, | ||||||
| 		internal.PassFlag, | 		internal.PassFlag, | ||||||
| 		internal.OfflineFlag, |  | ||||||
| 	}, | 	}, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| 	BashComplete: autocomplete.AppNameComplete, | 	BashComplete: autocomplete.AppNameComplete, | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		app := internal.ValidateApp(c) | 		app := internal.ValidateApp(c) | ||||||
|  |  | ||||||
| 		if !internal.Offline { |  | ||||||
| 			if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil { |  | ||||||
| 				logrus.Fatal(err) |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if len(c.Args()) == 1 && !allSecrets { | 		if len(c.Args()) == 1 && !allSecrets { | ||||||
| 			err := errors.New("missing arguments <secret>/<version> or '--all'") | 			err := errors.New("missing arguments <secret>/<version> or '--all'") | ||||||
| 			internal.ShowSubcommandHelpAndError(c, err) | 			internal.ShowSubcommandHelpAndError(c, err) | ||||||
| @ -129,7 +121,6 @@ var appSecretInsertCommand = cli.Command{ | |||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		internal.PassFlag, | 		internal.PassFlag, | ||||||
| 		internal.OfflineFlag, |  | ||||||
| 	}, | 	}, | ||||||
| 	Before:       internal.SubCommandBefore, | 	Before:       internal.SubCommandBefore, | ||||||
| 	ArgsUsage:    "<domain> <secret-name> <version> <data>", | 	ArgsUsage:    "<domain> <secret-name> <version> <data>", | ||||||
|  | |||||||
| @ -71,10 +71,6 @@ version. | |||||||
| 			logrus.Fatalf("failed to determine version of deployed %s", app.Name) | 			logrus.Fatalf("failed to determine version of deployed %s", app.Name) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if err := recipe.EnsureExists(app.Recipe); err != nil { |  | ||||||
| 			logrus.Fatal(err) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		recipeMeta, err := recipe.GetRecipeMeta(app.Recipe, internal.Offline) | 		recipeMeta, err := recipe.GetRecipeMeta(app.Recipe, internal.Offline) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
|  | |||||||
| @ -10,10 +10,11 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| var recipeVersionCommand = cli.Command{ | var recipeVersionCommand = cli.Command{ | ||||||
| 	Name:      "versions", | 	Name:        "versions", | ||||||
| 	Aliases:   []string{"v"}, | 	Aliases:     []string{"v"}, | ||||||
| 	Usage:     "List recipe versions", | 	Usage:       "List recipe versions", | ||||||
| 	ArgsUsage: "<recipe>", | 	ArgsUsage:   "<recipe>", | ||||||
|  | 	Description: "Versions are read from the recipe catalogue.", | ||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		internal.OfflineFlag, | 		internal.OfflineFlag, | ||||||
|  | |||||||
| @ -30,6 +30,89 @@ setup() { | |||||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" |   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 git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   assert_success | ||||||
|  |   assert_output --partial 'foo' | ||||||
|  |  | ||||||
|  |   run $ABRA app backup "$TEST_APP_DOMAIN" app | ||||||
|  |   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" | ||||||
|  |  | ||||||
|  |   _checkout_recipe "$TEST_RECIPE" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # bats test_tags=slow | ||||||
|  | @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 deploy "$TEST_APP_DOMAIN" --chaos --no-input | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run $ABRA app backup "$TEST_APP_DOMAIN" app --chaos | ||||||
|  |   assert_success | ||||||
|  |   assert_output --partial 'running backup for the app service' | ||||||
|  |  | ||||||
|  |   _undeploy_app | ||||||
|  |  | ||||||
|  |   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||||
|  |   assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||||
|  |  | ||||||
|  |   _checkout_recipe "$TEST_RECIPE" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @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 backup "$TEST_APP_DOMAIN" --debug | ||||||
|  |   assert_failure | ||||||
|  |   assert_output --partial 'no containers matching' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @test "ensure recipe not up to date if --offline" { | ||||||
|  |   latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" | ||||||
|  |   refute [ -z "$latestCommit" ]; | ||||||
|  |  | ||||||
|  |   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 backup "$TEST_APP_DOMAIN" --debug --offline | ||||||
|  |   assert_failure | ||||||
|  |   assert_output --partial 'no containers matching' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   assert_output --partial 'behind 3' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
| @test "detect backup labels" { | @test "detect backup labels" { | ||||||
|   run $ABRA app backup "$TEST_APP_DOMAIN" --debug |   run $ABRA app backup "$TEST_APP_DOMAIN" --debug | ||||||
|   assert_failure |   assert_failure | ||||||
| @ -44,7 +127,7 @@ setup() { | |||||||
|   run sed -i '/backupbot.backup=true/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" |   run sed -i '/backupbot.backup=true/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app backup "$TEST_APP_DOMAIN" app |   run $ABRA app backup "$TEST_APP_DOMAIN" app --chaos | ||||||
|   assert_failure |   assert_failure | ||||||
|   assert_output --partial 'no backup config for app' |   assert_output --partial 'no backup config for app' | ||||||
|  |  | ||||||
| @ -55,7 +138,7 @@ setup() { | |||||||
|   run sed -i '/backupbot.backup.path=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" |   run sed -i '/backupbot.backup.path=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app backup "$TEST_APP_DOMAIN" app |   run $ABRA app backup "$TEST_APP_DOMAIN" app --chaos | ||||||
|   assert_failure |   assert_failure | ||||||
|   assert_output --partial 'backup paths are empty for app?' |   assert_output --partial 'backup paths are empty for app?' | ||||||
|  |  | ||||||
|  | |||||||
| @ -38,11 +38,73 @@ setup(){ | |||||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" |   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' | ||||||
|  |  | ||||||
|  |   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 | ||||||
|  |  | ||||||
|  |   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 check "$TEST_APP_DOMAIN" | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @test "ensure recipe not up to date if --offline" { | ||||||
|  |   latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" | ||||||
|  |   refute [ -z "$latestCommit" ]; | ||||||
|  |  | ||||||
|  |   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 check "$TEST_APP_DOMAIN" --offline | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   assert_output --partial 'behind 3' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
| @test "error if missing .env.sample" { | @test "error if missing .env.sample" { | ||||||
|   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample" |   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample" | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app check "$TEST_APP_DOMAIN" |   run $ABRA app check "$TEST_APP_DOMAIN" --chaos | ||||||
|   assert_failure |   assert_failure | ||||||
|   assert_output --partial '.env.sample does not exist?' |   assert_output --partial '.env.sample does not exist?' | ||||||
|  |  | ||||||
| @ -53,7 +115,7 @@ setup(){ | |||||||
|   run bash -c 'echo "NEW_VAR=foo" >> "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample"' |   run bash -c 'echo "NEW_VAR=foo" >> "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample"' | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app check "$TEST_APP_DOMAIN" |   run $ABRA app check "$TEST_APP_DOMAIN" --chaos | ||||||
|   assert_failure |   assert_failure | ||||||
|   assert_output --partial \ |   assert_output --partial \ | ||||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env is missing NEW_VAR" |     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env is missing NEW_VAR" | ||||||
|  | |||||||
| @ -39,6 +39,71 @@ setup(){ | |||||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" |   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' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @test "ensure recipe not up to date if --offline" { | ||||||
|  |   latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" | ||||||
|  |   refute [ -z "$latestCommit" ]; | ||||||
|  |  | ||||||
|  |   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' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
| @test "error if missing arguments without passing --local" { | @test "error if missing arguments without passing --local" { | ||||||
|   run $ABRA app cmd "$TEST_APP_DOMAIN" |   run $ABRA app cmd "$TEST_APP_DOMAIN" | ||||||
|   assert_failure |   assert_failure | ||||||
| @ -61,7 +126,7 @@ setup(){ | |||||||
|   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh" |   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh" | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local |   run $ABRA app cmd "$TEST_APP_DOMAIN" test_cmd --local --chaos | ||||||
|   assert_failure |   assert_failure | ||||||
|   assert_output --partial "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh does not exist" |   assert_output --partial "$ABRA_DIR/recipes/$TEST_RECIPE/abra.sh does not exist" | ||||||
|  |  | ||||||
|  | |||||||
| @ -27,6 +27,112 @@ setup(){ | |||||||
|   assert_output --partial 'cannot find app' |   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 restore "$TEST_APP_DOMAIN" app DOESNTEXIST | ||||||
|  |   assert_failure | ||||||
|  |   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 git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   assert_success | ||||||
|  |   assert_output --partial 'foo' | ||||||
|  |  | ||||||
|  |   run $ABRA app restore "$TEST_APP_DOMAIN" app DOESNTEXIST | ||||||
|  |   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" | ||||||
|  |  | ||||||
|  |   _checkout_recipe "$TEST_RECIPE" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # bats test_tags=slow | ||||||
|  | @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 touch "$BATS_TMPDIR/foo.txt" | ||||||
|  |   assert_success | ||||||
|  |   assert_exists "$BATS_TMPDIR/foo.txt" | ||||||
|  |  | ||||||
|  |   run tar -cvf "$BATS_TMPDIR/foo.tar.gz" "$BATS_TMPDIR/foo.txt" | ||||||
|  |   assert_success | ||||||
|  |   assert_exists "$BATS_TMPDIR/foo.tar.gz" | ||||||
|  |  | ||||||
|  |   run $ABRA app deploy "$TEST_APP_DOMAIN" --chaos --no-input | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run $ABRA app restore "$TEST_APP_DOMAIN" app "$BATS_TMPDIR/foo.tar.gz" \ | ||||||
|  |     --debug --chaos | ||||||
|  |   assert_success | ||||||
|  |   assert_output --partial 'restore config detected' | ||||||
|  |   assert_output --partial 'detected pre-hook command' | ||||||
|  |   assert_output --partial 'detected post-hook command' | ||||||
|  |  | ||||||
|  |   run $ABRA app run "$TEST_APP_DOMAIN" app ls "$BATS_TMPDIR" | ||||||
|  |   assert_success | ||||||
|  |   assert_output --partial 'foo.txt' | ||||||
|  |  | ||||||
|  |   _undeploy_app | ||||||
|  |  | ||||||
|  |   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||||
|  |   assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||||
|  |  | ||||||
|  |   _checkout_recipe "$TEST_RECIPE" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @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 restore "$TEST_APP_DOMAIN" app DOESNTEXIST | ||||||
|  |   assert_failure | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @test "ensure recipe not up to date if --offline" { | ||||||
|  |   latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" | ||||||
|  |   refute [ -z "$latestCommit" ]; | ||||||
|  |  | ||||||
|  |   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 restore "$TEST_APP_DOMAIN" app DOESNTEXIST --offline | ||||||
|  |   assert_failure | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   assert_output --partial 'behind 3' | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" | ||||||
|  |   assert_success | ||||||
|  |  | ||||||
|  |   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||||
|  |   refute_output --partial 'behind 3' | ||||||
|  | } | ||||||
|  |  | ||||||
| @test "error if missing service" { | @test "error if missing service" { | ||||||
|   run $ABRA app restore "$TEST_APP_DOMAIN" |   run $ABRA app restore "$TEST_APP_DOMAIN" | ||||||
|   assert_failure |   assert_failure | ||||||
| @ -43,16 +149,6 @@ setup(){ | |||||||
|   assert_output --partial "doesn't exist" |   assert_output --partial "doesn't exist" | ||||||
| } | } | ||||||
|  |  | ||||||
| @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 restore "$TEST_APP_DOMAIN" app DOESNTEXIST |  | ||||||
|   assert_failure |  | ||||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" |  | ||||||
| } |  | ||||||
|  |  | ||||||
| # bats test_tags=slow | # bats test_tags=slow | ||||||
| @test "detect labels if restore enabled" { | @test "detect labels if restore enabled" { | ||||||
|   run touch "$BATS_TMPDIR/foo.txt" |   run touch "$BATS_TMPDIR/foo.txt" | ||||||
| @ -90,7 +186,8 @@ setup(){ | |||||||
|   run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --chaos |   run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --chaos | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app restore "$TEST_APP_DOMAIN" app "$BATS_TMPDIR/foo.tar.gz" --debug |   run $ABRA app restore "$TEST_APP_DOMAIN" app "$BATS_TMPDIR/foo.tar.gz" \ | ||||||
|  |     --debug --chaos | ||||||
|   assert_success |   assert_success | ||||||
|   refute_output --partial 'restore config detected' |   refute_output --partial 'restore config detected' | ||||||
|   refute_output --partial 'detected pre-hook command' |   refute_output --partial 'detected pre-hook command' | ||||||
|  | |||||||
| @ -48,49 +48,6 @@ setup(){ | |||||||
|   assert_output --partial "doesn't exist in the env config" |   assert_output --partial "doesn't exist in the env config" | ||||||
| } | } | ||||||
|  |  | ||||||
| @test "generate: 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 secret generate "$TEST_APP_DOMAIN" --all |  | ||||||
|   assert_success |  | ||||||
|  |  | ||||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status |  | ||||||
|   refute_output --partial 'behind 3' |  | ||||||
|  |  | ||||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all |  | ||||||
|   assert_success |  | ||||||
| } |  | ||||||
|  |  | ||||||
| @test "generate: recipe not up to date if --offline" { |  | ||||||
|   latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" |  | ||||||
|   refute [ -z "$latestCommit" ]; |  | ||||||
|  |  | ||||||
|   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 secret generate "$TEST_APP_DOMAIN" --all --offline |  | ||||||
|   assert_success |  | ||||||
|  |  | ||||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status |  | ||||||
|   assert_output --partial 'behind 3' |  | ||||||
|  |  | ||||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all |  | ||||||
|   assert_success |  | ||||||
|  |  | ||||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" |  | ||||||
|   assert_success |  | ||||||
|  |  | ||||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status |  | ||||||
|   refute_output --partial 'behind 3' |  | ||||||
| } |  | ||||||
|  |  | ||||||
| @test "generate: create secrets" { | @test "generate: create secrets" { | ||||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" |   run $ABRA app secret ls "$TEST_APP_DOMAIN" | ||||||
|   assert_success |   assert_success | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user