#!/usr/bin/env bash

setup_file(){
  load "$PWD/tests/integration/helpers/common"
  _common_setup
  _add_server
  _new_app
}

teardown_file(){
  _rm_app
  _rm_server
  _reset_recipe
}

setup(){
  load "$PWD/tests/integration/helpers/common"
  _common_setup
  _ensure_catalogue
}

teardown(){
  _reset_app
}

@test "badly formatted env version bails out" {
  run sed -i 's/TYPE=abra-test-recipe/TYPE=abra-test-recipe:0.2.0+1.21.0/g' \
    "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
  assert_success

  run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
  assert_failure
  assert_output --partial 'seems invalid'
}

@test "invalid env version bails out" {
  run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe:DOESNTEXIST/g' \
    "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
  assert_success

  run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
  assert_failure
  assert_output --partial 'not found'
}
