Skip to content

Commit 079a90f

Browse files
authored
Merge pull request #363 from mgreenegit/powershell_group
PowerShell adapter PR
2 parents ef36815 + 98f4126 commit 079a90f

27 files changed

+1382
-465
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ node_modules/
1010
tree-sitter-dscexpression/bindings/
1111
tree-sitter-dscexpression/src/
1212
tree-sitter-dscexpression/parser.*
13-
tree-sitter-dscexpression/binding.gyp
13+
tree-sitter-dscexpression/binding.gyp

build.ps1

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,18 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")
188188

189189
if (Test-Path "./copy_files.txt") {
190190
Get-Content "./copy_files.txt" | ForEach-Object {
191-
Copy-Item $_ $target -Force -ErrorAction Ignore
191+
# if the line contains a '\' character, throw an error
192+
if ($_ -match '\\') {
193+
throw "copy_files.txt should use '/' as the path separator"
194+
}
195+
# copy the file to the target directory, creating the directory path if needed
196+
$fileCopyPath = $_.split('/')
197+
if ($fileCopyPath.Length -gt 1) {
198+
$fileCopyPath = $fileCopyPath[0..($fileCopyPath.Length - 2)]
199+
$fileCopyPath = $fileCopyPath -join '/'
200+
New-Item -ItemType Directory -Path "$target/$fileCopyPath" -Force -ErrorAction Ignore | Out-Null
201+
}
202+
Copy-Item $_ "$target/$_" -Force -ErrorAction Ignore
192203
}
193204
}
194205

@@ -199,6 +210,8 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")
199210
}
200211
}
201212

213+
Save-PSResource -Path $target -Name 'PSDesiredStateConfiguration' -Version '2.0.7' -Repository PSGallery -TrustRepository
214+
202215
if ($failed) {
203216
Write-Host -ForegroundColor Red "Build failed"
204217
exit 1
@@ -243,14 +256,12 @@ if ($Test) {
243256
$FullyQualifiedName = @{ModuleName="PSDesiredStateConfiguration";ModuleVersion="2.0.7"}
244257
if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName))
245258
{ "Installing module PSDesiredStateConfiguration 2.0.7"
246-
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
247-
Install-Module PSDesiredStateConfiguration -RequiredVersion 2.0.7
259+
Install-PSResource -Name PSDesiredStateConfiguration -Version 2.0.7 -Repository PSGallery -TrustRepository
248260
}
249261

250262
if (-not(Get-Module -ListAvailable -Name Pester))
251263
{ "Installing module Pester"
252-
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
253-
Install-Module Pester -WarningAction Ignore
264+
Install-PSResource Pester -WarningAction Ignore -Repository PSGallery -TrustRepository
254265
}
255266

