Skip to content

Commit 4ec26df

Browse files
authored
Merge pull request #1398 from SteveL-MSFT/deprecate-psadapter
Enable deprecation of resources and extensions
2 parents d5e6b96 + 9fd644f commit 4ec26df

26 files changed

Lines changed: 375 additions & 29 deletions

adapters/powershell/Tests/powershellgroup.config.tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ Describe 'PowerShell adapter resource tests' {
293293
if ($metadata -eq 'Microsoft.DSC') {
294294
"$TestDrive/tracing.txt" | Should -FileContentMatch "Invoking $Operation for '$adapter'" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)
295295
}
296+
if ($adapter -eq 'Microsoft.DSC/PowerShell') {
297+
(Get-Content -Raw -Path $TestDrive/tracing.txt) | Should -Match "Resource 'Microsoft.DSC/PowerShell' is deprecated" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)
298+
}
296299
}
297300

298301
It 'Config works with credential object' {

adapters/powershell/Tests/powershellgroup.resource.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Describe 'PowerShell adapter resource tests' {
368368
It 'Specifying a non-existent version returns an error' {
369369
$null = dsc resource get -r TestClassResource/TestClassResource --version 0.0.2 2> $TestDrive/error.log
370370
$LASTEXITCODE | Should -Be 7
371-
Get-Content -Path $TestDrive/error.log | Should -Match 'Resource not found: TestClassResource/TestClassResource 0.0.2'
371+
(Get-Content -Raw -Path $TestDrive/error.log) | Should -BeLike '*Resource not found: TestClassResource/TestClassResource 0.0.2*' -Because (Get-Content -Raw -Path $TestDrive/error.log)
372372
}
373373

374374
It 'Can process SecureString property' {

adapters/powershell/Tests/win_powershellgroup.tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ resources:
279279
}
280280
if ($metadata -eq 'Microsoft.DSC') {
281281
"$TestDrive/tracing.txt" | Should -FileContentMatch "Invoking $Operation for '$adapter'" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)
282-
282+
}
283+
if ($adapter -eq 'Microsoft.Windows/WindowsPowerShell') {
284+
(Get-Content -Raw -Path $TestDrive/tracing.txt) | Should -Match "Resource 'Microsoft.Windows/WindowsPowerShell' is deprecated" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)
283285
}
284286
}
285287
}

adapters/powershell/powershell.dsc.resource.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "Microsoft.DSC/PowerShell",
44
"version": "0.1.0",
55
"kind": "adapter",
6+
"deprecationMessage": "Use the 'Microsoft.Adapters/PowerShell' adapter instead.",
67
"description": "Resource adapter to classic DSC Powershell resources.",
78
"tags": [
89
"PowerShell"

adapters/powershell/windowspowershell.dsc.resource.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "Microsoft.Windows/WindowsPowerShell",
44
"version": "0.1.0",
55
"kind": "adapter",
6+
"deprecationMessage": "Use the 'Microsoft.Adapters/WindowsPowerShell' adapter instead.",
67
"description": "Resource adapter to classic DSC Powershell resources in Windows PowerShell.",
78
"tags": [
89
"PowerShell"

dsc/tests/dsc_adapter.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,18 @@ Describe 'Tests for adapter support' {
227227
}
228228
}
229229
}
230+
231+
It 'Deprecated adapted resource shows message' {
232+
try {
233+
$dscHome = Split-Path (Get-Command dsc).Source -Parent
234+
$env:DSC_RESOURCE_PATH = (Join-Path -Path $dscHome -ChildPath 'deprecated') + [System.IO.Path]::PathSeparator + $dscHome
235+
$out = dsc resource get -r Adapted/Deprecated -i '{}' 2>$TestDrive/error.log | ConvertFrom-Json
236+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log | Out-String)
237+
$out | Should -Not -BeNullOrEmpty
238+
(Get-Content $TestDrive/error.log -Raw) | Should -Match "Resource 'Adapted/Deprecated' is deprecated: This adapted resource is deprecated" -Because (Get-Content $TestDrive/error.log | Out-String)
239+
} finally {
240+
$env:DSC_RESOURCE_PATH = $null
241+
}
242+
}
230243
}
231244
}

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,17 @@ Describe 'Discover extension tests' {
135135
$env:PATH = $oldPath
136136
}
137137
}
138+
139+
It 'Deprecated extension shows message' {
140+
try {
141+
$dscHome = Split-Path (Get-Command dsc).Source -Parent
142+
$env:DSC_RESOURCE_PATH = (Join-Path -Path $dscHome -ChildPath 'deprecated') + [System.IO.Path]::PathSeparator + $dscHome
143+
144+
$null = dsc resource list 2> $TestDrive/error.log
145+
$LASTEXITCODE | Should -Be 0
146+
(Get-Content -Path "$TestDrive/error.log" -Raw) | Should -Match "Extension 'Test/ExtensionDeprecated' is deprecated: This extension is deprecated" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String)
147+
} finally {
148+
$env:DSC_RESOURCE_PATH = $null
149+
}
150+
}
138151
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'Import extension tests' {
5+
It 'Deprecated extension shows message' {
6+
try {
7+
$dscHome = Split-Path (Get-Command dsc).Source -Parent
8+
$env:DSC_RESOURCE_PATH = (Join-Path -Path $dscHome -ChildPath 'deprecated') + [System.IO.Path]::PathSeparator + $dscHome
9+
10+
Set-Content -Path "$TestDrive/test.testimport" -Value 'Test content'
11+
$null = dsc config get -f "$TestDrive/test.testimport" 2> $TestDrive/error.log | ConvertFrom-Json
12+
$LASTEXITCODE | Should -Be 2 -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String)
13+
(Get-Content -Path "$TestDrive/error.log" -Raw) | Should -Match "Extension 'Test/ExtensionDeprecated' is deprecated: This extension is deprecated" -Because (Get-Content -Path "$TestDrive/error.log" -Raw | Out-String)
14+
} finally {
15+
$env:DSC_RESOURCE_PATH = $null
16+
}
17+
}
18+
}

