Skip to content

Replace duplicated mockEnvProvider test types with shared environment providers#2014

Open
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/improve-tests-95b28963
Open

Replace duplicated mockEnvProvider test types with shared environment providers#2014
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/improve-tests-95b28963

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 9, 2026

Add MapEnvProvider and NoEnvProvider to pkg/environment for use in tests, replacing 6 nearly identical mockEnvProvider implementations scattered across test files.

  • MapEnvProvider wraps a map[string]string for test env lookups
  • NoEnvProvider always returns ("", false) for no-env-available cases
  • Remove ~70 lines of duplicated mock boilerplate from 7 test files

Changed files

  • pkg/environment/env.go — add MapEnvProvider and NoEnvProvider
  • pkg/config/auto_test.go — use shared providers
  • pkg/config/sources_test.go — use shared providers
  • pkg/runtime/model_switcher_test.go — use shared providers
  • pkg/model/provider/rulebased/client_test.go — use shared providers
  • pkg/model/provider/custom_provider_test.go — use shared providers
  • pkg/model/provider/bedrock/client_test.go — use shared providers
  • pkg/model/provider/openai/api_type_test.go — use shared providers

@dgageot dgageot requested a review from a team as a code owner March 9, 2026 18:04
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

🟢 Review: COMMENT

Assessment: 🟢 APPROVE

Summary

No bugs found in the changed code. This PR successfully consolidates duplicated test mock code into shared, reusable test helpers.

Changes reviewed:

  • Added MapEnvProvider and NoEnvProvider to pkg/environment/env.go — both correctly implement the Provider interface with proper nil safety
  • Removed ~70 lines of duplicated mockEnvProvider implementations from 7 test files
  • All test conversions maintain identical behavior by replacing local mocks with calls to the new shared constructors
  • Dependency updates in go.mod/go.sum are routine version bumps

The code is clean, type-safe, and improves maintainability by eliminating test code duplication. ✅

@dgageot dgageot force-pushed the board/improve-tests-95b28963 branch from 64d3d45 to 4828383 Compare March 9, 2026 18:06
… providers

Add MapEnvProvider and NoEnvProvider to pkg/environment for use in tests,
replacing 6 nearly identical mockEnvProvider implementations scattered
across test files.

- MapEnvProvider wraps a map[string]string for test env lookups
- NoEnvProvider always returns ("", false) for no-env-available cases
- Remove ~70 lines of duplicated mock boilerplate from 7 test files

Assisted-By: docker-agent
@dgageot dgageot force-pushed the board/improve-tests-95b28963 branch from 4828383 to 30cfb66 Compare March 9, 2026 18:07
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.

1 participant