trap {
  write-error $_
  exit 1
}

$env:GOPATH = Join-Path -Path $PWD "gopath"
$env:PATH = $env:GOPATH + "/bin;C:/go/bin;" + $env:PATH

cd $env:GOPATH/src/github.com/cloudfoundry/bosh-agent

if ((Get-Command "go.exe" -ErrorAction SilentlyContinue) -eq $null)
{
  Write-Host "Installing Go 1.6.3!"
  Invoke-WebRequest https://storage.googleapis.com/golang/go1.6.3.windows-amd64.msi -OutFile go.msi

  $p = Start-Process -FilePath "msiexec" -ArgumentList "/passive /norestart /i go.msi" -Wait -PassThru

  if($p.ExitCode -ne 0)
  {
    throw "Golang MSI installation process returned error code: $($p.ExitCode)"
  }
  Write-Host "Go is installed!"
}

# Change constant for unit test process labels to prevent collisions with
# bosh deployed Job Supervisor
$file = Join-Path -Path $PWD jobsupervisor/windows_job_supervisor.go
(Get-Content $file).replace('serviceDescription = "vcap"', 'serviceDescription = "vcap_test"') | Set-Content $file

go.exe install github.com/cloudfoundry/bosh-agent/vendor/github.com/onsi/ginkgo/ginkgo
ginkgo.exe -r -keepGoing -skipPackage="integration,vendor"

trap {
  write-error $_
  exit 1
}

$env:GOPATH = Join-Path -Path $PWD "gopath"
$env:PATH = $env:GOPATH + "/bin;C:/go/bin;" + $env:PATH

cd $env:GOPATH/src/github.com/cloudfoundry/bosh-agent

if ((Get-Command "go.exe" -ErrorAction SilentlyContinue) -eq $null)
{
  Write-Host "Installing Go 1.6.3!"
  Invoke-WebRequest https://storage.googleapis.com/golang/go1.6.3.windows-amd64.msi -OutFile go.msi

  $p = Start-Process -FilePath "msiexec" -ArgumentList "/passive /norestart /i go.msi" -Wait -PassThru

  if($p.ExitCode -ne 0)
  {
    throw "Golang MSI installation process returned error code: $($p.ExitCode)"
  }
  Write-Host "Go is installed!"
}

# Change constant for unit test process labels to prevent collisions with
# bosh deployed Job Supervisor
$file = Join-Path -Path $PWD jobsupervisor/windows_job_supervisor.go
(Get-Content $file).replace('serviceDescription = "vcap"', 'serviceDescription = "vcap_test"') | Set-Content $file

go.exe install github.com/cloudfoundry/bosh-agent/vendor/github.com/onsi/ginkgo/ginkgo
ginkgo.exe -r -keepGoing -skipPackage="integration,vendor"
if ($LastExitCode -ne 0)
{
    Write-Error $_
    exit 1
}

Handle errors for windows unit test
Handle errors for windows unit test

Signed-off-by: Sunjay Bhatia <df2d57be7987a471915f625a5499155bc16d4200@pivotal.io>
