@@ -30,7 +30,7 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
30
30
$r = dsc resource list -- adapter Microsoft.Windows/ WindowsPowerShell
31
31
$LASTEXITCODE | Should - Be 0
32
32
$resources = $r | ConvertFrom-Json
33
- ($resources | ? {$_.Type -eq ' PSDesiredStateConfiguration/File' }).Count | Should - Be 1
33
+ ($resources | Where-Object {$_.Type -eq ' PSDesiredStateConfiguration/File' }).Count | Should - Be 1
34
34
}
35
35
36
36
It ' Get works on Binary "File" resource' - Skip:(! $IsWindows ){
@@ -72,7 +72,6 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
72
72
}
73
73
74
74
It ' Verify that there are no cache rebuilds for several sequential executions' - Skip:(! $IsWindows ) {
75
-
76
75
# remove cache file
77
76
$cacheFilePath = Join-Path $env: LocalAppData " dsc\WindowsPSAdapterCache.json"
78
77
Remove-Item - Force - Path $cacheFilePath - ErrorAction Ignore
@@ -82,12 +81,100 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
82
81
" $TestDrive /tracing.txt" | Should - FileContentMatchExactly ' Constructing Get-DscResource cache'
83
82
84
83
# next executions following shortly after should Not rebuild the cache
85
- 1 .. 3 | % {
84
+ 1 .. 3 | ForEach-Object {
86
85
dsc - l trace resource list - a Microsoft.Windows/ WindowsPowerShell 2> $TestDrive / tracing.txt
87
86
" $TestDrive /tracing.txt" | Should -Not - FileContentMatchExactly ' Constructing Get-DscResource cache'
88
87
}
89
88
}
90
89
90
+ It ' Verify if assertion is used that no module is cleared in the cache' - Skip:(! $IsWindows ) {
91
+ # create a test file in the test drive
92
+ $testFile = " $testdrive \test.txt"
93
+ New-Item - Path $testFile - ItemType File - Force | Out-Null
94
+
95
+ # remove cache file
96
+ $cacheFilePath = Join-Path $env: LocalAppData " dsc\WindowsPSAdapterCache.json"
97
+ Remove-Item - Force - Path $cacheFilePath - ErrorAction Ignore
98
+
99
+ # build the cache
100
+ dsc resource list -- adapter Microsoft.Windows/ WindowsPowerShell | Out-Null
101
+
102
+ # Create a test module in the test drive
103
+ $testModuleDir = " $testdrive \TestModule\1.0.0"
104
+ New-Item - Path $testModuleDir - ItemType Directory - Force | Out-Null
105
+
106
+ $manifestContent = @"
107
+ @{
108
+ RootModule = 'TestModule.psm1'
109
+ ModuleVersion = '1.0.0'
110
+ GUID = $ ( [guid ]::NewGuid().Guid)
111
+ Author = 'Microsoft Corporation'
112
+ CompanyName = 'Microsoft Corporation'
113
+ Copyright = '(c) Microsoft Corporation. All rights reserved.'
114
+ Description = 'Test module for DSC tests'
115
+ PowerShellVersion = '5.1'
116
+ DscResourcesToExport = @()
117
+ FunctionsToExport = @()
118
+ CmdletsToExport = @()
119
+ VariablesToExport = @()
120
+ AliasesToExport = @()
121
+ }
122
+ "@
123
+ Set-Content - Path " $testModuleDir \TestModule.psd1" - Value $manifestContent
124
+
125
+ $scriptContent = @"
126
+ Write-Host 'The DSC world!'
127
+ "@
128
+ Set-Content - Path " $testModuleDir \TestModule.psm1" - Value $scriptContent
129
+
130
+ # Add the test module directory to PSModulePath
131
+ $env: PSModulePath += [System.IO.Path ]::PathSeparator + $testdrive
132
+
133
+ $yaml = @"
134
+ `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
135
+ resources:
136
+ - name: File
137
+ type: Microsoft.Windows/WindowsPowerShell
138
+ properties:
139
+ resources:
140
+ - name: File
141
+ type: PSDesiredStateConfiguration/File
142
+ properties:
143
+ DestinationPath: $testfile
144
+ - name: File present
145
+ type: Microsoft.DSC/Assertion
146
+ properties:
147
+ `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
148
+ resources:
149
+ - name: Use powershell adapter
150
+ type: Microsoft.Windows/WindowsPowerShell
151
+ properties:
152
+ resources:
153
+ - name: File present
154
+ type: PSDesiredStateConfiguration/File
155
+ properties:
156
+ DestinationPath: $testFile
157
+ dependsOn:
158
+ - "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
159
+ - name: TestPSRepository
160
+ type: PSTestModule/TestPSRepository
161
+ properties:
162
+ Name: NuGet
163
+ dependsOn:
164
+ - "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
165
+ - "[resourceId('Microsoft.DSC/Assertion', 'File present')]"
166
+ "@
167
+ # output to file for Windows PowerShell 5.1
168
+ $filePath = " $testdrive \test.assertion.dsc.resource.yaml"
169
+ $yaml | Set-Content - Path $filePath - Force
170
+ dsc config test -f $filePath 2> " $TestDrive /error.txt"
171
+ $LASTEXITCODE | Should - Be 2
172
+
173
+ $cache = Get-Content - Path $cacheFilePath - Raw | ConvertFrom-Json
174
+ $cache.ResourceCache.Type | Should - Contain ' PSTestModule/TestPSRepository'
175
+ $cache.ResourceCache.Type | Should - Contain ' PSDesiredStateConfiguration/File'
176
+ }
177
+
91
178
It ' _inDesiredState is returned correction: <Context>' - Skip:(! $IsWindows ) - TestCases @ (
92
179
@ { Context = ' Both running' ; FirstState = ' Running' ; SecondState = ' Running' }
93
180
@ { Context = ' Both stopped' ; FirstState = ' Stopped' ; SecondState = ' Stopped' }
0 commit comments