@@ -6,20 +6,22 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
6
6
BeforeAll {
7
7
if ($isWindows ) {
8
8
winrm quickconfig- quiet- force
9
- }
10
- $OldPSModulePath = $env: PSModulePath
11
- $env: PSModulePath += [System.IO.Path ]::PathSeparator+ $PSScriptRoot
9
+ $OldPSModulePath = $env: PSModulePath
10
+ $env: PSModulePath += [System.IO.Path ]::PathSeparator+ $PSScriptRoot
12
11
13
- $winpsConfigPath = Join-path $PSScriptRoot " winps_resource.dsc.yaml"
14
- if ($isWindows ) {
15
- $cacheFilePath_v5 = Join-Path $env: LocalAppData " dsc" " WindowsPSAdapterCache.json"
12
+ $winpsConfigPath = Join-path $PSScriptRoot " winps_resource.dsc.yaml"
13
+ if ($isWindows ) {
14
+ $cacheFilePath_v5 = Join-Path $env: LocalAppData " dsc" " WindowsPSAdapterCache.json"
15
+ }
16
16
}
17
17
}
18
18
AfterAll {
19
- $env: PSModulePath = $OldPSModulePath
19
+ if ($isWindows ) {
20
+ $env: PSModulePath = $OldPSModulePath
20
21
21
- # Remove after all the tests are done
22
- Remove-Module $script :winPSModule - Force- ErrorAction Ignore
22
+ # Remove after all the tests are done
23
+ Remove-Module $script :winPSModule - Force- ErrorAction Ignore
24
+ }
23
25
}
24
26
25
27
BeforeEach {
@@ -161,7 +163,7 @@ resources:
161
163
- "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
162
164
- name: TestPSRepository
163
165
type: PSTestModule/TestPSRepository
164
- properties:
166
+ properties:
165
167
Name: NuGet
166
168
dependsOn:
167
169
- "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
@@ -201,7 +203,7 @@ resources:
201
203
type: PsDesiredStateConfiguration/Service
202
204
properties:
203
205
Name: Spooler
204
- State:$SecondState
206
+ State:$SecondState
205
207
"@
206
208
207
209
$inDesiredState = if ($FirstState -eq $SecondState ) {
@@ -242,11 +244,11 @@ resources:
242
244
# Instead of calling dsc.exe we call the cmdlet directly to be able to test the output and mocks
243
245
$resourceObject = Get-DscResourceObject - jsonInput$jsonInput
244
246
$cacheEntry = Invoke-DscCacheRefresh - Module PSDesiredStateConfiguration
245
-
247
+
246
248
$out = Invoke-DscOperation - Operation Test- DesiredState$resourceObject - dscResourceCache$cacheEntry
247
249
$LASTEXITCODE | Should- Be0
248
250
$out.properties.InDesiredState.InDesiredState | Should- Be$false
249
-
251
+
250
252
Should- Invoke- CommandNameConvertTo-SecureString - Exactly- Times1 - Scope It
251
253
}
252
254
@@ -261,7 +263,7 @@ resources:
261
263
Credential:
262
264
UserName: 'User'
263
265
OtherProperty: 'Password'
264
- "@
266
+ "@
265
267
# Compared to PowerShell we use test here as it filters out the properties
266
268
$out = dsc config test- i$yaml 2>&1 | Out-String
267
269
$LASTEXITCODE | Should- Be2
@@ -339,7 +341,7 @@ class PSClassResource {
339
341
}
340
342
341
343
[void] Set() {
342
-
344
+
343
345
}
344
346
345
347
static [PSClassResource[]] Export()
@@ -374,23 +376,23 @@ class PSClassResource {
374
376
}
375
377
376
378
It' Get works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
377
-
379
+
378
380
$out = dsc resource get- r PSClassResource/ PSClassResource-- input (@ {Name = ' TestName' }| ConvertTo-Json )| ConvertFrom-Json
379
381
$LASTEXITCODE | Should- Be0
380
382
$out.actualState.Name | Should- Be' TestName'
381
- $propCount = $out.actualState | Get-Member - MemberType NoteProperty
383
+ $propCount = $out.actualState | Get-Member - MemberType NoteProperty
382
384
$propCount.Count | Should- Be1 # Only the DscProperty should be returned
383
385
}
384
386
385
387
It' Set works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
386
-
388
+
387
389
$out = dsc resource set- r PSClassResource/ PSClassResource-- input (@ {Name = ' TestName' }| ConvertTo-Json )| ConvertFrom-Json
388
390
$LASTEXITCODE | Should- Be0
389
391
$out.afterstate.InDesiredState | Should- Be$true
390
392
}
391
393
392
394
It' Export works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
393
-
395
+
394
396
$out = dsc resource export- r PSClassResource/ PSClassResource| ConvertFrom-Json
395
397
$LASTEXITCODE | Should- Be0
396
398
$out | Should-Not - BeNullOrEmpty