Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes PowerShell/DSC#159 resources should have enum labels #208

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
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