Skip to content

Expand offline Pester tests with CI pipeline integration#606

Open
arudell wants to merge 12 commits into
microsoft:mainfrom
arudell:arudell-pester-test-expansion
Open

Expand offline Pester tests with CI pipeline integration#606
arudell wants to merge 12 commits into
microsoft:mainfrom
arudell:arudell-pester-test-expansion

Conversation

@arudell

@arudell arudell commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

Overhauls the Pester test infrastructure to use offline (mock-based) tests with randomized data, adds CI pipeline execution, and removes the deprecated online/self-hosted runner workflows.

Changes

New test files

  • tests/offline/Utilities.Tests.ps1 - Unit tests for Format-SdnMacAddress, Format-MacAddressWithDashes, Format-MacAddressNoDashes, Format-ByteSize, Format-KiloBitSize, Confirm-IpAddressInRange, Confirm-IpAddressInCidrRange
  • tests/offline/Health.Tests.ps1 - Tests for provisioning/configuration state validation, NIC health, gateway health, and MAC duplicate detection
  • tests/CONTRIBUTING_TESTS.md - Comprehensive guide for future contributors adding Pester tests

Expanded existing tests

  • NetworkController.Tests.ps1 - Expanded from 2 tests to ~10 across 4 Describe blocks (Get-SdnServer, Get-SdnGateway, Get-SdnLoadBalancerMux, Get-SdnResource)

Mock data

  • All 14 JSON files in tests/offline/data/SdnApiResources/ rewritten with consistent randomized naming (DVLAB prefix) and proper UTF-8 encoding

CI/CD

  • New: .github/workflows/pester-tests.yml - Runs offline Pester tests on every push to main and every PR
  • Updated: .github/workflows/build-pipeline.yml - Added test gate between build and publish steps
  • Removed: server2019-sdntest.yml, server2019-sdntest-pr.yml - Deprecated self-hosted runner workflows that required a live SDN environment

Runner improvements

  • RunTests.ps1 now supports -Tag and -TestFile parameters
  • Handles NC REST API {value:[...]} JSON wrapper format automatically

Testing

Tests require the module to be built first (.\build.ps1), then run via .\tests\offline\RunTests.ps1.

arudell and others added 3 commits July 15, 2026 10:28
- Add Utilities.Tests.ps1: Format-* and Confirm-IpAddress* unit tests
- Add Health.Tests.ps1: provisioning/configuration state, MAC duplicate detection
- Expand NetworkController.Tests.ps1: Get-SdnGateway, Get-SdnLoadBalancerMux, Get-SdnResource
- Replace all mock data with consistent DVLAB-prefixed randomized names
- Update RunTests.ps1: add -Tag and -TestFile parameters, handle wrapped JSON
- Add CONTRIBUTING_TESTS.md: instructions for adding new Pester tests
- Update README.md: document new runner options, link to CONTRIBUTING_TESTS.md

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- Add 'Pester Tests' workflow (pester-tests.yml): runs offline tests on
  every push to main and every PR targeting main
- Add 'Run Offline Pester Tests' step to build-pipeline.yml so tests
  gate the publish step

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Online tests required a live SDN environment on a self-hosted runner
and are no longer maintained. All validation is now covered by the
offline mock-based Pester tests.

Removed:
- .github/workflows/server2019-sdntest.yml
- .github/workflows/server2019-sdntest-pr.yml
- tests/online/ (RunTests.ps1, config sample, wave1/, waveAll/)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
@arudell
arudell requested a review from a team as a code owner July 15, 2026 15:57
arudell and others added 3 commits July 15, 2026 11:21
- Create .github/instructions/pester-tests.instructions.md with full
  skill guide (patterns, mock data, naming, CI, running tests)
- Add Pester Testing section to .github/copilot-instructions.md
- Remove online test references from CONTRIBUTING_TESTS.md (online tests
  were deleted in prior commit)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- .github/prompts/create-pester-test.prompt.md: reusable slash command
  to generate offline Pester tests for any function
