Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real path to temp path on macOS and GetTempPath() otherwise when constructing TestDrive #1294

Merged
merged 4 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Functions/Environment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ InModuleScope -ModuleName Pester {


Describe 'Get-TempDirectory' {
It 'returns the correct temp directory for Windows' {
Mock 'GetPesterOs' {
'Windows'
}
$expected = $env:TEMP = "C:\temp"
It 'returns the correct temp directory for Windows' -Skip:((GetPesterOs) -ne 'Windows') {
$expected = [System.IO.Path]::GetTempPath()

$temp = Get-TempDirectory
$temp | Should -Not -BeNullOrEmpty
Expand All @@ -106,10 +103,10 @@ InModuleScope -ModuleName Pester {
Mock 'GetPesterOs' {
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved
'MacOS'
}
Get-TempDirectory | Should -Be '/tmp'
Get-TempDirectory | Should -Be '/private/tmp'
}

It "returns '/tmp' directory for Linux" {
It "returns '/tmp' directory for Linux" -Skip:((GetPesterOs) -ne 'Linux') {
Mock 'GetPesterOs' {
'Linux'
}
Expand Down
7 changes: 4 additions & 3 deletions Functions/Environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ function GetPesterOs {
}

function Get-TempDirectory {
if ((GetPesterOs) -eq 'Windows') {
$env:TEMP
if ((GetPesterOs) -eq 'macOS') {
# Special case for macOS using the real path instead of /tmp which is a symlink to this path
"/private/tmp"
}
else {
'/tmp'
[System.IO.Path]::GetTempPath()
}
}

Expand Down
9 changes: 6 additions & 3 deletions Functions/TestDrive.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Set-StrictMode -Version Latest
if ($PSVersionTable.PSVersion.Major -lt 6 -or $IsWindows) {
$tempPath = $env:TEMP
}
elseif ($IsMacOS) {
$tempPath = '/private/tmp'
}
else {
$tempPath = '/tmp'
}
Expand Down Expand Up @@ -179,7 +182,7 @@ InModuleScope Pester {
# Symlink cmdlets were introduced in PowerShell v5 and deleting them
# requires running as admin, so skip tests when those conditions are
# not met
if ((GetPesterOs) -eq "Windows") {
if ((GetPesterOs) -eq "Windows") {
if ($psVersion -lt 5) {
$skipTest = $true
}
Expand All @@ -197,8 +200,8 @@ InModuleScope Pester {
It "Deletes symbolic links in TestDrive" -skip:$skipTest {

# using non-powershell paths here because we need to interop with cmd below
$root = (Get-PsDrive 'TestDrive').Root
$source = "$root\source"
$root = (Get-PsDrive 'TestDrive').Root
$source = "$root\source"
$symlink = "$root\symlink"

$null = New-Item -Type Directory -Path $source
Expand Down