256267
foreach ($project in $projects) {
@@ -295,7 +306,7 @@ if ($Test) {
295306
if (-not(Get-Module -ListAvailable -Name Pester))
296307
{ "Installing module Pester"
297308
$InstallTargetDir = ($env:PSModulePath -split ";")[0]
298-
Find-Module -Name 'Pester' -Repository 'PSGallery' | Save-Module -Path $InstallTargetDir
309+
Find-PSResource -Name 'Pester' -Repository 'PSGallery' | Save-PSResource -Path $InstallTargetDir -TrustRepository
299310
}
300311

301312
"Updated Pester module location:"

dsc/tests/dsc_config_get.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Describe 'dsc config get tests' {
2727
It 'will fail if resource schema does not match' -Skip:(!$IsWindows) {
2828
$jsonPath = Join-Path $PSScriptRoot '../examples/invalid_schema.dsc.yaml'
2929
$config = Get-Content $jsonPath -Raw
30-
$null = $config | dsc config get | ConvertFrom-Json
30+
$testError = & {$config | dsc config get get 2>&1}
31+
$testError[0] | Should -match 'error:'
3132
$LASTEXITCODE | Should -Be 2
3233
}
3334

dsc/tests/dsc_get.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Describe 'resource get tests' {
4444
"Name": "ProductName"
4545
}
4646
'@
47-
$json | dsc resource get -r Microsoft.Windows/registry
47+
$testError = & {$json | dsc resource get -r Microsoft.Windows/registry get 2>&1}
48+
$testError[0] | SHould -match 'error:'
4849
$LASTEXITCODE | Should -Be 2
4950
}
5051
}

dsc/tests/dsc_parameters.tests.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ Describe 'Parameters tests' {
8181
"@
8282
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json
8383

84-
$null = $config_yaml | dsc config -p $params_json get
84+
$testError = & {$config_yaml | dsc config -p $params_json get 2>&1}
85+
$testError | Should -match 'Parameter input failure:'
8586
$LASTEXITCODE | Should -Be 4
8687
}
8788

@@ -108,8 +109,9 @@ Describe 'Parameters tests' {
108109
"@
109110
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json
110111

111-
$null = $config_yaml | dsc config -p $params_json get
112-
$LASTEXITCODE | Should -Be 4
112+
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
113+
$testError[0] | Should -match 'error'
114+
$LASTEXITCODE | Should -Be 2
113115
}
114116

115117
It 'Input number value is out of range for <min> and <max>' -TestCases @(
@@ -134,8 +136,9 @@ Describe 'Parameters tests' {
134136
"@
135137
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json
136138

137-
$null = $config_yaml | dsc config -p $params_json get
138-
$LASTEXITCODE | Should -Be 4
139+
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
140+
$testError[0] | Should -match 'error'
141+
$LASTEXITCODE | Should -Be 2
139142
}
140143

141144
It 'Input is not in the allowed value list for <type>' -TestCases @(
@@ -158,8 +161,9 @@ Describe 'Parameters tests' {
158161
"@
159162
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json
160163

161-
$null = $config_yaml | dsc config -p $params_json get
162-
$LASTEXITCODE | Should -Be 4
164+
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
165+
$testError[0] | Should -match 'error'
166+
$LASTEXITCODE | Should -Be 2
163167
}
164168

165169
It 'Length constraint is incorrectly applied to <type> with <constraint>' -TestCases @(
@@ -184,8 +188,9 @@ Describe 'Parameters tests' {
184188
"@
185189
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json
186190

187-
$null = $config_yaml | dsc config -p $params_json get | ConvertFrom-Json
188-
$LASTEXITCODE | Should -Be 4
191+
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
192+
$testError[0] | Should -match 'error'
193+
$LASTEXITCODE | Should -Be 2
189194
}
190195

191196
It 'Default value is used when not provided' {

powershell-adapter/Tests/PSTestModule/DscResources/TestPSRepository/TestPSRepository.psm1 renamed to powershell-adapter/Tests/PSTestModule/1.0.0/DscResources/TestPSRepository/TestPSRepository.psm1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
14
enum EnsureEnumeration {
25
Absent
36
Present
@@ -14,7 +17,7 @@ function Get-TargetResource {
1417
)
1518

1619
$returnValue = @{
17-
Ensure = [EnsureEnumeration]::Absent
20+
Ensure = ([EnsureEnumeration]::Absent).ToString()
1821
Name = $Name
1922
SourceLocation = $null
2023
ScriptSourceLocation = $null
@@ -27,7 +30,7 @@ function Get-TargetResource {
2730
}
2831

2932
if ($Name -eq "TestPSRepository1") {
30-
$returnValue.Ensure = [EnsureEnumeration]::Present
33+
$returnValue.Ensure = ([EnsureEnumeration]::Present).ToString()
3134
$returnValue.SourceLocation = 'https://www.powershellgallery.com/api/v2'
3235
$returnValue.ScriptSourceLocation = 'https://www.powershellgallery.com/api/v2/items/psscript'
3336
$returnValue.PublishLocation = 'https://www.powershellgallery.com/api/v2/package/'
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
13
@{
2-
RootModule = 'TestClassResource.psm1'
34
ModuleVersion = '1.0.0'
45
GUID = '5d73a601-4a6c-43c5-ba3f-619b18bbb404'
56
Author = 'Microsoft Corporation'
67
CompanyName = 'Microsoft Corporation'
78
Copyright = '(c) Microsoft Corporation. All rights reserved.'
89
Description = 'PowerShell module for testing DSCv3'
9-
PowerShellVersion = '5.0'
10-
DscResourcesToExport = 'TestClassResource'
10+
PowerShellVersion = '5.1'
11+
DscResourcesToExport = 'TestPSRepository'
1112
FunctionsToExport = @(
1213
'Test-World')
13-
VariablesToExport = '@()'
14+
VariablesToExport = @()
1415
AliasesToExport = @()
1516
PrivateData = @{
1617
PSData = @{
@@ -20,6 +21,7 @@
2021
'PSEdition_Core',
2122
'Linux',
2223
'Mac')
24+
DscCapabilities = @('Get', 'Test')
2325
}
2426
}
2527
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
@{
5+
6+
# Script module or binary module file associated with this manifest.
7+
RootModule = 'TestClassResource.psm1'
8+
9+
# Version number of this module.
10+
ModuleVersion = '0.0.1'
11+
12+
# ID used to uniquely identify this module
13+
GUID = 'b267fa32-e77d-48e6-9248-676cc6f2327f'
14+
15+
# Author of this module
16+
Author = 'Microsoft'
17+
18+
# Company or vendor of this module
19+
CompanyName = 'Microsoft Corporation'
20+
21+
# Copyright statement for this module
22+
Copyright = '(c) Microsoft. All rights reserved.'
23+
24+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
25+
FunctionsToExport = @()
26+
27+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
28+
CmdletsToExport = '*'
29+
30+
# Variables to export from this module
31+
VariablesToExport = @()
32+
33+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
34+
AliasesToExport = @()
35+
36+
# DSC resources to export from this module
37+
DscResourcesToExport = 'TestClassResource'
38+
39+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
40+
PrivateData = @{
41+
PSData = @{
42+
DscCapabilities = @(
43+
'Get'
44+
'Test'
45+
)
46+
}
47+
}
48+
49+
}
50+

powershell-adapter/Tests/PSTestModule/TestClassResource.psm1 renamed to powershell-adapter/Tests/TestClassResource/0.0.1/TestClassResource.psm1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
14
using namespace System.Collections.Generic
25

36
enum EnumPropEnumeration {
@@ -15,7 +18,7 @@ class TestClassResource
1518
[string] $Prop1
1619

1720
[DscProperty()]
18-
[EnumPropEnumeration] $EnumProp
21+
[string] $EnumProp
1922

2023
[void] Set()
2124
{
@@ -43,7 +46,7 @@ class TestClassResource
4346
{
4447
$this.Prop1 = $env:DSC_CONFIG_ROOT
4548
}
46-
$this.EnumProp = [EnumPropEnumeration]::Expected
49+
$this.EnumProp = ([EnumPropEnumeration]::Expected).ToString()
4750
return $this
4851
}
4952

0 commit comments

Comments
 (0)