Skip to content

Commit

Permalink
Add $env:WorkingPath
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Apr 4, 2022
1 parent 5e1d5dd commit d7df1c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 60 deletions.
14 changes: 7 additions & 7 deletions tests/Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ param ()
BeforeDiscovery {
Get-InstalledVcRedist | Uninstall-VcRedist -Confirm:$False
$ValidateReleases = @("2017", "2019", "2022")
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
[System.Environment]::SetEnvironmentVariable("WorkingPath",$env:GITHUB_WORKSPACE)
}
Else {
[System.Environment]::SetEnvironmentVariable("WorkingPath",$env:APPVEYOR_BUILD_FOLDER)
}
}

Describe "VcRedist manifest tests" -ForEach $ValidateReleases {
Context "Validate manifest" {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
$VcManifest = "$WorkingPath\VcRedist\VisualCRedistributables.json"
$VcManifest = "$env:WorkingPath\VcRedist\VisualCRedistributables.json"
Write-Host -ForegroundColor "Cyan" "`tGetting manifest from: $VcManifest."
$CurrentManifest = Get-Content -Path $VcManifest | ConvertFrom-Json
$VcRedist = $_
Expand Down
33 changes: 10 additions & 23 deletions tests/Module.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
param ()

BeforeDiscovery {

If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
[System.Environment]::SetEnvironmentVariable("WorkingPath", $env:GITHUB_WORKSPACE)
}
Else {
[System.Environment]::SetEnvironmentVariable("WorkingPath", $env:APPVEYOR_BUILD_FOLDER)
}
}

Describe "General module validation" {
Context 'Validation' {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
$scripts = Get-ChildItem -Path "$WorkingPath\VcRedist" -Recurse -Include "*.ps1", "*.psm1", "*.psd1"
$scripts = Get-ChildItem -Path "$env:WorkingPath\VcRedist" -Recurse -Include "*.ps1", "*.psm1", "*.psd1"

# TestCases are splatted to the script so we need hashtables
$testCase = $scripts | ForEach-Object { @{file = $_ } }
Expand All @@ -45,13 +44,7 @@ Describe "General module validation" {
Describe "Function validation" {
Context 'Validation' {
BeforeEach {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
$scripts = Get-ChildItem -Path "$WorkingPath\VcRedist" -Recurse -Include "*.ps1"
$scripts = Get-ChildItem -Path "$env:WorkingPath\VcRedist" -Recurse -Include "*.ps1"
$testCase = $scripts | ForEach-Object { @{file = $_ } }
}

Expand All @@ -77,20 +70,14 @@ Describe "Function validation" {
Describe 'Module Metadata validation' {
Context 'File info' {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
}

It 'Script fileinfo should be OK' {
{ Test-ModuleManifest -Path "$WorkingPath\VcRedist\VcRedist.psd1" -ErrorAction "Stop" } | Should -Not -Throw
{ Test-ModuleManifest -Path "$env:WorkingPath\VcRedist\VcRedist.psd1" -ErrorAction "Stop" } | Should -Not -Throw
}

It 'Import module should be OK' {
{ Import-Module "$WorkingPath\VcRedist" -Force -ErrorAction "Stop" } | Should -Not -Throw
{ Import-Module "$env:WorkingPath\VcRedist" -Force -ErrorAction "Stop" } | Should -Not -Throw
}
}
}
42 changes: 12 additions & 30 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") {
[System.Environment]::SetEnvironmentVariable("WorkingPath",$env:GITHUB_WORKSPACE)
}
Else {
[System.Environment]::SetEnvironmentVariable("WorkingPath",$env:APPVEYOR_BUILD_FOLDER)
}
}

Describe -Name "Validate Get-VcList for <VcRedist.Name>" -ForEach $TestVcRedists {
Expand Down Expand Up @@ -92,13 +98,7 @@ Describe -Name "Validate manifest counts" {
Describe -Name "Validate manifest scenarios" {
Context 'Validation' {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
$Json = [System.IO.Path]::Combine($WorkingPath, "Redists.json")
$Json = [System.IO.Path]::Combine($env:WorkingPath, "Redists.json")
Export-VcManifest -Path $Json
$VcList = Get-VcList -Path $Json
$VcCount = @{
Expand All @@ -113,24 +113,18 @@ Describe -Name "Validate manifest scenarios" {
$VcList.Count | Should -BeGreaterOrEqual $VcCount.Default
}
It "Given an JSON file that does not exist, it should throw an error" {
{ Get-VcList -Path $([System.IO.Path]::Combine($WorkingPath, "RedistsFail.json")) } | Should -Throw
{ Get-VcList -Path $([System.IO.Path]::Combine($env:WorkingPath, "RedistsFail.json")) } | Should -Throw
}
It "Given an invalid JSON file, should throw an error on read" {
{ Get-VcList -Path $([System.IO.Path]::Combine($WorkingPath, "README.MD")) } | Should -Throw
{ Get-VcList -Path $([System.IO.Path]::Combine($env:WorkingPath, "README.MD")) } | Should -Throw
}
}
}

Describe "Export-VcManifest" {
Context 'Validation' {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
$Json = [System.IO.Path]::Combine($WorkingPath, "Redists.json")
$Json = [System.IO.Path]::Combine($env:WorkingPath, "Redists.json")
Export-VcManifest -Path $Json
$VcList = Get-VcList -Path $Json
$VcCount = @{
Expand All @@ -148,7 +142,7 @@ Describe "Export-VcManifest" {
$VcList.Count | Should -BeGreaterOrEqual $VcCount.Default
}
It "Given an invalid path, it should throw an error" {
{ Export-VcManifest -Path $([System.IO.Path]::Combine($WorkingPath, "Temp", "Temp.json")) } | Should -Throw
{ Export-VcManifest -Path $([System.IO.Path]::Combine($env:WorkingPath, "Temp", "Temp.json")) } | Should -Throw
}
}
}
Expand Down Expand Up @@ -221,22 +215,10 @@ Describe "Save-VcRedist" {

Describe "Save-VcRedist pipeline" {
BeforeAll {
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
if ([System.String]::IsNullOrWhiteSpace($env:Temp)) { $DownloadDir = $env:Temp } else { $DownloadDir = $env:TMPDIR }
New-Item -Path ([System.IO.Path]::Combine($DownloadDir, "VcTest")) -ItemType "Directory" -ErrorAction "SilentlyContinue" > $Null
Push-Location -Path ([System.IO.Path]::Combine($DownloadDir, "VcTest"))
$TestReleases = @("2012", "2013", "2015", "2017", "2019", "2022")
If (Test-Path -Path env:GITHUB_WORKSPACE -ErrorAction "SilentlyContinue") {
$WorkingPath = $env:APPVEYOR_BUILD_FOLDER
}
Else {
$WorkingPath = $env:GITHUB_WORKSPACE
}
}

Context "Test pipeline support" {
Expand All @@ -247,7 +229,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($WorkingPath, "Temp")) } | Should -Throw
{ Save-VcRedist -Path ([System.IO.Path]::Combine($env:WorkingPath, "Temp")) } | Should -Throw
}
}

Expand Down

0 comments on commit d7df1c5

Please sign in to comment.