#!/bin/bash
set -eu

function cleanup {
  rm $FOG_RC
}

# Override default of ~/.fog and delete afterwards.
export FOG_RC=$(mktemp /tmp/vcloud_fog_rc.XXXXXXXXXX)
trap cleanup EXIT

cat <<EOF >${FOG_RC}
${FOG_CREDENTIAL}:
  vcloud_director_host: '${API_HOST}'
  vcloud_director_username: '${API_USERNAME}'
  vcloud_director_password: ''
EOF

git clean -ffdx

# We wish to force using a version of ruby installed with rbenv, because the version of ruby shipped with
# Ubuntu 12.04 has a bug we hit in Psych when loading YAML files.
export RBENV_VERSION="1.9.3"

bundle install --path "${HOME}/bundles/${JOB_NAME}" --shebang="/usr/bin/env ruby"

# Obtain the integration test parameters
git clone git@github.gds:gds/vcloud-tools-testing-config.git
mv vcloud-tools-testing-config/vcloud_tools_testing_config.yaml spec/integration/
rm -rf vcloud-tools-testing-config

# Never log token to STDOUT.
set +x
eval $(printenv API_PASSWORD | bundle exec vcloud-login)

bundle exec rake
bundle exec rake integration

#!/bin/bash
set -eu

function cleanup {
  rm $FOG_RC
}

# Override default of ~/.fog and delete afterwards.
export FOG_RC=$(mktemp /tmp/vcloud_fog_rc.XXXXXXXXXX)
trap cleanup EXIT

cat <<EOF >${FOG_RC}
${FOG_CREDENTIAL}:
  vcloud_director_host: '${API_HOST}'
  vcloud_director_username: '${API_USERNAME}'
  vcloud_director_password: ''
EOF

git clean -ffdx

# We wish to force using a version of ruby installed with rbenv, because the version of ruby shipped with
# Ubuntu 12.04 has a bug we hit in Psych when loading YAML files.
export RBENV_VERSION="1.9.3"

bundle install --path "${HOME}/bundles/${JOB_NAME}" --shebang="/usr/bin/env ruby"

# Obtain the integration test parameters
git clone git@github.gds:gds/vcloud-tools-testing-config.git
mv vcloud-tools-testing-config/vcloud_tools_testing_config.yaml spec/integration/
rm -rf vcloud-tools-testing-config

# Never log token to STDOUT.
set +x
eval $(printenv API_PASSWORD | bundle exec vcloud-login)
trap "bundle exec vcloud-logout" EXIT

bundle exec rake
bundle exec rake integration

Call vcloud-logout after integration tests
Call vcloud-logout after integration tests

To guard us against the possibility that our vCloud session tokens might be
exposed and copy/pasted from CI build output. I'm using a `trap` to ensure
that this gets called regardless of whether the spec or integrations tests
fail.
