Skip to content

Commit a3184db

Browse files
committed
Resolve feedback
1 parent 1e46b00 commit a3184db

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

powershell-adapter/Tests/powershellgroup.resource.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Describe 'PowerShell adapter resource tests' {
2727
$r = dsc resource list '*' -a Microsoft.DSC/PowerShell
2828
$LASTEXITCODE | Should -Be 0
2929
$resources = $r | ConvertFrom-Json
30-
($resources | ? { $_.Type -eq 'TestClassResource/TestClassResource' }).Count | Should -Be 1
30+
($resources | Where-Object { $_.Type -eq 'TestClassResource/TestClassResource' }).Count | Should -Be 1
3131
($resources | Where-Object -Property type -EQ 'TestClassResource/TestClassResource').capabilities | Should -BeIn @('get', 'set', 'test', 'export')
32+
($resources | Where-Object -Property type -EQ 'TestClassResource/NoExport').capabilities | Should -BeIn @('get', 'set', 'test')
3233
}
3334

3435
It 'Get works on class-based resource' {

powershell-adapter/psDscAdapter/powershell.resource.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ switch ($Operation) {
9191
# TODO: for perf, it is better to take capabilities from psd1 in Invoke-DscCacheRefresh, not by extra call to Get-Module
9292
if ($DscResourceInfo.ModuleName) {
9393
$module = Get-Module -Name $DscResourceInfo.ModuleName -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
94-
if ($module.PrivateData.PSData.DscCapabilities) {
94+
if ($DscResourceInfo.Capabilities) {
95+
$capabilities = $DscResourceInfo.Capabilities
96+
} elseif ($module.PrivateData.PSData.DscCapabilities) {
97+
9598
$capabilities = $module.PrivateData.PSData.DscCapabilities
96-
}
97-
elseif ($DscResourceInfo.Methods) {
98-
$capabilities = $DscResourceInfo.Methods
99-
}
100-
else {
99+
} else {
101100
$capabilities = @('get', 'set', 'test')
102101
}
103102
}

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Add-AstMembers {
6060

6161
foreach ($member in $TypeAst.Members) {
6262
$property = $member -as [System.Management.Automation.Language.PropertyMemberAst]
63-
if (($property -eq $null) -or ($property.IsStatic)) {
63+
if (($null -eq $property) -or ($property.IsStatic)) {
6464
continue;
6565
}
6666
$skipProperty = $true
@@ -139,7 +139,7 @@ function FindAndParseResourceDefinitions {
139139
$DscResourceInfo.Version = $moduleVersion
140140

141141
$DscResourceInfo.Properties = [System.Collections.Generic.List[DscResourcePropertyInfo]]::new()
142-
$DscResourceInfo.Methods = GetClassBasedCapabilities $typeDefinitionAst.Members
142+
$DscResourceInfo.Capabilities = GetClassBasedCapabilities $typeDefinitionAst.Members
143143
Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
144144

145145
$resourceList.Add($DscResourceInfo)
@@ -531,21 +531,21 @@ function GetTypeInstanceFromModule {
531531
}
532532

533533
function GetClassBasedCapabilities ($functionMemberAst) {
534-
$capabilities = @()
534+
$capabilities = [System.Collections.Generic.List[string[]]]::new()
535535
# These are the methods that we can potentially expect in a class-based DSC resource.
536536
$availableMethods = @('get', 'set', 'setHandlesExist', 'whatIf', 'test', 'delete', 'export')
537537
$methods = $functionMemberAst | Where-Object { $_ -is [System.Management.Automation.Language.FunctionMemberAst] -and $_.Name -in $availableMethods }
538538

539539
foreach ($method in $methods.Name) {
540540
# We go through each method to properly case handle the method names.
541541
switch ($method) {
542-
'Get' { $capabilities += 'get' }
543-
'Set' { $capabilities += 'set' }
544-
'Test' { $capabilities += 'test' }
545-
'WhatIf' { $capabilities += 'whatIf' }
546-
'SetHandlesExist' { $capabilities += 'setHandlesExist' }
547-
'Delete' { $capabilities += 'delete' }
548-
'Export' { $capabilities += 'export' }
542+
'Get' { $capabilities.Add('get') }
543+
'Set' { $capabilities.Add('set') }
544+
'Test' { $capabilities.Add('test') }
545+
'WhatIf' { $capabilities.Add('whatIf') }
546+
'SetHandlesExist' { $capabilities.Add('setHandlesExist') }
547+
'Delete' { $capabilities.Add('delete') }
548+
'Export' { $capabilities.Add('export') }
549549
}
550550
}
551551

@@ -601,5 +601,5 @@ class DscResourceInfo {
601601
[string] $ImplementedAs
602602
[string] $CompanyName
603603
[System.Collections.Generic.List[DscResourcePropertyInfo]] $Properties
604-
[string[]] $Methods
604+
[string[]] $Capabilities
605605
}

0 commit comments

Comments
 (0)