|
| 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