Chore: Add testify-based HTTP mocking infrastructure and pilot migration#1606
Merged
Chore: Add testify-based HTTP mocking infrastructure and pilot migration#1606
Conversation
…st.go - Add MockHTTPClientWithHandlers helper function for HTTP-level mocking - Add path pattern matching support for GitHub API endpoints - Migrate pkg/github/git_test.go from go-github-mock to new infrastructure - Keep go-github-mock dependency for now (other files still use it) Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
- Migrate pkg/github/code_scanning_test.go to new infrastructure - Add comprehensive migration documentation in docs/testing-migration.md - Fix linter warning in helper_test.go - All tests and lint checks pass - 2 of 16 test files migrated, 14 remaining for incremental migration Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
- Remove unused OnAny method - Extract executeHandler helper to eliminate code duplication - Consolidate MockHTTPClientWithHandler to use MockHTTPClientWithHandlers - Simplify transport implementation (single multiHandlerTransport) - All tests and lint checks pass Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Replace go-github-mock with stretchr/testify/mock
Chore: Add testify-based HTTP mocking infrastructure and pilot migration
Dec 15, 2025
Contributor
|
@copilot remove this file - |
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
Contributor
Author
SamMorrowDrums
previously approved these changes
Dec 15, 2025
Collaborator
SamMorrowDrums
left a comment
There was a problem hiding this comment.
I like this, but is there value in defining github API route constances somewhere and sharing them versus writing them out per test?
Maybe, just a passing thought. The new pattern is otherwise clean and nice I feel.
JoannaaKL
reviewed
Dec 15, 2025
- Add mock import to code_scanning_test.go and git_test.go - Replace hardcoded paths with mock.GetRepos*.Pattern references - Ensures consistency with existing test patterns and easier maintenance Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
JoannaaKL
reviewed
Dec 15, 2025
…hub-mock - Add endpoint pattern constants to helper_test.go - Update code_scanning_test.go to use new constants - Update git_test.go to use new constants - Removes dependency on go-github-mock endpoint patterns - Prepares for eventual removal of go-github-mock dependency Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
SamMorrowDrums
approved these changes
Dec 16, 2025
JoannaaKL
approved these changes
Dec 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1492
Description
Implements Phase 1 and begins Phase 2 of migrating test infrastructure from
migueleliasweb/go-github-mocktostretchr/testify-based HTTP mocking. Consolidates testing dependencies while establishing patterns for incremental migration of remaining test files.Migration Status: 2 of 16 test files migrated (454 lines), 14 files remaining (~14,210 lines).
Changes
New HTTP Mocking Infrastructure (
pkg/github/helper_test.go)MockHTTPClientWithHandlers: Route-based HTTP client mocking with GitHub API path patterns{owner},{repo},{tree}wildcards for flexible endpoint matchingexecuteHandler: Eliminates response creation duplication across transport implementationshelper_test.go:GetReposByOwnerByRepoGetReposGitTreesByOwnerByRepoByTreeGetReposCodeScanningAlertsByOwnerByRepoGetReposCodeScanningAlertsByOwnerByRepoByAlertNumberMigrated Test Files
pkg/github/git_test.go(196 lines) - pilot migration, simplest filepkg/github/code_scanning_test.go(258 lines) - demonstrates query parameter validationBoth test files now use locally-defined endpoint pattern constants instead of hardcoded paths for better maintainability and consistency.
Dependencies
github.com/stretchr/objx(required by testify/mock)go-github-mockuntil full migration complete (will be removed in future PRs)Tradeoffs
Partial migration over full replacement: Migrated 2 files to establish infrastructure and patterns rather than all 16 files. Reduces PR scope and risk while enabling future incremental work. Full migration deferred to subsequent PRs as outlined in issue.
HTTP-level mocking over interface-based: Maintains current architectural patterns (HTTP transport mocking) rather than introducing interface wrappers around GitHub client. Interface-based approach would require extensive production code changes; HTTP-level mocking achieves dependency consolidation goals with test-only changes.
Local constants over go-github-mock patterns: Defines endpoint pattern constants locally in this repo rather than reusing
go-github-mockpatterns. This enables eventual removal of thego-github-mockdependency while maintaining clean, maintainable test code.No migration documentation: Migration patterns are documented inline in test files and helper functions rather than in a separate documentation file to keep the PR focused on code changes.
Alternatives
sed/automated migration: Considered batch migration via scripting, but endpoint patterns vary significantly across test files (query params, error scenarios, pagination). Manual migration ensures correctness and provides learning for establishing robust patterns.
Remove go-github-mock immediately: Cannot remove dependency until all test files migrated. Interim state maintains both approaches until migration complete.
Reuse mock.EndpointPattern constants: Initially considered reusing existing
mock.EndpointPatternconstants fromgo-github-mock, but defining local constants better supports the goal of removing thego-github-mockdependency entirely.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.