Skip to content

Commit 650c34c

Browse files
author
Andrew
committed
added tests for adapter lookup table
1 parent 17c38ba commit 650c34c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

dsc/tests/dsc_discovery.tests.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,56 @@ Describe 'tests for resource discovery' {
9696
$env:DSC_RESOURCE_PATH = $oldPath
9797
}
9898
}
99+
100+
It 'Ensure List operation populates adapter lookup table' {
101+
$lookupTableFilePath = if ($IsWindows) {
102+
Join-Path $env:LocalAppData "dsc\AdaptedResourcesLookupTable.json"
103+
} else {
104+
Join-Path $env:HOME ".dsc" "AdaptedResourcesLookupTable.json"
105+
}
106+
107+
# remove adapter lookup table file
108+
Remove-Item -Force -Path $lookupTableFilePath -ErrorAction SilentlyContinue
109+
Test-Path $lookupTableFilePath -PathType Leaf | Should -BeFalse
110+
111+
# perform List on an adapter - this should create adapter lookup table file
112+
dsc resource list -a Microsoft.DSC/PowerShell | Out-Null
113+
114+
Test-Path $lookupTableFilePath -PathType Leaf | Should -BeTrue
115+
}
116+
117+
It 'Ensure non-List operation populates adapter lookup table' {
118+
$lookupTableFilePath = if ($IsWindows) {
119+
Join-Path $env:LocalAppData "dsc\AdaptedResourcesLookupTable.json"
120+
} else {
121+
Join-Path $env:HOME ".dsc" "AdaptedResourcesLookupTable.json"
122+
}
123+
124+
# remove adapter lookup table file
125+
Remove-Item -Force -Path $lookupTableFilePath -ErrorAction SilentlyContinue
126+
Test-Path $lookupTableFilePath -PathType Leaf | Should -BeFalse
127+
128+
# perform Get on an adapter - this should create adapter lookup table file
129+
$oldPSModulePath = $env:PSModulePath
130+
$TestClassResourcePath = Resolve-Path "$PSScriptRoot/../../powershell-adapter/Tests"
131+
$env:DSC_RESOURCE_PATH = $null
132+
$env:PSModulePath += [System.IO.Path]::PathSeparator + $TestClassResourcePath
133+
"{'Name':'TestClassResource1'}" | dsc resource get -r 'TestClassResource/TestClassResource' | Out-Null
134+
135+
Test-Path $lookupTableFilePath -PathType Leaf | Should -BeTrue
136+
$env:PSModulePath = $oldPSModulePath
137+
}
138+
139+
It 'Verify adapter lookup table is used on repeat invocations' {
140+
141+
$oldPSModulePath = $env:PSModulePath
142+
$TestClassResourcePath = Resolve-Path "$PSScriptRoot/../../powershell-adapter/Tests"
143+
$env:DSC_RESOURCE_PATH = $null
144+
$env:PSModulePath += [System.IO.Path]::PathSeparator + $TestClassResourcePath
145+
dsc resource list -a Microsoft.DSC/PowerShell | Out-Null
146+
"{'Name':'TestClassResource1'}" | dsc -l trace resource get -r 'TestClassResource/TestClassResource' 2> $TestDrive/tracing.txt
147+
148+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Lookup table found resource 'testclassresource/testclassresource' in adapter 'Microsoft.DSC/PowerShell'"
149+
$env:PSModulePath = $oldPSModulePath
150+
}
99151
}

0 commit comments

Comments
 (0)