Skip to content

Commit

Permalink
Update tests for working path
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Apr 3, 2022
1 parent 37e2249 commit a9e6e8b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ci/Invoke-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
8 changes: 7 additions & 1 deletion tests/Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $_
Expand Down
15 changes: 10 additions & 5 deletions tests/Module.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $_ } }
Expand All @@ -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 = $_ } }
}

Expand All @@ -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
}
}
18 changes: 12 additions & 6 deletions tests/PublicFunctions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <VcRedist.Name>" -Foreach $TestVcRedists {
Expand Down Expand Up @@ -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 = @{
Expand All @@ -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 = @{
Expand All @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit a9e6e8b

Please sign in to comment.