dsc/tests/dsc_extension_secret.tests.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,27 @@ Describe 'Tests for the secret() function and extensions' {
168168
$out.results.Count | Should -Be 1
169169
$out.results[0].result.actualState.Output | Should -BeExactly 'Hello'
170170
}
171+
172+
It 'Deprecated extension shows message' {
173+
try {
174+
$dscHome = Split-Path (Get-Command dsc).Source -Parent
175+
$env:DSC_RESOURCE_PATH = (Join-Path -Path $dscHome -ChildPath 'deprecated') + [System.IO.Path]::PathSeparator + $dscHome
176+
177+
$configYaml = @'
178+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
179+
variables:
180+
myString: "[secret('nonExisting')]"
181+
resources:
182+
- name: Database Connection
183+
type: Microsoft.DSC.Debug/Echo
184+
properties:
185+
output: "[variables('myString')]"
186+
'@
187+
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json
188+
$LASTEXITCODE | Should -Be 4
189+
(Get-Content -Raw -Path "$TestDrive/error.log") | Should -Match "Extension 'Test/ExtensionDeprecated' is deprecated: This extension is deprecated" -Because (Get-Content -Raw -Path "$TestDrive/error.log")
190+
} finally {
191+
$env:DSC_RESOURCE_PATH = $null
192+
}
193+
}
171194
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'Deprecated resource tests' {
5+
BeforeAll {
6+
$dscHome = Split-Path (Get-Command dsc).Source -Parent
7+
$env:DSC_RESOURCE_PATH = (Join-Path -Path $dscHome -ChildPath 'deprecated') + [System.IO.Path]::PathSeparator + $dscHome
8+
}
9+
10+
AfterAll {
11+
$env:DSC_RESOURCE_PATH = $null
12+
}
13+
14+
It 'Deprecated resource for operation <operation>' -TestCases @(
15+
@{ operation = 'get' }
16+
@{ operation = 'set' }
17+
@{ operation = 'delete' }
18+
@{ operation = 'test' }
19+
@{ operation = 'export' }
20+
) {
21+
param($operation)
22+
23+
$out = dsc resource $operation -r Test/OperationDeprecated -i '{}' 2>$TestDrive/error.log | ConvertFrom-Json
24+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw | Out-String)
25+
if ($operation -eq 'delete') {
26+
$out | Should -BeNullOrEmpty
27+
} else {
28+
$out | Should -Not -BeNullOrEmpty
29+
}
30+
(Get-Content $TestDrive/error.log -Raw) | Should -Match "Resource 'Test/OperationDeprecated' is deprecated: This resource is deprecated"
31+
}
32+
33+
It 'Deprecated resource for schema' {
34+
$out = dsc resource schema -r Test/OperationDeprecated 2>$TestDrive/error.log | ConvertFrom-Json
35+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw | Out-String)
36+
$out | Should -Not -BeNullOrEmpty
37+
(Get-Content $TestDrive/error.log -Raw) | Should -Match "Resource 'Test/OperationDeprecated' is deprecated: This resource is deprecated"
38+
}
39+
40+
It 'Deprecated message when used in config' {
41+
$configYaml = @'
42+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
43+
resources:
44+
- name: test
45+
type: Test/OperationDeprecated
46+
properties:
47+
operation: get
48+
'@
49+
50+
$out = dsc config get -i $configYaml 2>$TestDrive/error.log | ConvertFrom-Json
51+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw | Out-String)
52+
$out.results.count | Should -Be 1
53+
$out.results[0].type | Should -BeExactly 'Test/OperationDeprecated'
54+
(Get-Content $TestDrive/error.log -Raw) | Should -Match "Resource 'Test/OperationDeprecated' is deprecated: This resource is deprecated"
55+
}
56+
}

0 commit comments

Comments
 (0)