# Defines helper functions used across a variety of tests.

create_repo() {
  local dir_name="${1:-}"
  if [ -z "${dir_name}" ]; then
    repo_path="$(mktemp --directory)"
  else
    repo_path="$(mktemp --directory)/${dir_name}"
  fi

  mkdir -p "${repo_path}"
  git init "${repo_path}" >/dev/null 2>&1

  echo ${repo_path}
}

destroy-all-containers() {
  docker ps -aq | xargs --no-run-if-empty docker rm --force
}

container-running() {
  [ "$(docker inspect --format={{.State.Status}} "$1")" = running ]
}

# Defines helper functions used across a variety of tests.

create_repo() {
  local dir_name="${1:-}"
  if [ -z "${dir_name}" ]; then
    repo_path="$(mktemp --directory)"
  else
    repo_path="$(mktemp --directory)/${dir_name}"
  fi

  mkdir -p "${repo_path}"
  git init "${repo_path}" >/dev/null 2>&1

  echo ${repo_path}
}

destroy-all-containers() {
  docker ps -aq | xargs --no-run-if-empty docker rm --force
}

container-running() {
  [ "$(docker inspect --format={{.State.Status}} "$1")" = running ]
}

file() {
  local file=$1

  # `file` will be passed file contents via STDIN
  while read data; do
    echo "$data" >> "$file"
  done
}

Add file helper for creating multiline files from Heredocs
Add file helper for creating multiline files from Heredocs

We want to create Dock configuration files in our test suite easily.
This helper allows us to do that in a slightly more readable way.

    file path/to/file <<-EOF
    Multiple
    lines
    go
    here
    EOF
