-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtestadapter.resource.ps1
More file actions
77 lines (68 loc) · 2.64 KB
/
testadapter.resource.ps1
File metadata and controls
77 lines (68 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Operation to perform. Choose from List, Get, Set, Test, Export, Validate.')]
[ValidateSet('List', 'Get', 'Set', 'Test', 'Export', 'Validate')]
[string]$Operation,
[Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true, HelpMessage = 'Configuration or resource input in JSON format.')]
[string]$jsonInput = '@{}'
)
# Read JSON input from stdin using $input automatic variable for operations that need it
if ($Operation -ne 'List') {
$stdinData = $input | Out-String
if (-not [string]::IsNullOrWhiteSpace($stdinData)) {
$jsonInput = $stdinData
}
}
function Write-DscTrace {
param(
[Parameter(Mandatory = $false)]
[ValidateSet('Error', 'Warn', 'Info', 'Debug', 'Trace')]
[string]$Operation = 'Debug',
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Message
)
$trace = @{$Operation = $Message } | ConvertTo-Json -Compress
$host.ui.WriteErrorLine($trace)
}
'Hello from TestAdapter.' | Write-DscTrace
'PSPath=' + $PSHome | Write-DscTrace
'PSModulePath=' + $env:PSModulePath | Write-DscTrace
if ($jsonInput -ne '@{}') {
$inputobj = $jsonInput | ConvertFrom-Json
}
"Input: $jsonInput" | Write-DscTrace
switch ($Operation) {
'List' {
@{
type = "Test/TestCase"
kind = 'resource'
version = '1'
capabilities = @('get', 'set', 'test', 'export')
path = $PSScriptRoot
directory = Split-Path $PSScriptRoot
implementedAs = 'adapter'
author = 'Test'
properties = @('TestCaseId', 'Input', 'Result')
requireAdapter = 'Test/TestAdapter'
description = 'TestCase resource'
} | ConvertTo-Json -Compress
}
{ @('Get','Set','Test') -contains $_ } {
"Operation: $Operation" | Write-DscTrace
if ($inputobj.resources.properties.TestCaseId -eq 1) {
"Is TestCaseId 1" | Write-DscTrace
@{result = @(@{name = $inputobj.resources.name; type = $inputobj.resources.type; properties = @{'TestCaseId' = 1; 'Input' = ''}})} | ConvertTo-Json -Depth 10 -Compress
}
}
'Export' {
@{result = @(
@{'TestCaseId' = 1; 'Input' = ''},
@{'TestCaseId' = 2; 'Input' = ''}
)} | ConvertTo-Json -Depth 10 -Compress
}
'Validate' {
@{ valid = $true } | ConvertTo-Json
}
}