Skip to content

Commit 902bb64

Browse files
G.ReijnG.Reijn
authored andcommitted
Outputting YAML file to path
1 parent 78b362f commit 902bb64

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

powershell-adapter/Tests/win_powershellgroup.tests.ps1

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,47 @@ Write-Host 'Hello from TestModule!'
133133
$yaml = @"
134134
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
135135
resources:
136-
- name: File resource
137-
type: PSDesiredStateConfiguration/File
136+
- name: File
137+
type: Microsoft.Windows/WindowsPowerShell
138138
properties:
139-
DestinationPath: $testdrive\test.txt
140-
- name: File assertion
139+
resources:
140+
- name: File
141+
type: PSDesiredStateConfiguration/File
142+
properties:
143+
DestinationPath: $testdrive\test.txt
144+
- name: File present
141145
type: Microsoft.DSC/Assertion
142146
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
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: $testDrive\test.txt
149157
dependsOn:
150-
- "[resourceId('PSDesiredStateConfiguration/File', 'File resource')]"
158+
- "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
151159
- name: TestPSRepository
152160
type: DscResources/TestPSRepository
153161
properties:
154162
Name: NuGet
155163
dependsOn:
156-
- "[resourceId('PSDesiredStateConfiguration/File', 'File resource')]"
157-
- "[resourceId('Microsoft.DSC/Assertion', 'File assertion')]"
164+
- "[resourceId('Microsoft.Windows/WindowsPowerShell', 'File')]"
165+
- "[resourceId('Microsoft.DSC/Assertion', 'File present')]"
158166
"@
159-
$r = dsc config test -i $yaml | ConvertFrom-Json
167+
# outputting to file because dsc doesn't handle the yaml string correctly when dependsOn is used
168+
$filePath = "$testdrive\test.assertion.dsc.resource.yaml"
169+
$yaml | Set-Content -Path $filePath -Force
170+
$r = dsc config test -f $filePath | ConvertFrom-Json
171+
$r = dsc config test -f "$testdrive\test.assertion.dsc.resource.yaml" | ConvertFrom-Json
160172
$LASTEXITCODE | Should -Be 0
161173
$r.results[0].result.inDesiredState | Should -Be $true
162174
$cache = Get-Content -Raw -Path $cacheFilePath
163175
$cache.ResourceCache | Should -Contain @('DscResources/TestPSRepository', 'PSDesiredStateConfiguration/File')
164176

165-
166177
# Clean up the test module directory
167178
Remove-Item -Path "$testModuleDir" -Recurse -Force -ErrorAction Ignore
168179
}

0 commit comments

Comments
 (0)