microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
376 stars 49 forks source link

[Question] is TypeOf case insensitive or not ? #201

Closed LaurentDardenne closed 5 years ago

LaurentDardenne commented 5 years ago

Is this documentation false ?

TypeName - One or more type names which will be evaluated against the pipeline object. TypeName is case insensitive.

The result of the following code indicates that TypeOf keyword is case-sensitive :

$Path='C:\temp'

$Rule='Test.Rule.ps1'
@'
Rule 'MustBeTypeLowerCase' {
    TypeOf -TypeName 'my'
}
Rule 'MustBeTypeUppercase' {
    TypeOf -TypeName 'My'
}
'@ >"$Path\$Rule"

$Result= [PSCustomObject]@{PSTypeName='My';name='Test'}|Invoke-PSRule -path "$Path\$Rule" 
$Result|Select-Object RuleName,Outcome,OutcomeReason
# RuleName            Outcome OutcomeReason
# --------            ------- -------------
# MustBeTypeLowerCase    Fail     Processed
# MustBeTypeUppercase    Pass     Processed

$Result= [PSCustomObject]@{PSTypeName='my';name='Test'}|Invoke-PSRule -path "$Path\$Rule" 
$Result|Select-Object RuleName,Outcome,OutcomeReason

# RuleName            Outcome OutcomeReason
# --------            ------- -------------
# MustBeTypeLowerCase    Pass     Processed
# MustBeTypeUppercase    Fail     Processed
BernieWhite commented 5 years ago

@LaurentDardenne You are correct. The documentation is incorrect. The -TypeName property is case-sensitive.