Skip to content

Commit 87ecb7a

Browse files
author
Andrew
committed
Added tests
1 parent 9711de9 commit 87ecb7a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

powershell-adapter/Tests/powershellgroup.resource.tests.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,31 @@ Describe 'PowerShell adapter resource tests' {
280280

281281
$env:TestClassResourceResultCount = $null
282282
}
283+
284+
It 'Verify that there are no cache rebuids for several sequential executions' {
285+
286+
# remove cache file
287+
$cacheFilePath = if ($IsWindows) {
288+
# PS 6+ on Windows
289+
Join-Path $env:LocalAppData "dsc\PSAdapterCache.json"
290+
} else {
291+
# either WinPS or PS 6+ on Linux/Mac
292+
if ($PSVersionTable.PSVersion.Major -le 5) {
293+
Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json"
294+
} else {
295+
Join-Path $env:HOME ".dsc" "PSAdapterCache.json"
296+
}
297+
}
298+
Remove-Item -Force -Path $cacheFilePath -ErrorAction SilentlyContinue
299+
300+
# first execution should build the cache
301+
dsc -l trace resource list -a Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
302+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Constructing Get-DscResource cache'
303+
304+
# next executions following shortly after should Not rebuild the cache
305+
1..3 | %{
306+
dsc -l trace resource list -a Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
307+
"$TestDrive/tracing.txt" | Should -Not -FileContentMatchExactly 'Constructing Get-DscResource cache'
308+
}
309+
}
283310
}

powershell-adapter/Tests/win_powershellgroup.tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,21 @@ Describe 'WindowsPowerShell adapter resource tests' {
7070
$res = $r | ConvertFrom-Json
7171
$res.results[0].result.actualState.result[0].properties.DestinationPath | Should -Be "$testFile"
7272
}
73+
74+
It 'Verify that there are no cache rebuids for several sequential executions' {
75+
76+
# remove cache file
77+
$cacheFilePath = Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json"
78+
Remove-Item -Force -Path $cacheFilePath -ErrorAction SilentlyContinue
79+
80+
# first execution should build the cache
81+
dsc -l trace resource list -a Microsoft.Windows/WindowsPowerShell 2> $TestDrive/tracing.txt
82+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Constructing Get-DscResource cache'
83+
84+
# next executions following shortly after should Not rebuild the cache
85+
1..3 | %{
86+
dsc -l trace resource list -a Microsoft.Windows/WindowsPowerShell 2> $TestDrive/tracing.txt
87+
"$TestDrive/tracing.txt" | Should -Not -FileContentMatchExactly 'Constructing Get-DscResource cache'
88+
}
89+
}
7390
}

0 commit comments

Comments
 (0)