From 6c1c6d6670866aefb44cbce130234e8aaa4d3e12 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 26 Sep 2023 16:01:16 -0700 Subject: [PATCH 1/2] Fix `add-path.ps1` to use $PSScriptRoot instead of $PWD --- tools/add-path.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/add-path.ps1 b/tools/add-path.ps1 index b3d7bcf2..aa391974 100644 --- a/tools/add-path.ps1 +++ b/tools/add-path.ps1 @@ -1,12 +1,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# This script will add the current directory to the PATH environment variable +# This script will add the script directory to the PATH environment variable # for the current user. This is useful for development purposes. $pathSeparator = [System.IO.Path]::PathSeparator $paths = $env:PATH.Split($pathSeparator) -if ($paths -notcontains $PWD) { - $env:PATH = "$PWD" + $pathSeparator + $env:PATH - Write-Host -ForegroundColor Green "Added $PWD to `$env:PATH" +if ($paths -notcontains $PSScriptRoot) { + $env:PATH = "$PSScriptRoot" + $pathSeparator + $env:PATH + Write-Host -ForegroundColor Green "Added $PSScriptRoot to `$env:PATH" } From b204c40c21be6bd8481b79eba41ba5af45b21a11 Mon Sep 17 00:00:00 2001 From: miroman9364 <107484955+miroman9364@users.noreply.github.com> Date: Wed, 27 Sep 2023 13:41:38 -0700 Subject: [PATCH 2/2] Fix resources should have enum labels This fixes issue #159. When converting JSON into PowerShell object, replace enum values with the string label names. --- .../TestPSRepository/TestPSRepository.psm1 | 9 +++++++-- .../Tests/PSTestModule/TestClassResource.psm1 | 9 +++++++++ .../Tests/powershellgroup.resource.tests.ps1 | 16 ++++++++++++++++ powershellgroup/powershellgroup.resource.ps1 | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/powershellgroup/Tests/PSTestModule/DscResources/TestPSRepository/TestPSRepository.psm1 b/powershellgroup/Tests/PSTestModule/DscResources/TestPSRepository/TestPSRepository.psm1 index c7b3c30d..d02c38d4 100644 --- a/powershellgroup/Tests/PSTestModule/DscResources/TestPSRepository/TestPSRepository.psm1 +++ b/powershellgroup/Tests/PSTestModule/DscResources/TestPSRepository/TestPSRepository.psm1 @@ -1,3 +1,8 @@ +enum EnsureEnumeration { + Absent + Present +} + function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] @@ -9,7 +14,7 @@ function Get-TargetResource { ) $returnValue = @{ - Ensure = 'Absent' + Ensure = [EnsureEnumeration]::Absent Name = $Name SourceLocation = $null ScriptSourceLocation = $null @@ -22,7 +27,7 @@ function Get-TargetResource { } if ($Name -eq "TestPSRepository1") { - $returnValue.Ensure = 'Present' + $returnValue.Ensure = [EnsureEnumeration]::Present $returnValue.SourceLocation = 'https://www.powershellgallery.com/api/v2' $returnValue.ScriptSourceLocation = 'https://www.powershellgallery.com/api/v2/items/psscript' $returnValue.PublishLocation = 'https://www.powershellgallery.com/api/v2/package/' diff --git a/powershellgroup/Tests/PSTestModule/TestClassResource.psm1 b/powershellgroup/Tests/PSTestModule/TestClassResource.psm1 index b8bd937d..5fb0fa94 100644 --- a/powershellgroup/Tests/PSTestModule/TestClassResource.psm1 +++ b/powershellgroup/Tests/PSTestModule/TestClassResource.psm1 @@ -1,3 +1,8 @@ +enum EnumPropEnumeration { + Unexpected + Expected +} + [DscResource()] class TestClassResource { @@ -7,6 +12,9 @@ class TestClassResource [DscProperty()] [string] $Prop1 + [DscProperty()] + [EnumPropEnumeration] $EnumProp + [void] Set() { } @@ -29,6 +37,7 @@ class TestClassResource { $this.Prop1 = "ValueForProp1" } + $this.EnumProp = [EnumPropEnumeration]::Expected return $this } } diff --git a/powershellgroup/Tests/powershellgroup.resource.tests.ps1 b/powershellgroup/Tests/powershellgroup.resource.tests.ps1 index 7c026c8f..408c3d06 100644 --- a/powershellgroup/Tests/powershellgroup.resource.tests.ps1 +++ b/powershellgroup/Tests/powershellgroup.resource.tests.ps1 @@ -36,6 +36,22 @@ Describe 'PowerShellGroup resource tests' { $res.actualState.PublishLocation | Should -BeExactly 'https://www.powershellgallery.com/api/v2/package/' } + It 'Get uses enum names on class-based resource' -Skip:(!$IsWindows){ + + $r = "{'Name':'TestClassResource1'}" | dsc resource get -r PSTestModule/TestClassResource + $LASTEXITCODE | Should -Be 0 + $res = $r | ConvertFrom-Json + $res.actualState.EnumProp | Should -BeExactly 'Expected' + } + + It 'Get uses enum names on script-based resource' -Skip:(!$IsWindows){ + + $r = "{'Name':'TestPSRepository1'}" | dsc resource get -r PSTestModule/TestPSRepository + $LASTEXITCODE | Should -Be 0 + $res = $r | ConvertFrom-Json + $res.actualState.Ensure | Should -BeExactly 'Present' + } + It 'Test works on class-based resource' -Skip:(!$IsWindows){ $r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1'}" | dsc resource test -r PSTestModule/TestClassResource diff --git a/powershellgroup/powershellgroup.resource.ps1 b/powershellgroup/powershellgroup.resource.ps1 index 89a9449e..838950af 100644 --- a/powershellgroup/powershellgroup.resource.ps1 +++ b/powershellgroup/powershellgroup.resource.ps1 @@ -176,7 +176,7 @@ elseif ($Operation -eq 'Get') } } - $result | ConvertTo-Json + $result | ConvertTo-Json -EnumsAsStrings } elseif ($Operation -eq 'Set') {