diff --git a/ci/Invoke-Tests.ps1 b/ci/Invoke-Tests.ps1 index 92bdbbd7..b989c690 100644 --- a/ci/Invoke-Tests.ps1 +++ b/ci/Invoke-Tests.ps1 @@ -28,4 +28,4 @@ Invoke-Pester -Configuration $Config # Upload test results $wc = New-Object -TypeName "System.Net.WebClient" -$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path -Path $Config.TestResult.OutputPath)) +$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", "$env:APPVEYOR_BUILD_FOLDER\tests\TestResults.xml") diff --git a/tests/Manifest.Tests.ps1 b/tests/Manifest.Tests.ps1 index d0dbed79..d944bbac 100644 --- a/tests/Manifest.Tests.ps1 +++ b/tests/Manifest.Tests.ps1 @@ -9,13 +9,19 @@ param () BeforeDiscovery { + If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") { + $WorkingPath = $env:APPVEYOR_BUILD_FOLDER + } + Else { + $WorkingPath = $env:GITHUB_WORKSPACE + } Get-InstalledVcRedist | Uninstall-VcRedist -Confirm:$False $ValidateReleases = @("2017", "2019", "2022") } Describe "VcRedist manifest tests" -ForEach $ValidateReleases { BeforeAll { - $VcManifest = "$env:GITHUB_WORKSPACE\VcRedist\VisualCRedistributables.json" + $VcManifest = "$WorkingPath\VcRedist\VisualCRedistributables.json" Write-Host -ForegroundColor "Cyan" "`tGetting manifest from: $VcManifest." $CurrentManifest = Get-Content -Path $VcManifest | ConvertFrom-Json $VcRedist = $_ diff --git a/tests/Module.Tests.ps1 b/tests/Module.Tests.ps1 index 51a7f8aa..13b5235e 100644 --- a/tests/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -9,12 +9,17 @@ param () BeforeDiscovery { - + If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") { + $WorkingPath = $env:APPVEYOR_BUILD_FOLDER + } + Else { + $WorkingPath = $env:GITHUB_WORKSPACE + } } Describe "General module validation" { BeforeAll { - $scripts = Get-ChildItem -Path "$env:GITHUB_WORKSPACE\VcRedist" -Recurse -Include "*.ps1", "*.psm1", "*.psd1" + $scripts = Get-ChildItem -Path "$WorkingPath\VcRedist" -Recurse -Include "*.ps1", "*.psm1", "*.psd1" # TestCases are splatted to the script so we need hashtables $testCase = $scripts | ForEach-Object { @{file = $_ } } @@ -37,7 +42,7 @@ Describe "General module validation" { Describe "Function validation" { BeforeEach { - $scripts = Get-ChildItem -Path "$env:GITHUB_WORKSPACE\VcRedist" -Recurse -Include "*.ps1" + $scripts = Get-ChildItem -Path "$WorkingPath\VcRedist" -Recurse -Include "*.ps1" $testCase = $scripts | ForEach-Object { @{file = $_ } } } @@ -61,10 +66,10 @@ Describe "Function validation" { # Test module and manifest Describe 'Module Metadata validation' { It 'Script fileinfo should be OK' { - { Test-ModuleManifest -Path "$env:GITHUB_WORKSPACE\VcRedist\VcRedist.psd1" -ErrorAction "Stop" } | Should -Not -Throw + { Test-ModuleManifest -Path "$WorkingPath\VcRedist\VcRedist.psd1" -ErrorAction "Stop" } | Should -Not -Throw } It 'Import module should be OK' { - { Import-Module "$env:GITHUB_WORKSPACE\VcRedist" -Force -ErrorAction "Stop" } | Should -Not -Throw + { Import-Module "$WorkingPath\VcRedist" -Force -ErrorAction "Stop" } | Should -Not -Throw } } diff --git a/tests/PublicFunctions.Tests.ps1 b/tests/PublicFunctions.Tests.ps1 index f711c4f4..f505f4bf 100644 --- a/tests/PublicFunctions.Tests.ps1 +++ b/tests/PublicFunctions.Tests.ps1 @@ -11,6 +11,12 @@ param () BeforeDiscovery { $TestReleases = @("2012", "2013", "2015", "2017", "2019", "2022") $TestVcRedists = Get-VcList -Release $TestReleases + If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") { + $WorkingPath = $env:APPVEYOR_BUILD_FOLDER + } + Else { + $WorkingPath = $env:GITHUB_WORKSPACE + } } Describe -Name "Validate Get-VcList for " -Foreach $TestVcRedists { @@ -91,7 +97,7 @@ Describe -Name "Validate manifest counts" { Describe -Name "Validate manifest scenarios" { BeforeAll { - $Json = [System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "Redists.json") + $Json = [System.IO.Path]::Combine($WorkingPath, "Redists.json") Export-VcManifest -Path $Json $VcList = Get-VcList -Path $Json $VcCount = @{ @@ -109,17 +115,17 @@ Describe -Name "Validate manifest scenarios" { } Context "Test fail scenarios" { It "Given an JSON file that does not exist, it should throw an error" { - { Get-VcList -Path $([System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "RedistsFail.json")) } | Should -Throw + { Get-VcList -Path $([System.IO.Path]::Combine($WorkingPath, "RedistsFail.json")) } | Should -Throw } It "Given an invalid JSON file, should throw an error on read" { - { Get-VcList -Path $([System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "README.MD")) } | Should -Throw + { Get-VcList -Path $([System.IO.Path]::Combine($WorkingPath, "README.MD")) } | Should -Throw } } } Describe "Export-VcManifest" { BeforeAll { - $Json = [System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "Redists.json") + $Json = [System.IO.Path]::Combine($WorkingPath, "Redists.json") Export-VcManifest -Path $Json $VcList = Get-VcList -Path $Json $VcCount = @{ @@ -142,7 +148,7 @@ Describe "Export-VcManifest" { } Context "Test fail scenarios" { It "Given an invalid path, it should throw an error" { - { Export-VcManifest -Path $([System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "Temp", "Temp.json")) } | Should -Throw + { Export-VcManifest -Path $([System.IO.Path]::Combine($WorkingPath, "Temp", "Temp.json")) } | Should -Throw } } } @@ -229,7 +235,7 @@ Describe "Save-VcRedist pipeline" { Context "Test fail scenarios" { It "Given an invalid path, it should throw an error" { - { Save-VcRedist -Path ([System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "Temp")) } | Should -Throw + { Save-VcRedist -Path ([System.IO.Path]::Combine($WorkingPath, "Temp")) } | Should -Throw } }