Must operator names follow PowerShell expectations, not raw Azure operator names¶
Context and Problem Statement¶
Must is deliberately Pester-like, so authors will bring Pester and PowerShell expectations with them. Two Azure operators behave differently from their Pester namesakes:
- Azure
matchis not a regular expression.#matches a digit,?a letter and.any character, and every other character matches itself. It is also case-sensitive. Pester's-Matchis a case-insensitive regex. Azure providesmatchInsensitivelyfor case-insensitive matching. - Pester's
-Containchecks whether a collection includes an item. Azurecontainsis a text test on the value, and Learn doesn't document its behaviour on arrays.
Considered Options¶
- PowerShell-flavoured names that state the Azure semantics
- The spec's original one-to-one names (
-Matchmaps tomatch,-Containmaps tocontains)
Decision Outcome¶
Chosen option: "PowerShell-flavoured names that state the Azure semantics".
| DSL | Policy operator | Inverted | Compile-time validation |
|---|---|---|---|
-Be v |
equals |
notEquals |
v must be a single value |
-BeIn a |
in |
notIn |
a must be an array, or an array-typed parameter |
-BeLike p |
like |
notLike |
at most one * in p |
-Match p |
matchInsensitively |
notMatchInsensitively |
p is an Azure match pattern, not a regex |
-MatchCase p |
match |
notMatch |
as above |
-ContainText s |
contains |
notContains |
no * in s |
-ContainKey k |
containsKey |
notContainsKey |
|
-Exist |
exists: true |
exists: false |
takes no value |
-BeGreaterThan n |
greater |
lessOrEquals |
|
-BeGreaterOrEqual n |
greaterOrEquals |
less |
|
-BeLessThan n |
less |
greaterOrEquals |
|
-BeLessOrEqual n |
lessOrEquals |
greater |
|
-Not |
flips the operator | ||
-IfPresent |
lenient missing-field handling (ADR-0004) | not valid inside Each, with -Exist, or in When |
|
-Strict |
strict missing-field handling inside Each (ADR-0004) |
only valid inside Each |
- Each
Musttakes exactly one operator. Zero or several is a compile error. Musttakes a field reference (Field, orElementinsideEach) from the pipeline. Anything else is a compile error.- A literal,
ParamorArmis accepted wherever a value is expected. - A
-Matchor-MatchCasepattern that looks like a regex (it contains^,$,\d,[,(or+) produces a warning, because Azure treats those characters literally.
Consequences¶
- Good, because the names don't silently mislead Pester users.
-Matchis case-insensitive, as in PowerShell. - Bad, because the DSL names no longer map one to one onto Azure operator names. The README operator table and
about_Bylaw_Operatorsdocument the mapping.
Confirmation¶
Unit tests cover each operator and its inversion, every validation error, and the regex-lookalike warning.