Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions adapters/powershell/Tests/powershellgroup.config.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,25 @@ Describe 'PowerShell adapter resource tests' {
}

It 'Config calling PS Resource directly works for <operation> with metadata <metadata> and adapter <adapter>' -TestCases @(
@{ Operation = 'get'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'set'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'test'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'get'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'set'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'test'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'get'; metadata = 'Ignored' }
@{ Operation = 'set'; metadata = 'Ignored' }
@{ Operation = 'test'; metadata = 'Ignored' }
@{ Operation = 'get'; directive = 'requireAdapter: '; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'set'; directive = 'requireAdapter: '; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'test'; directive = 'requireAdapter: '; adapter = 'Microsoft.DSC/PowerShell' }
@{ Operation = 'get'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'set'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'test'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/PowerShell' }
@{ Operation = 'get'; directive = '' }
@{ Operation = 'set'; directive = '' }
@{ Operation = 'test'; directive = '' }
) {
param($Operation, $metadata, $adapter)
param($Operation, $directive, $adapter)

$yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Class-resource Info
type: TestClassResource/TestClassResource
metadata:
${metadata}:
requireAdapter: $adapter
directives:
$directive$adapter
properties:
Name: 'TestClassResource1'
HashTableProp:
Expand All @@ -290,7 +289,7 @@ Describe 'PowerShell adapter resource tests' {
$out.results[0].result.inDesiredState | Should -BeFalse -Because $text
}
}
if ($metadata -eq 'Microsoft.DSC') {
if ($directive -eq 'requireAdapter: ') {
"$TestDrive/tracing.txt" | Should -FileContentMatch "Invoking $Operation for '$adapter'" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)
}
}
Expand Down
27 changes: 13 additions & 14 deletions adapters/powershell/Tests/win_powershellgroup.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,25 @@ resources:
}

