forked from toolshed/abra
		
	fix: recipe workflow with integration tests
This commit is contained in:
		@ -61,14 +61,6 @@ your SSH keys configured on your account.
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		recipe := internal.ValidateRecipe(c)
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureUpToDate(recipe.Name); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureLatest(recipe.Name); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		imagesTmp, err := getImageVersions(recipe)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
 | 
			
		||||
@ -64,6 +64,9 @@ local file system.
 | 
			
		||||
		nextTag := c.Args().Get(1)
 | 
			
		||||
		if len(tags) == 0 && nextTag == "" {
 | 
			
		||||
			logrus.Warnf("no git tags found for %s", recipe.Name)
 | 
			
		||||
			if internal.NoInput {
 | 
			
		||||
				logrus.Fatalf("unable to continue, input required for initial version")
 | 
			
		||||
			}
 | 
			
		||||
			fmt.Println(fmt.Sprintf(`
 | 
			
		||||
The following options are two types of initial semantic version that you can
 | 
			
		||||
pick for %s that will be published in the recipe catalogue. This follows the
 | 
			
		||||
 | 
			
		||||
@ -66,13 +66,20 @@ You may invoke this command in "wizard" mode and be prompted for input:
 | 
			
		||||
		internal.MajorFlag,
 | 
			
		||||
		internal.MachineReadableFlag,
 | 
			
		||||
		internal.AllTagsFlag,
 | 
			
		||||
		internal.OfflineFlag,
 | 
			
		||||
	},
 | 
			
		||||
	Before:       internal.SubCommandBefore,
 | 
			
		||||
	BashComplete: autocomplete.RecipeNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		recipe := internal.ValidateRecipe(c)
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureIsClean(recipe.Name); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureExists(recipe.Name); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureUpToDate(recipe.Name); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -1,25 +1,107 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
setup_file(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
  _add_server
 | 
			
		||||
  _new_app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
teardown_file(){
 | 
			
		||||
  _rm_server
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
setup(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# bats test_tags=slow
 | 
			
		||||
@test "pull in latest changes" {
 | 
			
		||||
  run $ABRA recipe fetch matrix-synapse
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/matrix-synapse" reset --hard HEAD~3
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/matrix-synapse" status
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'behind 3'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe release matrix-synapse --no-input
 | 
			
		||||
@test "validate recipe argument" {
 | 
			
		||||
  run $ABRA recipe release --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'no recipe name provided'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/matrix-synapse" status
 | 
			
		||||
  refute_output --partial 'behind 3'
 | 
			
		||||
  run $ABRA recipe release DOESNTEXIST --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'unable to validate recipe'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "release patch bump" {
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag --list
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output '0.1.0+1.20.0'
 | 
			
		||||
 | 
			
		||||
  run bash -c 'cat "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | grep -q "0.1.0+1.20.0"'
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'image: nginx:1.20.2'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'synced label'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'coop-cloud.${STACK_NAME}.version=0.1.1+1.20.2'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe release "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'no -p/--publish passed, not publishing'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag --list
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial '0.1.0+1.20.0'
 | 
			
		||||
  assert_output --partial '0.1.1+1.20.2'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~1
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d '0.1.1+1.20.2'
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial "Deleted tag '0.1.1+1.20.2'"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "release minor bump" {
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag --list
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output '0.1.0+1.20.0'
 | 
			
		||||
 | 
			
		||||
  run bash -c 'grep -q "0.1.0+1.20.0" "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"'
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --regexp 'image: nginx:1.2.*'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'synced label'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --regexp 'coop-cloud\.\$\{STACK_NAME\}\.version=0\.2\.0\+1\.2.*'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe release "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'no -p/--publish passed, not publishing'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag --list
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial '0.1.0+1.20.0'
 | 
			
		||||
  assert_output --regexp '0\.2\.0\+1\.2.*'
 | 
			
		||||
 | 
			
		||||
  # NOTE(d1): nuke it since we can't clean up the tag
 | 
			
		||||
  run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,39 +1,113 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
setup_file(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
  _add_server
 | 
			
		||||
  _new_app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
teardown_file(){
 | 
			
		||||
  _rm_server
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
setup(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "validate recipe argument" {
 | 
			
		||||
  run $ABRA recipe sync --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'no recipe name provided'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync DOESNTEXIST --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'unable to validate recipe'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "allow unstaged changes" {
 | 
			
		||||
  run $ABRA recipe fetch matrix-synapse
 | 
			
		||||
  run echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run echo "unstaged changes" >> "$ABRA_DIR/recipes/matrix-synapse/foo"
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/matrix-synapse" status
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'foo'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync matrix-synapse --patch
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run rm -rf "$ABRA_DIR/recipes/matrix-synapse/foo"
 | 
			
		||||
  run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_not_exists "$ABRA_DIR/recipes/matrix-synapse/foo"
 | 
			
		||||
  assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "detect unstaged label changes" {
 | 
			
		||||
  run $ABRA recipe fetch matrix-synapse
 | 
			
		||||
  run $ABRA recipe fetch "$TEST_RECIPE"
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync matrix-synapse --patch
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync matrix-synapse --patch
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'is already set, nothing to do?'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# TODO(d1): implement
 | 
			
		||||
@test "sync patch label bump" {
 | 
			
		||||
  run bash -c 'cat "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | grep -q "0.1.0+1.20.0"'
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'image: nginx:1.20.2'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'coop-cloud.${STACK_NAME}.version=0.1.1+1.20.2'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "sync minor label bump" {
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --regexp 'image: nginx:1.2.*'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --regexp 'coop-cloud\.\$\{STACK_NAME\}\.version=0\.2\.0\+1\.2.*'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "error if --no-input and no initial version" {
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d '0.1.0+1.20.0'
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial "Deleted tag '0.1.0+1.20.0'"
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe sync "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'unable to continue'
 | 
			
		||||
  assert_output --partial 'initial version'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" fetch -a
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial '[new tag]'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,105 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
setup_file(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
  _add_server
 | 
			
		||||
  _new_app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
teardown_file(){
 | 
			
		||||
  _rm_server
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
setup(){
 | 
			
		||||
  load "$PWD/tests/integration/helpers/common"
 | 
			
		||||
  _common_setup
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# TODO(d1): implement
 | 
			
		||||
@test "validate recipe argument" {
 | 
			
		||||
  run $ABRA recipe upgrade --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'no recipe name provided'
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade DOESNTEXIST --no-input
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'unable to validate recipe'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@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 recipe upgrade "$TEST_RECIPE" --no-input
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'can upgrade service: app'
 | 
			
		||||
 | 
			
		||||
  assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "error if unstaged changes" {
 | 
			
		||||
  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 recipe upgrade "$TEST_RECIPE" --no-input
 | 
			
		||||
  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 "ensure up to date" {
 | 
			
		||||
  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 recipe upgrade "$TEST_RECIPE" --no-input
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'can upgrade service: app'
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
 | 
			
		||||
  refute_output --partial 'behind 3'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "only one of -x/y/z flags" {
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input -x -y
 | 
			
		||||
  assert_failure
 | 
			
		||||
  assert_output --partial 'you can only use one of'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "upgrade patch" {
 | 
			
		||||
  run bash -c 'cat "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | grep -q "0.1.0+1.20.0"'
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --patch
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --partial 'image: nginx:1.20.2'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@test "upgrade minor" {
 | 
			
		||||
  run bash -c 'cat "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" | grep -q "0.1.0+1.20.0"'
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run $ABRA recipe upgrade "$TEST_RECIPE" --no-input --minor
 | 
			
		||||
  assert_success
 | 
			
		||||
 | 
			
		||||
  run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" diff
 | 
			
		||||
  assert_success
 | 
			
		||||
  assert_output --regexp 'image: nginx:1.2.*'
 | 
			
		||||
 | 
			
		||||
  _checkout_recipe "$TEST_RECIPE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user