-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Adds Platform Guards Around UnixFileMode Enum
The UnixFileMode enum type is not defined before PowerShell 7.3 and/or .NET 7, (which our GitHub runners don't have yet.)
- Loading branch information
1 parent
59cae0e
commit cc8aac5
Showing
4 changed files
with
192 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env pwsh | ||
#Requires -Modules "Pester" | ||
$ErrorActionPreference = "Stop" | ||
Set-StrictMode -Version Latest | ||
|
||
|
||
BeforeAll { | ||
$SutFile = Get-Item "$PSScriptRoot/../src/Set-ItemNixMode.ps1" | ||
$SutName = $SutFile.BaseName | ||
} | ||
|
||
Describe "SUT file" { | ||
It "should exist" { | ||
$SutFile | Should -Exist | ||
} | ||
|
||
It "should be sourceable" { | ||
{ . $SutFile.FullName } | Should -Not -Throw | ||
} | ||
|
||
Context "when sourced" { | ||
BeforeEach { | ||
. $SutFile | ||
} | ||
|
||
Describe "function" { | ||
BeforeDiscovery { | ||
$FileModeSettingNotSupported = $IsWindows -or ($null -eq [Type]::GetType("System.IO.UnixFileMode")) | ||
} | ||
|
||
It "should be defined" { | ||
Get-Command -Name $SutName -CommandType Function | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
Context "when invoked" -Skip:$FileModeSettingNotSupported { | ||
Context "with no arguments" { | ||
It "should throw" { | ||
{ & $SutName } | Should -Throw | ||
} | ||
} | ||
|
||
Context "for an existing file" { | ||
BeforeEach { | ||
$targetFile = New-TemporaryFile | ||
} | ||
|
||
AfterEach { | ||
Remove-Item $targetFile.FullName -Force | ||
} | ||
|
||
Context "ModeOctal is 700" { | ||
It "should set the mode" { | ||
$modeOctalParameter = '700' | ||
[System.IO.UnixFileMode] $expectedMode = [System.IO.UnixFileMode]::OwnerRead -bor [System.IO.UnixFileMode]::OwnerWrite -bor [System.IO.UnixFileMode]::OwnerExecute | ||
|
||
Set-ItemNixMode -Path $targetFile -ModeOctal $modeOctalParameter | ||
|
||
$targetFile.Refresh() | ||
$targetFile.Mode | Should -Be $expectedMode | ||
} | ||
} | ||
|
||
Context "ModeOctal is 555" { | ||
It "should set the mode" { | ||
$modeOctalParameter = '555' | ||
[System.IO.UnixFileMode] $expectedMode = [System.IO.UnixFileMode]::OwnerRead -bor [System.IO.UnixFileMode]::OwnerExecute -bor [System.IO.UnixFileMode]::GroupRead -bor [System.IO.UnixFileMode]::GroupExecute -bor [System.IO.UnixFileMode]::OthersRead -bor [System.IO.UnixFileMode]::OthersExecute | ||
|
||
Set-ItemNixMode -Path $targetFile -ModeOctal $modeOctalParameter | ||
|
||
$targetFile.Refresh() | ||
$targetFile.Mode | Should -Be $expectedMode | ||
} | ||
} | ||
|
||
Context "ModeOctal is 644" { | ||
It "should set the mode" { | ||
$modeOctalParameter = '644' | ||
[System.IO.UnixFileMode] $expectedMode = [System.IO.UnixFileMode]::OwnerRead -bor [System.IO.UnixFileMode]::OwnerWrite -bor [System.IO.UnixFileMode]::GroupRead -bor [System.IO.UnixFileMode]::OthersRead | ||
|
||
Set-ItemNixMode -Path $targetFile -ModeOctal $modeOctalParameter | ||
|
||
$targetFile.Refresh() | ||
$targetFile.Mode | Should -Be $expectedMode | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |