mirror of
https://github.com/PowerShell/PSDscResources
synced 2026-06-21 13:45:29 +00:00
fixing a few minor errors
This commit is contained in:
@@ -3,15 +3,15 @@
|
||||
Creates the environment variable 'TestEnvironmentVariable' and sets the value to 'TestValue'
|
||||
both on the machine and within the process.
|
||||
#>
|
||||
Configuration Sample_xEnvironment_CreateNonPathVariable
|
||||
Configuration Sample_Environment_CreateNonPathVariable
|
||||
{
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
Node localhost
|
||||
{
|
||||
xEnvironment CreateEnvironmentVariable
|
||||
Environment CreateEnvironmentVariable
|
||||
{
|
||||
Name = 'TestEnvironmentVariable'
|
||||
Value = 'TestValue'
|
||||
@@ -22,4 +22,4 @@ Configuration Sample_xEnvironment_CreateNonPathVariable
|
||||
}
|
||||
}
|
||||
|
||||
Sample_xEnvironment_CreateNonPathVariable
|
||||
Sample_Environment_CreateNonPathVariable
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
if it doesn't already exist or appends the value 'TestValue' to the existing path if it does
|
||||
already exist on the machine and within the process.
|
||||
#>
|
||||
Configuration Sample_xEnvironment_CreatePathVariable
|
||||
Configuration Sample_Environment_CreatePathVariable
|
||||
{
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
Node localhost
|
||||
{
|
||||
xEnvironment CreatePathEnvironmentVariable
|
||||
Environment CreatePathEnvironmentVariable
|
||||
{
|
||||
Name = 'TestPathEnvironmentVariable'
|
||||
Value = 'TestValue'
|
||||
@@ -23,4 +23,4 @@ Configuration Sample_xEnvironment_CreatePathVariable
|
||||
}
|
||||
}
|
||||
|
||||
Sample_xEnvironment_CreatePathVariable
|
||||
Sample_Environment_CreatePathVariable
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
Removes the environment variable 'TestEnvironmentVariable' from
|
||||
both the machine and the process.
|
||||
#>
|
||||
Configuration Sample_xEnvironment_Remove
|
||||
Configuration Sample_Environment_Remove
|
||||
{
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
Node localhost
|
||||
{
|
||||
xEnvironment RemoveEnvironmentVariable
|
||||
Environment RemoveEnvironmentVariable
|
||||
{
|
||||
Name = 'TestEnvironmentVariable'
|
||||
Ensure = 'Absent'
|
||||
@@ -21,4 +21,4 @@ Configuration Sample_xEnvironment_Remove
|
||||
}
|
||||
}
|
||||
|
||||
Sample_xEnvironment_Remove
|
||||
Sample_Environment_Remove
|
||||
|
||||
@@ -15,268 +15,268 @@ $script:testEnvironment = Enter-DscResourceTestEnvironment `
|
||||
|
||||
try
|
||||
{
|
||||
Describe 'Environment Integration Tests' {
|
||||
BeforeAll {
|
||||
# Import environment resource module for Get-TargetResource, Test-TargetResource, Set-TargetResource
|
||||
$moduleRootFilePath = Split-Path -Path (Split-Path $PSScriptRoot -Parent) -Parent
|
||||
$dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources'
|
||||
$environmentResourceFolderFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'MSFT_EnvironmentResource'
|
||||
$environmentResourceModuleFilePath = Join-Path -Path $environmentResourceFolderFilePath -ChildPath 'MSFT_EnvironmentResource.psm1'
|
||||
Import-Module -Name $environmentResourceModuleFilePath -Force
|
||||
}
|
||||
|
||||
It 'Should return the correct value for an environment variable that exists' {
|
||||
$envVar = 'Username'
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully retrieved
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
$regItem = Get-Item -Path 'HKLM:\\System\\CurrentControlSet\\Control\\Session Manager\\Environment'
|
||||
$matchVar = $regItem.GetValue($envVar)
|
||||
$retrievedVarValue = $retrievedVar.Value
|
||||
|
||||
# Verify the $retrievedVar environmnet variable value matches the value retrieved using [Environment] API
|
||||
$retrievedVarValue | Should Be $matchVar
|
||||
}
|
||||
|
||||
It 'Should return Absent for an environment variable that does not exists' {
|
||||
$envVar = 'BlahVar'
|
||||
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is not found
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should throw an error when creating a new environment variable with no Value specified' {
|
||||
# Ensure the variable does not already exist
|
||||
$envVar = 'TestEnvVar'
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
{ Set-TargetResource -Name $envVar } | Should Throw
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully created
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
|
||||
# Verify the create environmnet variable's value is set to default value [String]::Empty
|
||||
$retrievedVar.Value | Should Be $null
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should create a new environment variable with the Value specified' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Ensure the value does not already exist
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully created
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
# Verify the create environmnet variable's value is set
|
||||
$retrievedVar.Value | Should Be $val
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should update existing environment variable with new Value' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Create the environment variable
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Update the environment variable
|
||||
$newVal = 'TestEnvNewVal'
|
||||
Set-TargetResource -Name $envVar -Value $newVal
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully updated
|
||||
$retrievedVar.Value | Should Be $newVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should Remove an existing environment variable (Ensure = Absent)' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Create the environment variable
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should update a path environment variable' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$addPathVal = 'D'
|
||||
Set-TargetResource -Name $envVar -Value $addPathVal -Path $true
|
||||
|
||||
$expectedFinalVal = $val + ';' + $addPathVal
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Value | Should Be $expectedFinalVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should remove a sub-path from a path environment variable' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$removePathVal = 'C'
|
||||
Set-TargetResource -Name $envVar -Value $removePathVal -Path $true -Ensure Absent
|
||||
|
||||
$expectedFinalVal = 'A;B'
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Value | Should Be $expectedFinalVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should remove a path environment variable by removing all its sub-paths' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$removePathVal = 'C;B;A'
|
||||
Set-TargetResource -Name $envVar -Value $removePathVal -Path $true -Ensure Absent
|
||||
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment variable is present and should be' {
|
||||
$envVar = 'BlahVar'
|
||||
$val = 'A;B;C'
|
||||
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Test the created environmnet variable
|
||||
Test-TargetResource -Name $envVar | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment environment with a specific value exists and should' {
|
||||
$envVar = 'BlahVar'
|
||||
$val = 'BlahVal'
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Value $val | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment variable is absent and should be' {
|
||||
$envVar = 'BlahVar'
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Ensure Absent | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a path exists in a path environment variable and should' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'B'
|
||||
|
||||
# Test a sub-path exists in environment variable
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a matching but shuffled path exists in a path environment variable' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'B;a;c'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a path does not exist in a path environment variable and should not' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'D;E'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true -Ensure Absent | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should retrieve an existing environment variable using Get-TargetResource' {
|
||||
$envVar = 'windir'
|
||||
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully retrieved
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
$matchVar = '%SystemRoot%'
|
||||
$retrievedVarValue = $retrievedVar.Value
|
||||
|
||||
# Verify the $retrievedVar environmnet variable value matches the value retrieved using [Environment] API
|
||||
$retrievedVarValue | Should Be $matchVar
|
||||
}
|
||||
Describe 'Environment Integration Tests' {
|
||||
BeforeAll {
|
||||
# Import environment resource module for Get-TargetResource, Test-TargetResource, Set-TargetResource
|
||||
$moduleRootFilePath = Split-Path -Path (Split-Path $PSScriptRoot -Parent) -Parent
|
||||
$dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources'
|
||||
$environmentResourceFolderFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'MSFT_EnvironmentResource'
|
||||
$environmentResourceModuleFilePath = Join-Path -Path $environmentResourceFolderFilePath -ChildPath 'MSFT_EnvironmentResource.psm1'
|
||||
Import-Module -Name $environmentResourceModuleFilePath -Force
|
||||
}
|
||||
|
||||
It 'Should return the correct value for an environment variable that exists' {
|
||||
$envVar = 'Username'
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully retrieved
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
$regItem = Get-Item -Path 'HKLM:\\System\\CurrentControlSet\\Control\\Session Manager\\Environment'
|
||||
$matchVar = $regItem.GetValue($envVar)
|
||||
$retrievedVarValue = $retrievedVar.Value
|
||||
|
||||
# Verify the $retrievedVar environmnet variable value matches the value retrieved using [Environment] API
|
||||
$retrievedVarValue | Should Be $matchVar
|
||||
}
|
||||
|
||||
It 'Should return Absent for an environment variable that does not exists' {
|
||||
$envVar = 'BlahVar'
|
||||
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is not found
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should throw an error when creating a new environment variable with no Value specified' {
|
||||
# Ensure the variable does not already exist
|
||||
$envVar = 'TestEnvVar'
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
{ Set-TargetResource -Name $envVar } | Should Throw
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully created
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
|
||||
# Verify the create environmnet variable's value is set to default value [String]::Empty
|
||||
$retrievedVar.Value | Should Be $null
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should create a new environment variable with the Value specified' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Ensure the value does not already exist
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully created
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
# Verify the create environmnet variable's value is set
|
||||
$retrievedVar.Value | Should Be $val
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should update existing environment variable with new Value' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Create the environment variable
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Update the environment variable
|
||||
$newVal = 'TestEnvNewVal'
|
||||
Set-TargetResource -Name $envVar -Value $newVal
|
||||
|
||||
# Now retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully updated
|
||||
$retrievedVar.Value | Should Be $newVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should Remove an existing environment variable (Ensure = Absent)' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'TestEnvVal'
|
||||
|
||||
# Create the environment variable
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should update a path environment variable' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$addPathVal = 'D'
|
||||
Set-TargetResource -Name $envVar -Value $addPathVal -Path $true
|
||||
|
||||
$expectedFinalVal = $val + ';' + $addPathVal
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Value | Should Be $expectedFinalVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should remove a sub-path from a path environment variable' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$removePathVal = 'C'
|
||||
Set-TargetResource -Name $envVar -Value $removePathVal -Path $true -Ensure Absent
|
||||
|
||||
$expectedFinalVal = 'A;B'
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Value | Should Be $expectedFinalVal
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should remove a path environment variable by removing all its sub-paths' {
|
||||
$envVar = 'TestEnvVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$removePathVal = 'C;B;A'
|
||||
Set-TargetResource -Name $envVar -Value $removePathVal -Path $true -Ensure Absent
|
||||
|
||||
# Now try to retrieve the created variable
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable no more exists
|
||||
$retrievedVar.Ensure | Should Be 'Absent'
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment variable is present and should be' {
|
||||
$envVar = 'BlahVar'
|
||||
$val = 'A;B;C'
|
||||
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Test the created environmnet variable
|
||||
Test-TargetResource -Name $envVar | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment environment with a specific value exists and should' {
|
||||
$envVar = 'BlahVar'
|
||||
$val = 'BlahVal'
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Value $val | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when an environment variable is absent and should be' {
|
||||
$envVar = 'BlahVar'
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Ensure Absent | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a path exists in a path environment variable and should' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'B'
|
||||
|
||||
# Test a sub-path exists in environment variable
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a matching but shuffled path exists in a path environment variable' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'B;a;c'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should return true when a path does not exist in a path environment variable and should not' {
|
||||
$envVar = 'PathVar'
|
||||
$val = 'A;B;C'
|
||||
Set-TargetResource -Name $envVar -Value $val -Path $true
|
||||
|
||||
$subpath = 'D;E'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true -Ensure Absent | Should Be $true
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
}
|
||||
|
||||
It 'Should retrieve an existing environment variable using Get-TargetResource' {
|
||||
$envVar = 'windir'
|
||||
|
||||
$retrievedVar = Get-TargetResource -Name $envVar
|
||||
|
||||
# Verify the environmnet variable $envVar is successfully retrieved
|
||||
$retrievedVar.Ensure | Should Be 'Present'
|
||||
|
||||
$matchVar = '%SystemRoot%'
|
||||
$retrievedVarValue = $retrievedVar.Value
|
||||
|
||||
# Verify the $retrievedVar environmnet variable value matches the value retrieved using [Environment] API
|
||||
$retrievedVarValue | Should Be $matchVar
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user