@@ -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,92 @@ 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
+ BeforeAll {
92
+ New-Item - Path " $testdrive \test.txt" - ItemType File - Force | Out-Null
93
+ }
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 'Hello from TestModule!'
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 resource
137
+ type: PSDesiredStateConfiguration/File
138
+ properties:
139
+ DestinationPath: $testdrive \test.txt
140
+ - name: File assertion
141
+ type: Microsoft.DSC/Assertion
142
+ properties:
143
+ `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
144
+ resources:
145
+ - name: File
146
+ type: PSDesiredStateConfiguration/File
147
+ properties:
148
+ DestinationPath: $testdrive \test.txt
149
+ dependsOn:
150
+ - "[resourceId('PSDesiredStateConfiguration/File', 'File resource')]"
151
+ - name: TestPSRepository
152
+ type: DscResources/TestPSRepository
153
+ properties:
154
+ Name: NuGet
155
+ dependsOn:
156
+ - "[resourceId('PSDesiredStateConfiguration/File', 'File resource')]"
157
+ - "[resourceId('Microsoft.DSC/Assertion', 'File assertion')]"
158
+ "@
159
+ $r = dsc config test - i $yaml | ConvertFrom-Json
160
+ $LASTEXITCODE | Should - Be 0
161
+ $r.results [0 ].result.inDesiredState | Should - Be $true
162
+ $cache = Get-Content - Raw - Path $cacheFilePath
163
+ $cache.ResourceCache | Should - Contain @ (' DscResources/TestPSRepository' , ' PSDesiredStateConfiguration/File' )
164
+
165
+
166
+ # Clean up the test module directory
167
+ Remove-Item - Path " $testModuleDir " - Recurse - Force - ErrorAction Ignore
168
+ }
169
+
91
170
It ' _inDesiredState is returned correction: <Context>' - Skip:(! $IsWindows ) - TestCases @ (
92
171
@ { Context = ' Both running' ; FirstState = ' Running' ; SecondState = ' Running' }
93
172
@ { Context = ' Both stopped' ; FirstState = ' Stopped' ; SecondState = ' Stopped' }
0 commit comments