2020-06-09 19:52:06 +00:00
|
|
|
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
|
|
|
|
Import-Module (Join-Path $PSScriptRoot "../helpers/common-helpers.psm1")
|
|
|
|
|
2020-08-26 10:18:15 +00:00
|
|
|
BeforeAll {
|
|
|
|
Set-Location -Path "source"
|
|
|
|
$sourceLocation = Get-Location
|
2020-08-26 12:58:05 +00:00
|
|
|
|
2020-08-26 10:18:15 +00:00
|
|
|
function Get-UseGoLogs {
|
|
|
|
# GitHub Windows images don't have `HOME` variable
|
|
|
|
$homeDir = $env:HOME ?? $env:HOMEDRIVE
|
|
|
|
$logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/*/_diag/pages" -Resolve
|
2020-06-09 19:52:06 +00:00
|
|
|
|
2020-08-26 10:18:15 +00:00
|
|
|
$useGoLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object {
|
|
|
|
$logContent = Get-Content $_.Fullname -Raw
|
|
|
|
return $logContent -match "setup-go@v"
|
|
|
|
} | Select-Object -First 1
|
|
|
|
return $useGoLogFile.Fullname
|
|
|
|
}
|
2020-06-09 19:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Describe "Go" {
|
|
|
|
It "is available" {
|
|
|
|
"go version" | Should -ReturnZeroExitCode
|
|
|
|
}
|
|
|
|
|
2024-06-28 10:36:21 +00:00
|
|
|
It "version is correct" {
|
2024-06-28 11:14:00 +00:00
|
|
|
[version]$Version = $env:VERSION
|
|
|
|
$versionOutput = Invoke-Expression -Command "go version"
|
|
|
|
|
|
|
|
# Extract only the version number from the go version command output.
|
|
|
|
$installedVersion = ($versionOutput -split " ")[2] -replace "go", "" -replace "v", ""
|
|
|
|
|
|
|
|
$finalVersion = $Version.ToString(3)
|
|
|
|
If ($Version.Build -eq "0"){
|
|
|
|
$finalVersion = $Version.ToString(2)
|
2020-06-09 19:52:06 +00:00
|
|
|
}
|
2024-06-28 11:14:00 +00:00
|
|
|
$installedVersion | Should -Match $finalVersion
|
|
|
|
}
|
2024-06-28 10:53:31 +00:00
|
|
|
|
2020-06-09 19:52:06 +00:00
|
|
|
|
|
|
|
It "is used from tool-cache" {
|
|
|
|
$goPath = (Get-Command "go").Path
|
|
|
|
$goPath | Should -Not -BeNullOrEmpty
|
2020-08-26 10:18:15 +00:00
|
|
|
|
|
|
|
# GitHub Windows images don't have `AGENT_TOOLSDIRECTORY` variable
|
|
|
|
$toolcacheDir = $env:AGENT_TOOLSDIRECTORY ?? $env:RUNNER_TOOL_CACHE
|
|
|
|
$expectedPath = Join-Path -Path $toolcacheDir -ChildPath "go"
|
2020-06-09 19:52:06 +00:00
|
|
|
$goPath.startsWith($expectedPath) | Should -BeTrue -Because "'$goPath' is not started with '$expectedPath'"
|
|
|
|
}
|
|
|
|
|
2024-06-28 10:20:05 +00:00
|
|
|
if ($env:RUNNER_TYPE -eq "GitHub") {
|
|
|
|
# Analyze output of previous steps to check if Node.js was consumed from cache or downloaded
|
|
|
|
$useNodeLogFile = Get-UseNodeLogs
|
|
|
|
$useNodeLogFile | Should -Exist
|
|
|
|
$useNodeLogContent = Get-Content $useNodeLogFile -Raw
|
|
|
|
$useNodeLogContent | Should -Match "Found in cache"
|
|
|
|
} else {
|
|
|
|
# Get the installed version of Node.js
|
|
|
|
$nodeVersion = Invoke-Expression "node --version"
|
|
|
|
# Check if Node.js is installed
|
|
|
|
$nodeVersion | Should -Not -BeNullOrEmpty
|
|
|
|
# Check if the installed version of Node.js is the expected version
|
|
|
|
$nodeVersion | Should -Match $env:VERSION
|
|
|
|
}
|
2020-06-09 19:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2020-09-09 17:35:55 +00:00
|
|
|
$compiledPackageName = "simple"
|
2020-09-09 22:57:10 +00:00
|
|
|
if ($IsWindows) { $compiledPackageName += ".exe" }
|
2020-09-09 17:35:55 +00:00
|
|
|
(Resolve-Path "./$compiledPackageName").Path | Should -ReturnZeroExitCode
|
2020-06-09 19:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-09-09 17:35:55 +00:00
|
|
|
$compiledPackageName = "maps"
|
2020-09-09 22:57:10 +00:00
|
|
|
if ($IsWindows) { $compiledPackageName += ".exe" }
|
2020-09-09 17:35:55 +00:00
|
|
|
(Resolve-Path "./$compiledPackageName").Path | Should -ReturnZeroExitCode
|
2020-06-09 19:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-09-09 17:35:55 +00:00
|
|
|
$compiledPackageName = "methods"
|
2020-09-09 22:57:10 +00:00
|
|
|
if ($IsWindows) { $compiledPackageName += ".exe" }
|
2020-09-09 17:35:55 +00:00
|
|
|
(Resolve-Path "./$compiledPackageName").Path | Should -ReturnZeroExitCode
|
2020-06-09 19:52:06 +00:00
|
|
|
}
|
2024-06-28 10:20:05 +00:00
|
|
|
}
|