forked from toolshed/abra
		
	
		
			
				
	
	
		
			196 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			196 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| setup_file(){
 | |
|   load "$PWD/tests/integration/helpers/common"
 | |
|   _common_setup
 | |
|   _add_server
 | |
|   _new_app
 | |
| }
 | |
| 
 | |
| teardown_file(){
 | |
|   if [[ ! -f "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" ]]; then
 | |
|     _new_app
 | |
|   fi
 | |
| 
 | |
|   _undeploy_app
 | |
|   _rm_app
 | |
|   _rm_server
 | |
| 
 | |
|   if [[ -d "$ABRA_DIR/servers/foo" ]]; then
 | |
|     run rm -rf "$ABRA_DIR/servers/foo"
 | |
|     assert_success
 | |
|     assert_not_exists "$ABRA_DIR/servers/foo"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| setup(){
 | |
|   load "$PWD/tests/integration/helpers/common"
 | |
|   _common_setup
 | |
| }
 | |
| 
 | |
| teardown(){
 | |
|   if [[ ! -f "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" ]]; then
 | |
|     _new_app
 | |
|   fi
 | |
| 
 | |
|   _undeploy_app
 | |
|   _wipe_env_version
 | |
|   _reset_recipe
 | |
| 
 | |
|   if [[ -d "$ABRA_DIR/servers/foo" ]]; then
 | |
|     run rm -rf "$ABRA_DIR/servers/foo"
 | |
|     assert_success
 | |
|     assert_not_exists "$ABRA_DIR/servers/foo"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| @test "list without status" {
 | |
|   run $ABRA app ls
 | |
|   assert_success
 | |
|   assert_output --partial "$TEST_SERVER"
 | |
|   assert_output --partial "$TEST_APP_DOMAIN"
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "list with status" {
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
|   assert_output --partial "$TEST_SERVER"
 | |
|   assert_output --partial "$TEST_APP_DOMAIN"
 | |
|   assert_output --partial "unknown"
 | |
| 
 | |
|   _deploy_app
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
|   assert_output --partial "$TEST_SERVER"
 | |
|   assert_output --partial "$TEST_APP_DOMAIN"
 | |
|   assert_output --partial "deployed"
 | |
| }
 | |
| 
 | |
| @test "filter by server" {
 | |
|   run mkdir -p "$ABRA_DIR/servers/foo.com"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/foo.com"
 | |
| 
 | |
|   run cp \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" \
 | |
|     "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
|   assert_exists "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
| 
 | |
|   run $ABRA app ls
 | |
|   assert_success
 | |
|   assert_output --partial "$TEST_SERVER"
 | |
|   assert_output --partial "foo.com"
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/servers/foo.com"
 | |
|   assert_success
 | |
|   assert_not_exists "$ABRA_DIR/servers/foo.com"
 | |
| }
 | |
| 
 | |
| @test "filter by recipe" {
 | |
|   run mkdir -p "$ABRA_DIR/servers/foo.com"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/servers/foo.com"
 | |
| 
 | |
|   run cp \
 | |
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" \
 | |
|     "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
|   assert_exists "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
| 
 | |
|   run sed -i "s/TYPE=$TEST_RECIPE/TYPE=foo-recipe/g" "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
|   assert grep -q "TYPE=foo-recipe" "$ABRA_DIR/servers/foo.com/app.foo.com.env"
 | |
| 
 | |
|   run $ABRA app ls
 | |
|   assert_success
 | |
|   assert_output --partial "$TEST_RECIPE"
 | |
|   assert_output --partial "foo-recipe"
 | |
| 
 | |
|   run $ABRA app ls --recipe foo-recipe
 | |
|   assert_success
 | |
|   refute_output --partial "$TEST_RECIPE"
 | |
|   assert_output --partial "foo-recipe"
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/servers/foo.com"
 | |
|   assert_success
 | |
|   assert_not_exists "$ABRA_DIR/servers/foo.com"
 | |
| }
 | |
| 
 | |
| @test "output is machine readable" {
 | |
|   run $ABRA app ls --machine
 | |
| 
 | |
|   expectedOutput='{"'
 | |
|   expectedOutput+="$TEST_SERVER"
 | |
|   expectedOutput+='":{"apps":'
 | |
| 
 | |
|   assert_output --partial "$expectedOutput"
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "list with status fetches recipe" {
 | |
|   _deploy_app
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
 | |
|   assert_success
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "list with chaos version" {
 | |
|   run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
|   assert_success
 | |
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
 | |
| 
 | |
|   run $ABRA app deploy "$TEST_APP_DOMAIN" \
 | |
|     --no-input --no-converge-checks --chaos
 | |
|   assert_success
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
|   assert_output --partial "+U"
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/servers/foo.com"
 | |
|   assert_success
 | |
|   assert_not_exists "$ABRA_DIR/servers/foo.com"
 | |
| }
 | |
| 
 | |
| @test "list with status skips unknown servers" {
 | |
|   if [[ ! -d "$ABRA_DIR/servers/foo" ]]; then
 | |
|     run mkdir -p "$ABRA_DIR/servers/foo"
 | |
|     assert_success
 | |
|     assert_exists "$ABRA_DIR/servers/foo"
 | |
| 
 | |
|     run cp "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" \
 | |
|            "$ABRA_DIR/servers/foo/$TEST_APP_DOMAIN.env"
 | |
|     assert_success
 | |
|     assert_exists "$ABRA_DIR/servers/foo/$TEST_APP_DOMAIN.env"
 | |
|   fi
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
|   assert_output --partial "unknown server"
 | |
| }
 | |
| 
 | |
| # bats test_tags=slow
 | |
| @test "list does not fail if missing .env" {
 | |
|   _deploy_app
 | |
| 
 | |
|   run $ABRA app ls --status
 | |
|   assert_success
 | |
| 
 | |
|   run rm -rf "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
|   assert_success
 | |
|   assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
 | |
| 
 | |
|   output=$("$ABRA" app ls --server "$TEST_SERVER" --status --machine)
 | |
|   run diff \
 | |
|     <(jq -S "." <(echo "$output")) \
 | |
|     <(jq -S "." <(echo '{}'))
 | |
|   assert_success
 | |
| }
 |