-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get-PSModulePath
: Throw exception on missing My Documents folder (#125
- Loading branch information
Showing
6 changed files
with
126 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<# | ||
.SYNOPSIS | ||
Returns the user name cross-plattform. | ||
.DESCRIPTION | ||
Returns the current user name cross-plattform. The variable `$env:USERNAME` | ||
does not exist cross-platform which hinders development and testing on | ||
macOS and Linux. Instead this command can be used to get the user name | ||
cross-plattform. | ||
.OUTPUTS | ||
System.String | ||
.EXAMPLE | ||
Get-UserName | ||
Returns the user name regardless of platform. | ||
#> | ||
function Get-UserName | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param () | ||
|
||
$userName = $null | ||
|
||
if ($IsLinux -or $IsMacOs) | ||
{ | ||
$userName = $env:USER | ||
} | ||
else | ||
{ | ||
$userName = $env:USERNAME | ||
} | ||
|
||
return $userName | ||
} |
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,60 @@ | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] | ||
param () | ||
|
||
BeforeDiscovery { | ||
try | ||
{ | ||
if (-not (Get-Module -Name 'DscResource.Test')) | ||
{ | ||
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task. | ||
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) | ||
{ | ||
# Redirect all streams to $null, except the error stream (stream 2) | ||
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null | ||
} | ||
|
||
# If the dependencies has not been resolved, this will throw an error. | ||
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' | ||
} | ||
} | ||
catch [System.IO.FileNotFoundException] | ||
{ | ||
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' | ||
} | ||
} | ||
|
||
BeforeAll { | ||
$script:moduleName = 'DscResource.Common' | ||
|
||
# Make sure there are not other modules imported that will conflict with mocks. | ||
Get-Module -Name $script:moduleName -All | Remove-Module -Force | ||
|
||
# Re-import the module using force to get any code changes between runs. | ||
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' | ||
|
||
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName | ||
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName | ||
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName | ||
} | ||
|
||
AfterAll { | ||
$PSDefaultParameterValues.Remove('Mock:ModuleName') | ||
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName') | ||
$PSDefaultParameterValues.Remove('Should:ModuleName') | ||
|
||
Remove-Module -Name $script:moduleName | ||
} | ||
|
||
Describe 'Get-UserName' { | ||
Context 'When getting user name on Windows' -Skip:($IsLinux -or $IsMacOs) { | ||
It 'Should return the correct user name' { | ||
Get-UserName | Should -Be $env:USERNAME | ||
} | ||
} | ||
|
||
Context 'When getting user name' -Skip:($IsWindows -or $PSEdition -eq 'Desktop') { | ||
It 'Should return the correct user name' { | ||
Get-UserName | Should -Be $env:USER | ||
} | ||
} | ||
} |