forked from toolshed/abra
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			secret-ins
			...
			test-refac
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9ec99c7712 | 
| @ -6,7 +6,6 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"coopcloud.tech/abra/cli/internal" | ||||
| 	"coopcloud.tech/abra/pkg/autocomplete" | ||||
| @ -157,8 +156,6 @@ var appSecretInsertCommand = cli.Command{ | ||||
| 	Flags: []cli.Flag{ | ||||
| 		internal.DebugFlag, | ||||
| 		internal.PassFlag, | ||||
| 		internal.FileFlag, | ||||
| 		internal.TrimFlag, | ||||
| 	}, | ||||
| 	Before:       internal.SubCommandBefore, | ||||
| 	ArgsUsage:    "<domain> <secret-name> <version> <data>", | ||||
| @ -191,18 +188,6 @@ Example: | ||||
| 		version := c.Args().Get(2) | ||||
| 		data := c.Args().Get(3) | ||||
|  | ||||
| 		if internal.File { | ||||
| 			raw, err := os.ReadFile(data) | ||||
| 			if err != nil { | ||||
| 				logrus.Fatalf("reading secret from file: %s", err) | ||||
| 			} | ||||
| 			data = string(raw) | ||||
| 		} | ||||
|  | ||||
| 		if internal.Trim { | ||||
| 			data = strings.TrimSpace(data) | ||||
| 		} | ||||
|  | ||||
| 		secretName := fmt.Sprintf("%s_%s_%s", app.StackName(), name, version) | ||||
| 		if err := client.StoreSecret(cl, secretName, data, app.Server); err != nil { | ||||
| 			logrus.Fatal(err) | ||||
|  | ||||
| @ -38,20 +38,6 @@ var PassRemoveFlag = &cli.BoolFlag{ | ||||
| 	Destination: &PassRemove, | ||||
| } | ||||
|  | ||||
| var File bool | ||||
| var FileFlag = &cli.BoolFlag{ | ||||
| 	Name:        "file, f", | ||||
| 	Usage:       "Treat input as a file", | ||||
| 	Destination: &File, | ||||
| } | ||||
|  | ||||
| var Trim bool | ||||
| var TrimFlag = &cli.BoolFlag{ | ||||
| 	Name:        "trim, t", | ||||
| 	Usage:       "Trim input", | ||||
| 	Destination: &Trim, | ||||
| } | ||||
|  | ||||
| // Force force functionality without asking. | ||||
| var Force bool | ||||
|  | ||||
|  | ||||
| @ -50,9 +50,7 @@ teardown(){ | ||||
|   assert_success | ||||
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|  | ||||
|   _get_tag_hash 0.1.1+1.20.2 | ||||
|   _get_current_hash | ||||
|   assert_equal "$tagHash" "$currentHash" | ||||
|   assert_equal $(_get_tag_hash 0.1.1+1.20.2) $(_get_current_hash) | ||||
| } | ||||
|  | ||||
| @test "does not overwrite existing env files" { | ||||
| @ -113,13 +111,12 @@ teardown(){ | ||||
|  | ||||
| @test "ensure recipe up to date if no --offline" { | ||||
|   _reset_recipe | ||||
|   _get_n_hash 3 | ||||
|   wantHash=$(_get_n_hash 3) | ||||
|  | ||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 | ||||
|   assert_success | ||||
|  | ||||
|   _get_current_hash | ||||
|   assert_equal "$currentHash" "$nHash" | ||||
|   assert_equal $(_get_current_hash) "$wantHash" | ||||
|  | ||||
|   run $ABRA app new "$TEST_RECIPE" \ | ||||
|     --no-input \ | ||||
| @ -128,22 +125,19 @@ teardown(){ | ||||
|   assert_success | ||||
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|  | ||||
|   _get_head_hash | ||||
|   _get_current_hash | ||||
|   assert_equal "$HEAD_HASH" "$CURRENT_HASH" | ||||
|   assert_equal $(_get_head_hash) $(_get_current_hash) | ||||
|  | ||||
|   _reset_recipe | ||||
| } | ||||
|  | ||||
| @test "ensure recipe not up to date if --offline" { | ||||
|   _reset_recipe | ||||
|   _get_n_hash 3 | ||||
|   wantHash=$(_get_n_hash 3) | ||||
|  | ||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 | ||||
|   assert_success | ||||
|  | ||||
|   _get_current_hash | ||||
|   assert_equal "$currentHash" "$nHash" | ||||
|   assert_equal $(_get_current_hash) "$wantHash" | ||||
|  | ||||
|   # NOTE(d1): need to use --chaos to force same commit | ||||
|   run $ABRA app new "$TEST_RECIPE" \ | ||||
| @ -155,8 +149,7 @@ teardown(){ | ||||
|   assert_success | ||||
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|  | ||||
|   _get_current_hash | ||||
|   assert_equal "$currentHash" "$nHash" | ||||
|   assert_equal $(_get_current_hash) "$wantHash" | ||||
|  | ||||
|   _reset_recipe | ||||
| } | ||||
|  | ||||
| @ -19,13 +19,6 @@ teardown_file(){ | ||||
|   _reset_recipe | ||||
| } | ||||
|  | ||||
| teardown() { | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   _reset_app | ||||
|   _reset_recipe | ||||
|   _checkout_recipe | ||||
| } | ||||
|  | ||||
| setup(){ | ||||
|   load "$PWD/tests/integration/helpers/common" | ||||
|   _common_setup | ||||
| @ -84,6 +77,9 @@ setup(){ | ||||
|   assert_output --partial 'test_pass_one' | ||||
|   assert_output --partial 'test_pass_two' | ||||
|   refute_output --partial 'extra_pass' | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   assert_success | ||||
| } | ||||
|  | ||||
| @test "generate: broken if missing version" { | ||||
| @ -95,6 +91,7 @@ setup(){ | ||||
|   assert_failure | ||||
|   assert_output --partial 'missing version' | ||||
|  | ||||
|   _reset_app | ||||
| } | ||||
|  | ||||
| @test "generate: use version from app env" { | ||||
| @ -111,6 +108,11 @@ setup(){ | ||||
|   assert_success | ||||
|   assert_output --partial 'v2' | ||||
|   refute_output --partial 'v1' | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   assert_success | ||||
|  | ||||
|   _reset_app | ||||
| } | ||||
|  | ||||
| @test "generate: generate extra secret based on COMPOSE_FILE" { | ||||
| @ -129,6 +131,11 @@ setup(){ | ||||
|   run docker -c "$TEST_SERVER" secret ls | ||||
|   assert_success | ||||
|   assert_output --partial "$TEST_APP_DOMAIN_extra_pass_v1" | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   assert_success | ||||
|  | ||||
|   _reset_app | ||||
| } | ||||
|  | ||||
| @test "generate: bail if unstaged changes and no --chaos" { | ||||
| @ -155,6 +162,8 @@ setup(){ | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all --chaos | ||||
|   assert_success | ||||
|  | ||||
|   _checkout_recipe | ||||
| } | ||||
|  | ||||
| @test "generate: ensure secret name uses trimmed stack name" { | ||||
| @ -219,22 +228,9 @@ setup(){ | ||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" | ||||
|   assert_success | ||||
|   assert_output --partial 'true' | ||||
| } | ||||
|  | ||||
| @test "insert: create secret from file" { | ||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" test_pass_one | ||||
|   assert_success | ||||
|   assert_output --partial 'false' | ||||
|  | ||||
|   run bash -c "echo bar >> $ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
|  | ||||
|   run $ABRA app secret insert --file "$TEST_APP_DOMAIN" test_pass_one v1 "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
|   assert_success | ||||
|   assert_output --partial 'successfully stored on server' | ||||
|  | ||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" | ||||
|   assert_success | ||||
|   assert_output --partial 'true' | ||||
| } | ||||
|  | ||||
| @test "rm: validate arguments" { | ||||
| @ -318,6 +314,9 @@ setup(){ | ||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" | ||||
|   assert_success | ||||
|   assert_output --partial 'true' | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   assert_success | ||||
| } | ||||
|  | ||||
| @test "ls: show secrets as machine readable" { | ||||
| @ -331,6 +330,9 @@ setup(){ | ||||
|   run $ABRA app secret ls "$TEST_APP_DOMAIN" --machine | ||||
|   assert_success | ||||
|   assert_output --partial '"created-on-server":"true"' | ||||
|  | ||||
|   run $ABRA app secret rm "$TEST_APP_DOMAIN" --all | ||||
|   assert_success | ||||
| } | ||||
|  | ||||
| @test "ls: bail if unstaged changes and no --chaos" { | ||||
|  | ||||
| @ -48,19 +48,23 @@ _git_commit() { | ||||
| _get_tag_hash() { | ||||
|   tagHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-list -n 1 "$1") | ||||
|   assert_success | ||||
|   echo "$tagHash" | ||||
| } | ||||
|  | ||||
| _get_head_hash() { | ||||
|   headHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H" HEAD) | ||||
|   assert_success | ||||
|   echo "$headHash" | ||||
| } | ||||
|  | ||||
| _get_current_hash() { | ||||
|   currentHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H") | ||||
|   assert_success | ||||
|   echo "$currentHash" | ||||
| } | ||||
|  | ||||
| _get_n_hash() { | ||||
|   nHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H" "HEAD~$1") | ||||
|   assert_success | ||||
|   echo "$nHash" | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user