forked from actions/go-versions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGo.Tests.ps1
More file actions
74 lines (63 loc) · 2.64 KB
/
Go.Tests.ps1
File metadata and controls
74 lines (63 loc) · 2.64 KB
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
param (
[version] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Version
)
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
Import-Module (Join-Path $PSScriptRoot "../helpers/common-helpers.psm1")
function Get-UseGoLogs {
$logsFolderPath = Join-Path -Path $env:AGENT_HOMEDIRECTORY -ChildPath "_diag" | Join-Path -ChildPath "pages"
$useGoLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object {
$logContent = Get-Content $_.Fullname -Raw
return $logContent -match "GoTool"
} | Select-Object -First 1
return $useGoLogFile.Fullname
}
Describe "Go" {
It "is available" {
"go version" | Should -ReturnZeroExitCode
}
It "version is correct" {
$versionOutput = Invoke-Expression -Command "go version"
$finalVersion = $Version.ToString(3)
If ($Version.Build -eq "0"){
$finalVersion = $Version.ToString(2)
}
$versionOutput | Should -Match $finalVersion
}
It "is used from tool-cache" {
$goPath = (Get-Command "go").Path
$goPath | Should -Not -BeNullOrEmpty
$expectedPath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "go"
$goPath.startsWith($expectedPath) | Should -BeTrue -Because "'$goPath' is not started with '$expectedPath'"
}
It "cached version is used without downloading" {
# Analyze output of previous steps to check if Go was consumed from cache or downloaded
$useGoLogFile = Get-UseGoLogs
$useGoLogFile | Should -Exist
$useGoLogContent = Get-Content $useGoLogFile -Raw
$useGoLogContent | Should -Match "Found tool in cache"
}
Set-Location -Path "source"
$sourceLocation = Get-Location
It "Run simple code" {
$simpleLocation = Join-Path -Path $sourceLocation -ChildPath "simple"
Set-Location -Path $simpleLocation
"go run simple.go" | Should -ReturnZeroExitCode
"go build simple.go" | Should -ReturnZeroExitCode
"./simple" | Should -ReturnZeroExitCode
}
It "Run maps code" {
$mapsLocation = Join-Path -Path $sourceLocation -ChildPath "maps"
Set-Location -Path $mapsLocation
"go run maps.go" | Should -ReturnZeroExitCode
"go build maps.go" | Should -ReturnZeroExitCode
"./maps" | Should -ReturnZeroExitCode
}
It "Run methods code" {
$methodsLocation = Join-Path -Path $sourceLocation -ChildPath "methods"
Set-Location -Path $methodsLocation
"go run methods.go" | Should -ReturnZeroExitCode
"go build methods.go" | Should -ReturnZeroExitCode
"./methods" | Should -ReturnZeroExitCode
}
}