|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +Describe 'metadata tests' { |
| 5 | + It 'resource can provide metadata for <operation>' -TestCases @( |
| 6 | + @{ operation = 'get' } |
| 7 | + @{ operation = 'set' } |
| 8 | + @{ operation = 'test' } |
| 9 | + ) { |
| 10 | + param($operation) |
| 11 | + |
| 12 | + $configYaml = @' |
| 13 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 14 | + resources: |
| 15 | + - name: test |
| 16 | + type: Test/Metadata |
| 17 | + properties: |
| 18 | + _metadata: |
| 19 | + hello: world |
| 20 | + myNumber: 42 |
| 21 | +'@ |
| 22 | + |
| 23 | + $out = dsc config $operation -i $configYaml 2>$TestDrive/error.log | ConvertFrom-Json |
| 24 | + $LASTEXITCODE | Should -Be 0 |
| 25 | + $out.results.count | Should -Be 1 |
| 26 | + $out.results[0].metadata.hello | Should -BeExactly 'world' |
| 27 | + $out.results[0].metadata.myNumber | Should -Be 42 |
| 28 | + } |
| 29 | + |
| 30 | + It 'resource can provide metadata for export' { |
| 31 | + $configYaml = @' |
| 32 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 33 | + resources: |
| 34 | + - name: test |
| 35 | + type: Test/Metadata |
| 36 | + properties: |
| 37 | + _metadata: |
| 38 | + hello: There |
| 39 | + myNumber: 16 |
| 40 | +'@ |
| 41 | + $out = dsc config export -i $configYaml 2>$TestDrive/error.log | ConvertFrom-Json |
| 42 | + $LASTEXITCODE | Should -Be 0 |
| 43 | + $out.resources.count | Should -Be 3 |
| 44 | + $out.resources[0].metadata.hello | Should -BeExactly 'There' |
| 45 | + $out.resources[0].metadata.myNumber | Should -Be 16 |
| 46 | + $out.resources[0].name | Should -BeExactly 'Metadata example 1' |
| 47 | + $out.resources[1].metadata.hello | Should -BeExactly 'There' |
| 48 | + $out.resources[1].metadata.myNumber | Should -Be 16 |
| 49 | + $out.resources[1].name | Should -BeExactly 'Metadata example 2' |
| 50 | + $out.resources[2].metadata.hello | Should -BeExactly 'There' |
| 51 | + $out.resources[2].metadata.myNumber | Should -Be 16 |
| 52 | + $out.resources[2].name | Should -BeExactly 'Metadata example 3' |
| 53 | + } |
| 54 | + |
| 55 | + It 'resource returning Microsoft.DSC metadata is ignored' { |
| 56 | + $configYaml = @' |
| 57 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 58 | + resources: |
| 59 | + - name: test |
| 60 | + type: Test/Metadata |
| 61 | + properties: |
| 62 | + _metadata: |
| 63 | + Microsoft.DSC: |
| 64 | + hello: world |
| 65 | + validOne: true |
| 66 | +'@ |
| 67 | + $out = dsc config get -i $configYaml 2>$TestDrive/error.log | ConvertFrom-Json |
| 68 | + $LASTEXITCODE | Should -Be 0 |
| 69 | + $out.results.count | Should -Be 1 |
| 70 | + $out.results[0].metadata.validOne | Should -BeTrue |
| 71 | + $out.results[0].metadata.Microsoft.DSC | Should -BeNullOrEmpty |
| 72 | + (Get-Content $TestDrive/error.log) | Should -BeLike "*WARN*Resource returned '_metadata' property 'Microsoft.DSC' which is ignored*" |
| 73 | + } |
| 74 | +} |
0 commit comments