Skip to content

Commit 99bfd3e

Browse files
G.ReijnG.Reijn
G.Reijn
authored and
G.Reijn
committed
Undo changes
1 parent e69fcfa commit 99bfd3e

File tree

2 files changed

+101
-101
lines changed

2 files changed

+101
-101
lines changed

.vscode/launch.json

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
// {
2-
// // Use IntelliSense to learn about possible attributes.
3-
// // Hover to view descriptions of existing attributes.
4-
// // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
// "version": "0.2.0",
6-
// "configurations": [
7-
// {
8-
// "type": "lldb",
9-
// "request": "launch",
10-
// "name": "Debug config",
11-
// "program": "${workspaceFolder}/config/target/debug/config",
12-
// "args": [
13-
// "list",
14-
// "r*"
15-
// ],
16-
// "cwd": "${workspaceFolder}"
17-
// },
18-
// {
19-
// "name": "(macOS) Attach",
20-
// "type": "lldb",
21-
// "request": "attach",
22-
// "pid": "${command:pickMyProcess}",
23-
// },
24-
// {
25-
// "name": "(Windows) Attach",
26-
// "type": "cppvsdbg",
27-
// "request": "attach",
28-
// "processId": "${command:pickProcess}",
29-
// },
30-
// {
31-
// "name": "Debug sshdconfig",
32-
// "type": "cppvsdbg",
33-
// "request": "launch",
34-
// "program": "${workspaceFolder}/sshdconfig/target/debug/sshdconfig.exe",
35-
// "args": ["get"],
36-
// "cwd": "${workspaceFolder}"
37-
// }
38-
// ]
39-
// }
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug config",
11+
"program": "${workspaceFolder}/config/target/debug/config",
12+
"args": [
13+
"list",
14+
"r*"
15+
],
16+
"cwd": "${workspaceFolder}"
17+
},
18+
{
19+
"name": "(macOS) Attach",
20+
"type": "lldb",
21+
"request": "attach",
22+
"pid": "${command:pickMyProcess}",
23+
},
24+
{
25+
"name": "(Windows) Attach",
26+
"type": "cppvsdbg",
27+
"request": "attach",
28+
"processId": "${command:pickProcess}",
29+
},
30+
{
31+
"name": "Debug sshdconfig",
32+
"type": "cppvsdbg",
33+
"request": "launch",
34+
"program": "${workspaceFolder}/sshdconfig/target/debug/sshdconfig.exe",
35+
"args": ["get"],
36+
"cwd": "${workspaceFolder}"
37+
}
38+
]
39+
}

powershell-adapter/Tests/win_powershellgroup.tests.ps1

+62-62
Original file line numberDiff line numberDiff line change
@@ -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
@@ -123,7 +123,7 @@ Describe 'WindowsPowerShell adapter resource tests - requires elevated permissio
123123
Set-Content -Path "$testModuleDir\TestModule.psd1" -Value $manifestContent
124124

125125
$scriptContent = @"
126-
Write-Host 'Hello from TestModule!'
126+
Write-Host 'The DSC world!'
127127
"@
128128
Set-Content -Path "$testModuleDir\TestModule.psm1" -Value $scriptContent
129129

0 commit comments

Comments
 (0)