forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_e2e.ps1
executable file
·76 lines (63 loc) · 2.48 KB
/
test_e2e.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Execute end-to-end (e2e) tests to verify that everything is working right
# from the end user perspective
$repoDir = Join-Path $PSScriptRoot ".." | Join-Path -ChildPath ".."
if (-not (Test-Path env:GO_BINARY_PATH)) { $env:GO_BINARY_PATH = "go" }
$globalTmpDir = [System.IO.Path]::GetTempPath()
$tmpDirName = [GUID]::NewGuid()
$testGoPath = Join-Path $globalTmpDir $tmpDirName
$origGOPATH = if (Test-Path env:GOPATH) {$env:GOPATH} else {$null}
$origGOPROXY = if (Test-Path env:GOPROXY) {$env:GOPROXY} else {$null}
$origGO111MODULE = if (Test-Path env:GO111MODULE) {$env:GO111MODULE} else {$null}
New-Item $testGoPath -ItemType Directory | Out-Null
$goModCache = Join-Path $testGoPath "pkg" | Join-Path -ChildPath "mod"
$env:Path += ";" + "${$(Join-Path $repoDir "bin")}"
function clearGoModCache () {
Get-ChildItem -Path $goModCache -Recurse | Remove-Item -Recurse -Force -Confirm:$false
}
function stopProcesses () {
Get-Process -Name proxy* -ErrorAction SilentlyContinue | Stop-Process -Force
}
function teardown () {
# Cleanup ENV after our tests
if ($origGOPATH) {$env:GOPATH = $origGOPATH} else {Remove-Item env:GOPATH}
if ($origGOPROXY) {$env:GOPROXY = $origGOPROXY} else {Remove-Item env:GOPROXY}
if ($origGO111MODULE) {$env:GO111MODULE = $origGO111MODULE} else {Remove-Item env:GO111MODULE}
stopProcesses
# clear test gopath
Get-ChildItem -Path $testGoPath -Recurse | Remove-Item -Recurse -Force -Confirm:$false
Pop-Location
Pop-Location
}
try {
$env:GO111MODULE = "on"
## Start the proxy in the background and wait for it to be ready
Push-Location $(Join-Path $repoDir cmd | Join-Path -ChildPath proxy)
## just in case something is still running
stopProcesses
& go build -mod=vendor
Start-Process -NoNewWindow .\proxy.exe
$proxyUp = $false
do {
try {
$proxyUp = (Invoke-WebRequest -Method GET -Uri http://localhost:3000/readyz).StatusCode -eq "200"
}
catch {
Start-Sleep -Seconds 1
}
} while(-not $proxyUp)
## Clone our test repo
$testSource = Join-Path $testGoPath "happy-path"
git clone https://github.com/athens-artifacts/happy-path.git ${testSource}
Push-Location ${testSource}
$env:GOPATH = $testGoPath
## Make sure that our test repo works without the GOPROXY first
if (Test-Path env:GOPROXY) { Remove-Item env:GOPROXY }
& $env:GO_BINARY_PATH run .
clearGoModCache
## Verify that the test works against the proxy
$env:GOPROXY = "http://localhost:3000"
& $env:GO_BINARY_PATH run .
}
finally {
teardown
}