It 'Config calling PS Resource directly works for <operation> with metadata <metadata> and adapter <adapter>' -TestCases @(
@{ Operation = 'get'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'set'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'test'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'get'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'set'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'test'; metadata = 'Microsoft.DSC'; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'get'; metadata = 'Ignored' }
@{ Operation = 'set'; metadata = 'Ignored' }
@{ Operation = 'test'; metadata = 'Ignored' }
@{ Operation = 'get'; directive = 'requireAdapter: '; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'set'; directive = 'requireAdapter: '; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'test'; directive = 'requireAdapter: '; adapter = 'Microsoft.Windows/WindowsPowerShell' }
@{ Operation = 'get'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'set'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'test'; directive = 'requireAdapter: '; adapter = 'Microsoft.Adapter/WindowsPowerShell' }
@{ Operation = 'get'; directive = ''; adapter = '' }
@{ Operation = 'set'; directive = ''; adapter = '' }
@{ Operation = 'test'; directive = ''; adapter = '' }
) {
param($Operation, $metadata, $adapter)
param($Operation, $directive, $adapter)

$yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Class-resource Info
type: PSClassResource/PSClassResource
metadata:
${metadata}:
requireAdapter: $adapter
directives:
$directive$adapter
properties:
Name: TestInstance
Credential:
Expand All @@ -277,7 +276,7 @@ resources:
$out.results[0].result.inDesiredState | Should -BeTrue -Because $text
}
}
if ($metadata -eq 'Microsoft.DSC') {
if ($directive -eq 'requireAdapter: ') {
"$TestDrive/tracing.txt" | Should -FileContentMatch "Invoking $Operation for '$adapter'" -Because (Get-Content -Raw -Path $TestDrive/tracing.txt)

}
Expand Down
5 changes: 2 additions & 3 deletions dsc/examples/require_admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# note that the resource doesn't require admin, but this will fail to even try to run the
# config if the user is not root or elevated as administrator
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
metadata:
Microsoft.DSC:
securityContext: elevated
directives:
securityContext: elevated
resources:
- name: os
type: Microsoft/OSInfo
Expand Down
5 changes: 2 additions & 3 deletions dsc/examples/require_nonadmin.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# example showing use of specific metadata to indicate this config requires admin to run
# this will fail to even try to run the config if the user is root or elevated as administrator
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
metadata:
Microsoft.DSC:
securityContext: restricted
directives:
securityContext: restricted
resources:
- name: os
type: Microsoft/OSInfo
Expand Down
15 changes: 6 additions & 9 deletions dsc/tests/dsc_adapter.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ Describe 'Tests for adapter support' {
type: Test/Invalid
properties:
output: '1'
metadata:
Microsoft.DSC:
requireAdapter: InvalidAdapter/Invalid
directives:
requireAdapter: InvalidAdapter/Invalid
"@
$out = dsc config get -i $config_yaml 2>$TestDrive/error.log
$LASTEXITCODE | Should -Be 2 -Because (Get-Content $TestDrive/error.log | Out-String)
Expand All @@ -126,16 +125,14 @@ Describe 'Tests for adapter support' {
type: TestClassResource/TestClassResource
properties:
Name: 'Hello'
metadata:
Microsoft.DSC:
requireAdapter: Microsoft.DSC/PowerShell
directives:
requireAdapter: Microsoft.DSC/PowerShell
- name: Test2
type: TestClassResource/TestClassResource
properties:
Name: 'Bye'
metadata:
Microsoft.DSC:
requireAdapter: Microsoft.Adapter/PowerShell
directives:
requireAdapter: Microsoft.Adapter/PowerShell
'@
$out = dsc -l trace config get -i $config_yaml 2>$TestDrive/error.log | ConvertFrom-Json -Depth 10
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log | Out-String)
Expand Down
17 changes: 8 additions & 9 deletions dsc/tests/dsc_discovery.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,20 @@ Describe 'tests for resource discovery' {
}
}

It 'Resource discovery can be set to <mode>' -TestCases @(
@{ namespace = 'Microsoft.DSC'; mode = 'preDeployment' }
@{ namespace = 'Microsoft.DSC'; mode = 'duringDeployment' }
@{ namespace = 'Ignore'; mode = 'ignore' }
It 'Resource discovery directive can be set to <mode>' -TestCases @(
@{ mode = 'resourceDiscovery: preDeployment' }
@{ mode = 'resourceDiscovery: duringDeployment' }
@{ mode = '' }
) {
param($namespace, $mode)
param($mode)

$guid = (New-Guid).Guid.Replace('-', '')
$manifestPath = Join-Path (Split-Path (Get-Command dscecho -ErrorAction Stop).Source -Parent) echo.dsc.resource.json

$config_yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/manifest.json
metadata:
${namespace}:
resourceDiscovery: $mode
directives:
$mode
resources:
- type: Test/CopyResource
name: This should be found and executed
Expand All @@ -329,7 +328,7 @@ Describe 'tests for resource discovery' {
"@
$out = dsc -l trace config get -i $config_yaml 2> "$testdrive/tracing.txt"
$traceLog = Get-Content -Raw -Path "$testdrive/tracing.txt"
if ($mode -ne 'duringDeployment') {
if ($mode -notlike '*duringDeployment') {
$LASTEXITCODE | Should -Be 2
$out | Should -BeNullOrEmpty
$traceLog | Should -Match "ERROR.*?Resource not found: Test/$guid"
Expand Down
38 changes: 30 additions & 8 deletions dsc/tests/dsc_group.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Describe 'Group resource tests' {
$out = (dsc config get -f $PSScriptRoot/../examples/groups.dsc.yaml -o yaml | Out-String).Trim()
$LASTEXITCODE | Should -Be 0
$out | Should -BeLike @'
executionInformation:
duration: PT*S
endDatetime: *
executionType: actual
operation: get
securityContext: *
startDatetime: *
version: 3*
metadata:
Microsoft.DSC:
duration: PT*S
Expand All @@ -16,49 +24,63 @@ metadata:
startDatetime: *
version: 3*
results:
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: First Group
type: Microsoft.DSC/Group
result:
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: First
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: First
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: Nested Group
type: Microsoft.DSC/Group
result:
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: Nested First
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: Nested First
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: Nested Second
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: Nested Second
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: Last Group
type: Microsoft.DSC/Group
result:
- metadata:
- executionInformation:
duration: *
metadata:
Microsoft.DSC:
duration: *
name: Last
Expand All @@ -68,7 +90,7 @@ results:
output: Last
messages: `[`]
hadErrors: false
'@
'@ -Because $out
}

}
16 changes: 16 additions & 0 deletions dsc/tests/dsc_metadata.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ Describe 'metadata tests' {
$out.metadata.'Microsoft.DSC'.restartRequired[3].process.id | Should -Be 1234
$out.metadata.'Microsoft.DSC'.restartRequired[4].process.name | Should -BeExactly 'anotherProcess'
$out.metadata.'Microsoft.DSC'.restartRequired[4].process.id | Should -Be 5678
$out.results[0].executionInformation.restartRequired.count | Should -Be 2
$out.results[0].executionInformation.restartRequired[0].system | Should -BeExactly 'mySystem'
$out.results[0].executionInformation.restartRequired[1].service | Should -BeExactly 'myService'
$out.results[1].executionInformation.restartRequired.count | Should -Be 1
$out.results[1].executionInformation.restartRequired[0].service | Should -BeExactly 'sshd'
$out.results[2].executionInformation.restartRequired.count | Should -Be 2
$out.results[2].executionInformation.restartRequired[0].process.name | Should -BeExactly 'myProcess'
$out.results[2].executionInformation.restartRequired[0].process.id | Should -Be 1234
$out.executionInformation.restartRequired.count | Should -Be 5
$out.executionInformation.restartRequired[0].system | Should -BeExactly 'mySystem'
$out.executionInformation.restartRequired[1].service | Should -BeExactly 'myService'
$out.executionInformation.restartRequired[2].service | Should -BeExactly 'sshd'
$out.executionInformation.restartRequired[3].process.name | Should -BeExactly 'myProcess'
$out.executionInformation.restartRequired[3].process.id | Should -Be 1234
$out.executionInformation.restartRequired[4].process.name | Should -BeExactly 'anotherProcess'
$out.executionInformation.restartRequired[4].process.id | Should -Be 5678
}

It 'invalid item in _restartRequired metadata is a warning' {
Expand Down
Loading