#!/usr/bin/env bash

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

teardown_file(){
  _rm_server
}

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

teardown(){
  _add_server
}

@test "validate server" {
  run $ABRA server remove --no-input
  assert_failure

  run $ABRA server remove foo
  assert_failure
}

@test "remove server" {
  if [ "$TEST_SERVER" = "default" ]; then
    skip "cannot delete 'default' server (local)"
  fi

  assert_exists "$ABRA_DIR/servers/$TEST_SERVER"
  assert bash -c "docker context ls | grep -q $TEST_SERVER"

  run $ABRA server remove --no-input "$TEST_SERVER"
  assert_success
  assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER"
  refute bash -c "docker context ls | grep -q $TEST_SERVER"
}
