Skip to content

Latest commit

 

History

History
238 lines (180 loc) · 6.14 KB

Invoke-AvmTestUnit.md

File metadata and controls

238 lines (180 loc) · 6.14 KB

Invoke-AvmTestUnit

Synopsis

Run the module's Bicep Pester or Terraform unit-test tier.

Description

For Bicep, runs module tests/unit/*.tests.ps1 only by default. Pester runs in a child PowerShell process and receives repoRootPath and moduleFolderPaths. -Recurse includes nested module scopes. -IncludeCompliance adds packaged native conventions, metadata and README requirements in one in-process Pester run. Authored unit tests remain isolated in a child process. -CompliancePath selects an explicit alternate suite and implies -IncludeCompliance.

For Terraform, runs 'terraform test' against tests/unit/ through Invoke-AvmTerraformTestSuite -Tier unit.

Unlike the bare 'avm test' verb (which is the cheap, offline 'terraform validate' build pass), this tier executes real 'terraform test' HCL run blocks. A missing suite or a Pester filter matching no tests reports 'skipped' with zero runs, never a pass. Explicitly skipped Pester tests fail the tier.

This is a standalone credential-free tier. The Terraform tier also runs in 'avm pr-check'. Bicep convention checks are separate; the existing registry CI remains authoritative until that work is complete and a cutover is approved.

Routed by the dispatcher: 'avm test unit'.

CLI commands

  • avm test unit

Syntax

Invoke-AvmTestUnit [[-Path] <string>] [-Ecosystem <string>] [-AllowPathFallback] [-NoInit] [-Tag <string[]>] [-TestName <string[]>] [-Recurse] [-IncludeCompliance] [-CompliancePath <string>] [-RepositoryRoot <string>] [-SkipModuleVersionCheck] [<CommonParameters>]

Parameters

-AllowPathFallback

When set, accept a PATH-resolved tool binary that self-reports the lock-pinned version.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-CompliancePath

Bicep-only: explicit compliance Pester suite file. Relative paths resolve under -RepositoryRoot or the discovered repository root. Selecting a path enables compliance without -IncludeCompliance.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-Ecosystem

Force the ecosystem selector. Defaults to 'auto'.

Property Value
Type String
Required false
Position named
Default value auto
Accept pipeline input false
Accept wildcard characters false

-IncludeCompliance

Bicep-only: also run the packaged compliance suite. This is an explicit transition option, not part of the default unit tier.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-NoInit

Terraform-only: skip the automatic terraform init step.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-Path

Working directory whose enclosing module to test. Defaults to the current location.

Property Value
Type String
Required false
Position 1
Default value $PWD.Path
Accept pipeline input false
Accept wildcard characters false

-Recurse

Bicep-only: include child module scopes and their unit tests.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false
Aliases PesterTestRecurse

-RepositoryRoot

Bicep-only: override the repository root passed to authored tests.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-SkipModuleVersionCheck

Skip the PowerShell Gallery check that otherwise stops the command when a newer Avm.Authoring version is available. Writes a warning once.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-Tag

Bicep-only Pester tag filter. Alias: PesterTag.

Property Value
Type String[]
Required false
Position named
Default value @()
Accept pipeline input false
Accept wildcard characters false
Aliases PesterTag, PesterTags

-TestName

Bicep-only Pester full-name filter (supports Pester wildcards).

Property Value
Type String[]
Required false
Position named
Default value @()
Accept pipeline input false
Accept wildcard characters false

Examples

EXAMPLE 1

avm test unit

EXAMPLE 2

Invoke-AvmTestUnit -Path C:\repos\terraform-azurerm-avm-res-foo

EXAMPLE 3

avm test unit --ecosystem bicep --tag UDT --recurse

EXAMPLE 4

avm test unit --include-compliance

Outputs

  • pscustomobject from the engine: Engine, Tool, ToolPath, ToolSource, Status, FilesProcessed, RunsTotal, RunsPassed, RunsFailed, Issues. Bicep also reports RunsSkipped, RunsInconclusive, RunsFiltered, UnitFiles, ComplianceFile and ModuleScopes. When authored Pester runs in a child, Bicep also returns Authoring: the child's process ID, admitted source manifest/base/SHA256, observed post-suite loaded and discoverable module bases, loaded manifest/SHA256/version/GUID, and the module bases owning Get-AvmTool and Install-AvmTool. The receipt is validated against the admitted source and exact child copy before it is returned; failed identity checks throw. A skipped run without an authored suite has no Authoring receipt. RunsFailed includes native compliance warning assertions; their warning severity does not fail the tier. Authored test failures always fail it.