- .github/instructions/pester-review.instructions.md: code review rule
  that flags PRs adding/modifying functions without corresponding tests

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Single prompt that creates a new function following project conventions
AND generates its corresponding offline Pester tests in one invocation.
Instructions files remain separate for passive context loading.

- Remove: .github/prompts/create-pester-test.prompt.md
- Add: .github/prompts/add-sdn-function.prompt.md

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands offline Pester infrastructure and integrates it into CI while retiring live SDN test workflows.

Changes:

  • Adds utility, Network Controller, and health-related offline tests.
  • Enhances the test runner, fixtures, and contributor guidance.
  • Adds CI test gates and removes deprecated online workflows.

Reviewed changes

Copilot reviewed 22 out of 39 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
tests/README.md Documents offline runner options.
tests/online/waveAll/Start-SdnDataCollection.Tests.ps1 Removes live collection tests.
tests/online/waveAll/Get-SdnInfrastructureInfo.Tests.ps1 Removes live infrastructure tests.
tests/online/waveAll/Debug-SdnFabricInfrastructure.Tests.ps1 Removes live diagnostic tests.
tests/online/wave1/Utilities.Tests.ps1 Removes remote installation test.
tests/online/SdnDiagnosticsTestConfig-Sample.psd1 Removes online test configuration.
tests/online/RunTests.ps1 Removes online test runner.
tests/offline/Utilities.Tests.ps1 Adds utility unit tests.
tests/offline/SoftwareLoadBalancer.Tests.ps1 Updates mock NC URI.
tests/offline/RunTests.ps1 Adds filtering and wrapped-data loading.
tests/offline/NetworkController.Tests.ps1 Expands Network Controller tests.
tests/offline/Health.Tests.ps1 Adds health-related fixture tests.
tests/offline/data/SdnApiResources/iDNSServer_configuration.json Adds fictional DNS configuration.
tests/CONTRIBUTING_TESTS.md Adds test-authoring guidance.
.github/workflows/server2019-sdntest.yml Removes legacy push workflow.
.github/workflows/server2019-sdntest-pr.yml Removes legacy PR workflow.
.github/workflows/pester-tests.yml Adds offline test CI.
.github/workflows/build-pipeline.yml Adds a pre-publish test gate.
.github/prompts/add-sdn-function.prompt.md Adds function/test generation guidance.
.github/instructions/pester-tests.instructions.md Defines Pester conventions.
.github/instructions/pester-review.instructions.md Adds coverage review instructions.
.github/copilot-instructions.md Adds offline-testing guidance.

Comment thread .github/workflows/pester-tests.yml Outdated
Comment thread .github/workflows/build-pipeline.yml Outdated
Comment thread tests/offline/Utilities.Tests.ps1
Comment thread tests/offline/NetworkController.Tests.ps1 Outdated
Comment thread tests/offline/NetworkController.Tests.ps1 Outdated
Comment thread .github/instructions/pester-tests.instructions.md Outdated
Comment thread .github/prompts/add-sdn-function.prompt.md Outdated
Comment thread tests/offline/RunTests.ps1 Outdated
Comment thread .github/workflows/pester-tests.yml Outdated
Comment thread .github/workflows/build-pipeline.yml Outdated
- Use InModuleScope SdnDiagnostics for private utility functions
- Use InModuleScope SdnDiag.NetworkController with Mock Invoke-RestMethodWithRetry
  for NC REST functions (nested module session state requires this pattern)
- Fix MAC duplicate test @() wrapper for Group-Object single-result
- Add outboundNatRules back-reference to LB mock data
- Update instruction docs with correct mock patterns

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Copilot AI review requested due to automatic review settings July 15, 2026 17:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 39 changed files in this pull request and generated 16 comments.

