Skip to content

Commit 7695c1f

Browse files
author
Andrew
committed
Added tests
1 parent 093132e commit 7695c1f

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

dsc/tests/dsc_args.tests.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,85 @@ resources:
215215
$err.Length | Should -Not -Be 0
216216
$LASTEXITCODE | Should -Be 4
217217
}
218+
219+
It 'verify `dsc resource list` and `dsc resource list *`' {
220+
# return all native resources, providers, but not provider-based resources;
221+
# results for `dsc resource list` and `dsc resource list *` should be the same
222+
$a = dsc resource list -f json
223+
$b = dsc resource list * -f json
224+
$a.Count | Should -Be $b.Count
225+
0..($a.Count-1) | %{
226+
$a_obj = $a[$_] | ConvertFrom-Json
227+
$b_obj = $b[$_] | ConvertFrom-Json
228+
$a_obj.type | Should -Be $b_obj.type
229+
# adapter-based resources should Not be in the results
230+
$a_obj.requireAdapter | Should -BeNullOrEmpty
231+
$b_obj.requireAdapter | Should -BeNullOrEmpty
232+
}
233+
}
234+
235+
It 'verify `dsc resource list resource_filter`' {
236+
# same as previous but also apply resource_filter filter
237+
$a = dsc resource list Test* -f json
238+
0..($a.Count-1) | %{
239+
$a_obj = $a[$_] | ConvertFrom-Json
240+
$a_obj.type.StartsWith("Test") | Should -Be $true
241+
# adapter-based resources should Not be in the results
242+
$a_obj.requireAdapter | Should -BeNullOrEmpty
243+
}
244+
}
245+
246+
It 'verify `dsc resource list * *`' {
247+
# everything should be in the results: all native resources, providers, and provider-based resources
248+
$a = dsc resource list * * -f json
249+
$resourceKindFound = $false
250+
$groupKindFound = $false
251+
$adapterKindFound = $false
252+
253+
$adapterBasedResourceFound = $false
254+
255+
0..($a.Count-1) | %{
256+
$a_obj = $a[$_] | ConvertFrom-Json
257+
if ($a_obj.kind -eq "Resource") {
258+
$resourceKindFound = $true
259+
} elseif ($a_obj.kind -eq "Group") {
260+
$groupKindFound = $true
261+
} elseif ($a_obj.kind -eq "Adapter") {
262+
$adapterKindFound = $true
263+
}
264+
265+
if ($a_obj.requireAdapter) {
266+
$adapterBasedResourceFound = $true
267+
}
268+
269+
# break loop early if one of each is found
270+
if ($resourceKindFound -and $groupKindFound -and $adapterKindFound -and $adapterBasedResourceFound)
271+
{
272+
break
273+
}
274+
}
275+
276+
$resourceKindFound | Should -Be $true
277+
$groupKindFound | Should -Be $true
278+
$adapterKindFound | Should -Be $true
279+
$adapterBasedResourceFound | Should -Be $true
280+
}
281+
282+
It 'verify `dsc resource list * adapter_filter`' {
283+
# return all native resources, providers, and all resources of providers that match adapter_filter filter
284+
$a = dsc resource list * Test* -f json | ConvertFrom-Json
285+
$adapterBasedResources = $a | ? {$_.requireAdapter}
286+
foreach ($r in $adapterBasedResources) {
287+
$r.requireAdapter.StartsWith("Test") | Should -Be $true
288+
}
289+
}
290+
291+
It 'verify `dsc resource list resource_filter adapter_filter`' {
292+
# same as previous but also apply resource_filter filter to resource types
293+
$a = dsc resource list *TestResource2 *TestGroup -f json | ConvertFrom-Json
294+
$a.Count | Should -Be 1
295+
$r = $a[0]
296+
$r.requireAdapter | Should -Not -BeNullOrEmpty
297+
$r.requireAdapter.StartsWith("Test") | Should -Be $true
298+
}
218299
}

0 commit comments

Comments
 (0)