powershell/PSDSCDscTestsPresent is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
tally disables this rule by default because Desired State Configuration resources are out
of scope for Dockerfile
RUN analysis. Re-enable it with
include = ["powershell/PSDSCDscTestsPresent"] or by setting
rules.powershell.PSDSCDscTestsPresent.severity = "warning" in .tally.toml.Description
Checks that DSC tests for given resource are present.How
To fix a violation of this rule, please make sureTests directory is present:
- For non-class-based resources, it should exist at the same folder level as the
DSCResourcesfolder. - For class-based resources, it should be present at the same folder level as the resource
.psm1file.
Tests folder should contain a test script for a given resource. The filename should contain the
resource’s name.
Examples
Non-class-based resource
Let’s assume we have a non-class-based resource with the following file structure:- xAzure
- DSCResources
- MSFT_xAzureSubscription
- MSFT_xAzureSubscription.psm1
- MSFT_xAzureSubscription.schema.mof
- MSFT_xAzureSubscription
- DSCResources
- xAzure
- DSCResources
- MSFT_xAzureSubscription
- MSFT_xAzureSubscription.psm1
- MSFT_xAzureSubscription.schema.mof
- MSFT_xAzureSubscription
- Tests
- MSFT_xAzureSubscription_Tests.ps1
- DSCResources
Class-based resource
Let’s assume we have a class-based resource with the following file structure:- MyDscResource
- MyDscResource.psm1
- MyDscResource.psd1
- MyDscResource
- MyDscResource.psm1
- MyDscResource.psd1
- Tests
- MyDscResource_Tests.ps1