Comment thread .github/workflows/pester-tests.yml Outdated
Comment thread .github/workflows/build-pipeline.yml Outdated
Comment thread tests/offline/RunTests.ps1
Comment thread tests/offline/Health.Tests.ps1 Outdated
Comment thread tests/offline/Health.Tests.ps1 Outdated
Comment thread .github/instructions/pester-review.instructions.md
Comment thread tests/offline/RunTests.ps1 Outdated
Comment thread .github/instructions/pester-tests.instructions.md
Comment thread .github/prompts/add-sdn-function.prompt.md Outdated
Comment thread .github/copilot-instructions.md Outdated
- RunTests.ps1: add -PassThru and failure propagation
- Workflows: route through RunTests.ps1 for consistent exit codes
- Health.Tests.ps1: rewrite as data structure validation tests
  (direct invocation blocked by [TraceLevel] cross-module limitation)
- CONTRIBUTING_TESTS.md: rewrite with accurate patterns and limitation docs
- README.md: remove online test references, offline-only layout
- add-sdn-function.prompt.md: fix module location table
- pester-review.instructions.md: add manifest export check

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Copilot AI review requested due to automatic review settings July 15, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 39 changed files in this pull request and generated 4 comments.

Comment thread tests/offline/Health.Tests.ps1
Comment thread .github/instructions/pester-tests.instructions.md
Comment thread tests/offline/data/SdnApiResources/iDNSServer_configuration.json
Comment thread tests/offline/Utilities.Tests.ps1
- pester-tests.instructions.md: add applyTo frontmatter for scope targeting
- pester-tests.instructions.md: document singleton fixture exception (no wrapper)
- add-sdn-function.prompt.md: note singleton format for config endpoints
- copilot-instructions.md: fix Pattern B to correctly reference Invoke-RestMethodWithRetry
- Utilities.Tests.ps1: add /0 CIDR edge case (documents known bit-shift limitation)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Copilot AI review requested due to automatic review settings July 15, 2026 19:41
Resolve modify/delete conflicts: online test workflows were intentionally
removed in this branch. Accept our deletion over main's modifications.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 39 changed files in this pull request and generated 4 comments.

Comment thread tests/offline/Health.Tests.ps1
Comment thread tests/CONTRIBUTING_TESTS.md
Comment thread tests/offline/Utilities.Tests.ps1 Outdated
Comment thread .github/instructions/pester-tests.instructions.md Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 19:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 39 changed files in this pull request and generated 3 comments.

Comment thread tests/offline/Health.Tests.ps1
Comment thread tests/offline/Utilities.Tests.ps1 Outdated
Comment thread tests/CONTRIBUTING_TESTS.md Outdated
- Fix Confirm-IpAddressInCidrRange: special-case prefix length 0 to avoid
  32-bit shift wrap (modulo 32 made /0 behave like /32)
- Update test to assert correct /0 behavior (Should -BeTrue)
- Fix 'one assertion per It' rule to 'one behavior per It' in both
  pester-tests.instructions.md and CONTRIBUTING_TESTS.md
- Fix BeforeAll mock guidance: mocks must live inside InModuleScope blocks,
  not in BeforeAll outside them

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Copilot AI review requested due to automatic review settings July 15, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 40 changed files in this pull request and generated 3 comments.

Comment thread tests/offline/RunTests.ps1
Comment thread tests/offline/Health.Tests.ps1
Comment thread .github/prompts/add-sdn-function.prompt.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 15, 2026 21:57
@arudell
arudell enabled auto-merge (squash) July 15, 2026 21:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 40 changed files in this pull request and generated 2 comments.

Comment on lines +19 to +23
It "Detects Failed provisioning state (triggers FAIL in health function)" {
$servers = $Global:PesterOfflineTests.SdnApiResources['servers']
$failed = @($servers | Where-Object { $_.properties.provisioningState -eq 'Failed' })
$failed.Count | Should -Be 1
$failed[0].resourceId | Should -Be "DVLAB-S1-N04"
Comment on lines +128 to +132
It "Would detect duplicates if present" {
$testData = @(
[PSCustomObject]@{ properties = @{ privateMacAddress = "001DD8070001" } }
[PSCustomObject]@{ properties = @{ privateMacAddress = "001DD8070002" } }
[PSCustomObject]@{ properties = @{ privateMacAddress = "001DD8070001" } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants