#!/bin/bash

(
  set -e

  base=$( cd "$( dirname "$( dirname "$0" )")" && pwd )
  base_gopath=$( cd $base/../../.. && pwd )

  export GOPATH=$base_gopath:$GOPATH

  function printStatus {
      if [ $? -eq 0 ]; then
          echo -e "\nSWEET SUITE SUCCESS"
      else
          echo -e "\nSUITE FAILURE"
      fi
  }

  trap printStatus EXIT

  echo -e "\n Cleaning build artifacts..."
  go clean

  echo -e "\n Formatting packages..."
  go fmt $(go list ./... | grep -v /vendor/)

  echo -e "\n cd to base of project..."
  cd $base

  echo -e "\n Creating cpi binary..."
  go build -o out/cpi bosh-softlayer-cpi/main

if [ -z "$1" ]; then
  echo -e "\n Integration Testing ALL CPI methods"
  ginkgo -r -p -v --noisyPendings integration
else
  echo -e "\n Integration Testing for $1 methods"
  ginkgo -r -p -v --noisyPendings -focus $1 integration
fi

  echo -e "\n Vetting packages for potential issues..."
  go vet ./...
)
