Skip to content

Commit 6924975

Browse files
committed
feat: Update Mock-EnvironmentVariable.Tests.ps1
Add a test to check that an environment variable is reinitialiazed if it got destroyed
1 parent da49907 commit 6924975

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/PesterExtensions/Public/Mock-EnvironmentVariable.Tests.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ Describe 'Mock an environment variable' {
5353
}
5454
}
5555

56+
Describe 'Restore variable that got destroyed' {
57+
BeforeAll {
58+
$script:environmentVariableName = "test$(New-Guid)"
59+
$script:environmentVariable = "env:${environmentVariableName}"
60+
$script:InitialValue = 'Some value here and there'
61+
$script:UpdatedValue = 'Some updated value'
62+
New-Item -Path $environmentVariable -Value $InitialValue
63+
Mock-EnvironmentVariable -Variable $environmentVariableName -Value $UpdatedValue {
64+
Remove-Item -Path $environmentVariable -Recurse -Force -ErrorAction Ignore
65+
}
66+
}
67+
It 'Environment variable is set up' {
68+
(Get-ChildItem -Path $environmentVariable).Value | Should -Be $InitialValue
69+
}
70+
AfterAll {
71+
Remove-Item `
72+
-Path $environmentVariable `
73+
-Force `
74+
-Recurse `
75+
-ErrorAction Ignore
76+
}
77+
78+
}
79+
5680
Describe 'Initial value should be reasigned' {
5781
BeforeAll {
5882
$script:environmentVariableName = "test$(New-Guid)"

0 commit comments

Comments
 (0)