#!/usr/bin/env bash

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

# bats test_tags=slow
@test "generate catalogue" {
  run $ABRA catalogue generate
  assert_success

  for d in $(ls $ABRA_DIR/recipes); do 
    assert_exists "$ABRA_DIR/recipes/$d/.git"
  done
}

@test "error if unstaged changes" {
  run bash -c "echo foo >> $ABRA_DIR/catalogue/foo"
  assert_success
  assert_exists "$ABRA_DIR/catalogue/foo"

  run $ABRA catalogue generate
  assert_failure
  assert_output --partial 'locally unstaged changes'

  run rm -rf "$ABRA_DIR/catalogue/foo"
  assert_not_exists "$ABRA_DIR/catalogue/foo"
}

# bats test_tags=slow
@test "no error if unstaged and --chaos" {
  run bash -c "echo foo >> $ABRA_DIR/catalogue/foo"
  assert_success
  assert_exists "$ABRA_DIR/catalogue/foo"

  run $ABRA catalogue generate gitea --chaos
  assert_success

  run rm -rf "$ABRA_DIR/catalogue/foo"
  assert_not_exists "$ABRA_DIR/catalogue/foo"
}

# bats test_tags=slow
@test "generate only specific recipe" {
  run $ABRA catalogue generate gitea
  assert_success
  assert_exists "$ABRA_DIR/recipes/gitea/.git"
}
