@@ -25,67 +25,67 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
2525 }
2626 }
2727
28- It ' Windows PowerShell adapter supports File resource' - Skip:(! $IsWindows ){
29-
30- $r = dsc resource list -- adapter Microsoft.Windows/ WindowsPowerShell
31- $LASTEXITCODE | Should - Be 0
32- $resources = $r | ConvertFrom-Json
33- ($resources | Where-Object {$_.Type -eq ' PSDesiredStateConfiguration/File' }).Count | Should - Be 1
34- }
35-
36- It ' Get works on Binary "File" resource' - Skip:(! $IsWindows ){
37-
38- $testFile = " $testdrive \test.txt"
39- ' test' | Set-Content - Path $testFile - Force
40- $r = ' {"DestinationPath":"' + $testFile.replace (' \' , ' \\' ) + ' "}' | dsc resource get - r ' PSDesiredStateConfiguration/File' -f -
41- $LASTEXITCODE | Should - Be 0
42- $res = $r | ConvertFrom-Json
43- $res.actualState.DestinationPath | Should - Be " $testFile "
44- }
45-
46- It ' Set works on Binary "File" resource' - Skip:(! $IsWindows ){
47-
48- $testFile = " $testdrive \test.txt"
49- $null = ' {"DestinationPath":"' + $testFile.replace (' \' , ' \\' ) + ' ", type: File, contents: HelloWorld, Ensure: present}' | dsc resource set - r ' PSDesiredStateConfiguration/File' -f -
50- $LASTEXITCODE | Should - Be 0
51- Get-Content - Raw - Path $testFile | Should - Be " HelloWorld"
52- }
53-
54- It ' Get works on traditional "Script" resource' - Skip:(! $IsWindows ){
55-
56- $testFile = " $testdrive \test.txt"
57- ' test' | Set-Content - Path $testFile - Force
58- $r = ' {"GetScript": "@{result = $(Get-Content ' + $testFile.replace (' \' , ' \\' ) + ' )}", "SetScript": "throw", "TestScript": "throw"}' | dsc resource get - r ' PSDesiredStateConfiguration/Script' -f -
59- $LASTEXITCODE | Should - Be 0
60- $res = $r | ConvertFrom-Json
61- $res.actualState.result | Should - Be ' test'
62- }
63-
64- It ' Get works on config with File resource for WinPS' - Skip:(! $IsWindows ){
65-
66- $testFile = " $testdrive \test.txt"
67- ' test' | Set-Content - Path $testFile - Force
68- $r = (Get-Content - Raw $winpsConfigPath ).Replace(' c:\test.txt' , " $testFile " ) | dsc config get -f -
69- $LASTEXITCODE | Should - Be 0
70- $res = $r | ConvertFrom-Json
71- $res.results [0 ].result.actualState.result[0 ].properties.DestinationPath | Should - Be " $testFile "
72- }
73-
74- It ' Verify that there are no cache rebuilds for several sequential executions' - Skip:(! $IsWindows ) {
75- # remove cache file
76- $cacheFilePath = Join-Path $env: LocalAppData " dsc\WindowsPSAdapterCache.json"
77- Remove-Item - Force - Path $cacheFilePath - ErrorAction Ignore
78-
79- # first execution should build the cache
80- dsc - l trace resource list - a Microsoft.Windows/ WindowsPowerShell 2> $TestDrive / tracing.txt
81- " $TestDrive /tracing.txt" | Should - FileContentMatchExactly ' Constructing Get-DscResource cache'
82-
83- # next executions following shortly after should Not rebuild the cache
84- 1 .. 3 | ForEach-Object {
85- dsc - l trace resource list - a Microsoft.Windows/ WindowsPowerShell 2> $TestDrive / tracing.txt
86- " $TestDrive /tracing.txt" | Should -Not - FileContentMatchExactly ' Constructing Get-DscResource cache'
87- }
88- }
28+ # It 'Windows PowerShell adapter supports File resource' -Skip:(!$IsWindows){
29+
30+ # $r = dsc resource list --adapter Microsoft.Windows/WindowsPowerShell
31+ # $LASTEXITCODE | Should -Be 0
32+ # $resources = $r | ConvertFrom-Json
33+ # ($resources | Where-Object {$_.Type -eq 'PSDesiredStateConfiguration/File'}).Count | Should -Be 1
34+ # }
35+
36+ # It 'Get works on Binary "File" resource' -Skip:(!$IsWindows){
37+
38+ # $testFile = "$testdrive\test.txt"
39+ # 'test' | Set-Content -Path $testFile -Force
40+ # $r = '{"DestinationPath":"' + $testFile.replace('\','\\') + '"}' | dsc resource get -r 'PSDesiredStateConfiguration/File' -f -
41+ # $LASTEXITCODE | Should -Be 0
42+ # $res = $r | ConvertFrom-Json
43+ # $res.actualState.DestinationPath | Should -Be "$testFile"
44+ # }
45+
46+ # It 'Set works on Binary "File" resource' -Skip:(!$IsWindows){
47+
48+ # $testFile = "$testdrive\test.txt"
49+ # $null = '{"DestinationPath":"' + $testFile.replace('\','\\') + '", type: File, contents: HelloWorld, Ensure: present}' | dsc resource set -r 'PSDesiredStateConfiguration/File' -f -
50+ # $LASTEXITCODE | Should -Be 0
51+ # Get-Content -Raw -Path $testFile | Should -Be "HelloWorld"
52+ # }
53+
54+ # It 'Get works on traditional "Script" resource' -Skip:(!$IsWindows){
55+
56+ # $testFile = "$testdrive\test.txt"
57+ # 'test' | Set-Content -Path $testFile -Force
58+ # $r = '{"GetScript": "@{result = $(Get-Content ' + $testFile.replace('\','\\') + ')}", "SetScript": "throw", "TestScript": "throw"}' | dsc resource get -r 'PSDesiredStateConfiguration/Script' -f -
59+ # $LASTEXITCODE | Should -Be 0
60+ # $res = $r | ConvertFrom-Json
61+ # $res.actualState.result | Should -Be 'test'
62+ # }
63+
64+ # It 'Get works on config with File resource for WinPS' -Skip:(!$IsWindows){
65+
66+ # $testFile = "$testdrive\test.txt"
67+ # 'test' | Set-Content -Path $testFile -Force
68+ # $r = (Get-Content -Raw $winpsConfigPath).Replace('c:\test.txt',"$testFile") | dsc config get -f -
69+ # $LASTEXITCODE | Should -Be 0
70+ # $res = $r | ConvertFrom-Json
71+ # $res.results[0].result.actualState.result[0].properties.DestinationPath | Should -Be "$testFile"
72+ # }
73+
74+ # It 'Verify that there are no cache rebuilds for several sequential executions' -Skip:(!$IsWindows) {
75+ # # remove cache file
76+ # $cacheFilePath = Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json"
77+ # Remove-Item -Force -Path $cacheFilePath -ErrorAction Ignore
78+
79+ # # first execution should build the cache
80+ # dsc -l trace resource list -a Microsoft.Windows/WindowsPowerShell 2> $TestDrive/tracing.txt
81+ # "$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Constructing Get-DscResource cache'
82+
83+ # # next executions following shortly after should Not rebuild the cache
84+ # 1..3 | ForEach-Object {
85+ # dsc -l trace resource list -a Microsoft.Windows/WindowsPowerShell 2> $TestDrive/tracing.txt
86+ # "$TestDrive/tracing.txt" | Should -Not -FileContentMatchExactly 'Constructing Get-DscResource cache'
87+ # }
88+ # }
8989
9090 It ' Verify if assertion is used that no module is cleared in the cache' - Skip:(! $IsWindows ) {
9191 # create a test file in the test drive
@@ -168,7 +168,7 @@ resources:
168168 $filePath = " $testdrive \test.assertion.dsc.resource.yaml"
169169 $yaml | Set-Content - Path $filePath - Force
170170 dsc config test -f $filePath 2> " $TestDrive /error.txt"
171- $LASTEXITCODE | Should - Be 1
171+ $LASTEXITCODE | Should - Be 2
172172
173173 $cache = Get-Content - Path $cacheFilePath - Raw | ConvertFrom-Json
174174 $cache.ResourceCache.Type | Should - Contain ' PSTestModule/TestPSRepository'
0 commit comments