Skip to content

fix(tests): mock Install-Dotnet in DotnetSdk install test#178

Merged
HeyItsGilbert merged 2 commits into
mainfrom
fix/dotnetsdk-test-mock-install-dotnet
May 16, 2026
Merged

fix(tests): mock Install-Dotnet in DotnetSdk install test#178
HeyItsGilbert merged 2 commits into
mainfrom
fix/dotnetsdk-test-mock-install-dotnet

Conversation

@HeyItsGilbert
Copy link
Copy Markdown
Member

Summary

  • The DotnetSdk Type > Installs Dependency > Installs the .NET Core SDK to the specified directory test was an accidental integration test — it mocked Test-Dotnet but left Install-Dotnet unmocked, causing it to invoke the real dotnet-install script on CI runners.
  • The real installer requires network access and writes to a relative .dotnet path that doesn't exist on runners, so Test-Path '.dotnet' always returned $false.
  • Fix: add a Mock Install-Dotnet and replace the filesystem assertion with Should -Invoke Install-Dotnet -Times 1 -Exactly with a $InstallDir parameter filter.

Test plan

  • Tests/PSModuleGallery.Type.Tests.ps1 — 89 tests, all pass locally
  • The fixed test now asserts behavior (Install-Dotnet is called with the right directory) rather than side-effects (a real directory was created)

🤖 Generated with Claude Code

The test was calling the real dotnet-install script, which requires
network access and produces no local artifacts on CI runners. Replace
the filesystem assertion with a Should -Invoke check against a proper
Install-Dotnet mock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 16, 2026 16:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a test in Tests/PSModuleGallery.Type.Tests.ps1 that was inadvertently acting as an integration test by invoking the real dotnet-install script. The fix mocks Install-Dotnet and replaces a filesystem-based assertion with a Should -Invoke check on the mock.

Changes:

  • Add Mock Install-Dotnet alongside the existing Mock Test-Dotnet.
  • Replace Test-Path $script:SavePath | Should -BeTrue with Should -Invoke Install-Dotnet using a $InstallDir parameter filter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Test Results

    4 files  ±0     68 suites  ±0   2m 8s ⏱️ +15s
1 187 tests ±0  1 099 ✅ +5  88 💤 ±0  0 ❌  - 5 
1 440 runs  ±0  1 350 ✅ +5  90 💤 ±0  0 ❌  - 5 

Results for commit 801efe3. ± Comparison against base commit 6d4682b.

♻️ This comment has been updated with latest results.

@HeyItsGilbert HeyItsGilbert merged commit 83d7ab1 into main May 16, 2026
6 checks passed
@HeyItsGilbert HeyItsGilbert deleted the fix/dotnetsdk-test-mock-install-dotnet branch May 16, 2026 16:24
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.

2 participants