Skip to content

Commit

Permalink
Merge branch 'main' into issue_158
Browse files Browse the repository at this point in the history
  • Loading branch information
anmenaga committed Sep 28, 2023
2 parents 5231555 + ac8bc2f commit 9e89d73
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
enum EnsureEnumeration {
Absent
Present
}

function Get-TargetResource {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
Expand All @@ -9,7 +14,7 @@ function Get-TargetResource {
)

$returnValue = @{
Ensure = 'Absent'
Ensure = [EnsureEnumeration]::Absent
Name = $Name
SourceLocation = $null
ScriptSourceLocation = $null
Expand All @@ -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/'
Expand Down
9 changes: 9 additions & 0 deletions powershellgroup/Tests/PSTestModule/TestClassResource.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
enum EnumPropEnumeration {
Unexpected
Expected
}

[DscResource()]
class TestClassResource
{
Expand All @@ -7,6 +12,9 @@ class TestClassResource
[DscProperty()]
[string] $Prop1

[DscProperty()]
[EnumPropEnumeration] $EnumProp

[void] Set()
{
}
Expand All @@ -29,6 +37,7 @@ class TestClassResource
{
$this.Prop1 = "ValueForProp1"
}
$this.EnumProp = [EnumPropEnumeration]::Expected
return $this
}
}
Expand Down
16 changes: 16 additions & 0 deletions powershellgroup/Tests/powershellgroup.resource.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion powershellgroup/powershellgroup.resource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ elseif ($Operation -eq 'Get')
}
}

$result | ConvertTo-Json
$result | ConvertTo-Json -EnumsAsStrings
}
elseif ($Operation -eq 'Set')
{
Expand Down
8 changes: 4 additions & 4 deletions tools/add-path.ps1
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 9e89d73

Please sign in to comment.