Skip to content

Enable Set-StrictMode in unit tests for MSFT_UpdateServicesCleanup and MSFT_UpdateServicesServer #89

@coderabbitai

Description

@coderabbitai

Description

Multiple unit tests have Set-StrictMode commented out due to uninitialized variable issues. These should be fixed to ensure code quality and catch potential bugs.

Affected Files

MSFT_UpdateServicesCleanup.Tests.ps1

  • Line 107-108: Get-TargetResource when server is not configured (Absent scenario)
  • Line 145-146: Get-TargetResource when server is configured unexpectedly

MSFT_UpdateServicesServer.Tests.ps1

  • Line 89-90: Get-TargetResource - $ProxyCredentialUserName is not initialized
  • Line 126-127: Get-TargetResource (Absent) - variables are not initialized
  • Line 183-184: Get-TargetResource (Absent) - $ProxyCredentialUserName is not initialized
  • Line 220-221: Get-TargetResource (Present) - variables are not initialized
  • Line 276-277: Get-TargetResource (Present with wildcard products) - variables are not initialized

Required Actions

  1. Update the DSC resource implementations (MSFT_UpdateServicesCleanup.psm1 and MSFT_UpdateServicesServer.psm1) to properly initialize all variables before use
  2. Ensure all variables are declared and assigned default values
  3. Avoid reliance on pipeline-bound parameters or automatic variable population
  4. Uncomment Set-StrictMode in all affected test blocks
  5. Verify all tests pass with strict mode enabled

References

Additional Context

These issues were identified during the Pester 5 migration. Enabling strict mode helps catch uninitialized variables and other potential bugs at test time.


Requested by: @dan-hughes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThe issue is an enhancement request.help wantedThe issue is up for grabs for anyone in the community.testsThe issue or pull request is about tests only.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions