260 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			260 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| setup_file(){
 | |
|   load "$PWD/tests/integration/helpers/common"
 | |
|   _common_setup
 | |
|   _add_server
 | |
| }
 | |
| 
 | |
| teardown_file(){
 | |
|   _rm_server
 | |
|   _reset_recipe
 | |
| }
 | |
| 
 | |
| setup(){
 | |
|   load "$PWD/tests/integration/helpers/common"
 | |
|   _common_setup
 | |
|   _fetch_recipe
 | |
| }
 | |
| 
 | |
| teardown(){
 | |
|   _rm_app
 | |
|   _reset_recipe
 | |
|   _reset_tags
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
| }
 | |
| 
 | |
| @test "create new app" {
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   _get_head_hash
 | |
|   _get_current_hash
 | |
|   assert_equal "$headHash" "$currentHash"
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:$(_latest_release)" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| @test "create new app with version" {
 | |
|   run $ABRA app new "$TEST_RECIPE" 0.3.0+1.21.0 \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:0.3.0+1.21.0" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| @test "create new app with version commit" {
 | |
|   tagHash=$(_get_tag_hash "0.3.0+1.21.0")
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" "$tagHash" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:${tagHash}" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| @test "does not overwrite existing env files" {
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_failure
 | |
|   assert_output --partial 'already exists'
 | |
| }
 | |
| 
 | |
| @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 new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_failure
 | |
|   assert_output --partial 'locally unstaged changes'
 | |
| 
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_equal "$(_git_status)" "?? foo"
 | |
| 
 | |
|   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 git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
 | |
|   assert_success
 | |
|   assert_output --partial 'foo'
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --chaos \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_equal "$(_git_status)" "?? foo"
 | |
| 
 | |
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
 | |
|   assert_success
 | |
|   assert_output --partial 'foo'
 | |
| 
 | |
|   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" {
 | |
|   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 new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   assert_equal $(_get_head_hash) $(_get_current_hash)
 | |
| }
 | |
| 
 | |
| @test "ensure recipe not up to date if --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"
 | |
| 
 | |
|   # NOTE(d1): need to use --chaos to force same commit
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --offline \
 | |
|     --chaos \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   assert_equal $(_get_current_hash) "$wantHash"
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "generate secrets" {
 | |
|   latestRelease=$(_latest_release)
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN" \
 | |
|     --secrets
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   run $ABRA app secret ls "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_output --partial 'test_pass_one'
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "app new from chaos recipe" {
 | |
|   currentHash=$(_get_current_hash)
 | |
|   latestRelease=$(_latest_release)
 | |
| 
 | |
|   run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN" \
 | |
|     --secrets \
 | |
|     --chaos
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_output --partial "version: ${currentHash:0:8}+U"
 | |
| 
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_equal "$(_git_status)" "?? foo"
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:${currentHash:0:8}+U" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "app new, no releases, from chaos recipe" {
 | |
|   currentHash=$(_get_current_hash)
 | |
|   _remove_tags
 | |
| 
 | |
|   run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
| 
 | |
|   run $ABRA app new "$TEST_RECIPE" \
 | |
|     --no-input \
 | |
|     --server "$TEST_SERVER" \
 | |
|     --domain "$TEST_APP_DOMAIN" \
 | |
|     --secrets \
 | |
|     --chaos
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_output --partial "version: ${currentHash:0:8}+U"
 | |
| 
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_equal "$(_git_status)" "?? foo"
 | |
| 
 | |
|   run grep -q "TYPE=$TEST_RECIPE:${currentHash:0:8}+U" \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| @test "automatically select single server" {
 | |
|   # NOTE(d1): no --no-input required, single server available
 | |
|   run $ABRA app new "$TEST_RECIPE" --domain "$TEST_APP_DOMAIN"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| }
 |