Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Chore: Add testify-based HTTP mocking infrastructure and pilot migration#1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoannaaKL merged 10 commits intomainfromcopilot/replace-go-github-mock-again
Dec 17, 2025

Conversation

Copy link
Contributor

CopilotAI commentedDec 15, 2025
edited
Loading

Closes#1492

Description

Implements Phase 1 and begins Phase 2 of migrating test infrastructure frommigueleliasweb/go-github-mock tostretchr/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
    // Before: go-github-mockmock.NewMockedHTTPClient(mock.WithRequestMatch(mock.GetReposByOwnerByRepo,mockRepo),)// After: testify-based with local constantsMockHTTPClientWithHandlers(map[string]http.HandlerFunc{GetReposByOwnerByRepo:mockResponse(t,http.StatusOK,mockRepo),})
  • Path pattern matching: Supports{owner},{repo},{tree} wildcards for flexible endpoint matching
  • executeHandler: Eliminates response creation duplication across transport implementations
  • Local endpoint pattern constants: Defines GitHub API endpoint patterns as constants inhelper_test.go:
    • GetReposByOwnerByRepo
    • GetReposGitTreesByOwnerByRepoByTree
    • GetReposCodeScanningAlertsByOwnerByRepo
    • GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber

Migrated Test Files

  • pkg/github/git_test.go (196 lines) - pilot migration, simplest file
  • pkg/github/code_scanning_test.go (258 lines) - demonstrates query parameter validation

Both test files now use locally-defined endpoint pattern constants instead of hardcoded paths for better maintainability and consistency.

Dependencies

  • Addedgithub.com/stretchr/objx (required by testify/mock)
  • Retainedgo-github-mock until 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 reusinggo-github-mock patterns. This enables eventual removal of thego-github-mock dependency 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 existingmock.EndpointPattern constants fromgo-github-mock, but defining local constants better supports the goal of removing thego-github-mock dependency entirely.

Original prompt

This section details on the original issue you should resolve

<issue_title>Chore: replace migueleliasweb/go-github-mock with stretchr/testify/mock</issue_title>
<issue_description>### Describe the feature or problem you'd like to solve

The current test suite usesmigueleliasweb/go-github-mock for mocking GitHub REST API responses in unit tests. While this library has served us well, there are several reasons to consider replacing it withstretchr/testify/mock:

  1. Dependency Consolidation: We already usestretchr/testify for assertions (assert andrequire). Usingtestify/mock would consolidate our testing dependencies.

  2. Interface-based Mocking:testify/mock encourages interface-based mocking, which leads to better separation of concerns and more flexible test design.

  3. Maintenance & Activity:stretchr/testify is one of the most widely used Go testing libraries with active maintenance.

  4. Type Safety: Interface-based mocking provides compile-time type checking, whereas HTTP-level mocking relies on runtime matching.

  5. Reduced Dependencies: One less external dependency to maintain

Proposed solution

Replace HTTP-level mocking with interface-based mocking usingtestify/mock:

Phase 1: Create Mock Interfaces

  1. Define interfaces for GitHub client operations (if not already present)
  2. Create mock implementations usingtestify/mock
  3. Update the codebase to depend on interfaces rather than concrete clients

Phase 2: Migrate Tests Incrementally

  1. Start with a single test file to establish patterns
  2. Create helper functions for common mock setups
  3. Migrate remaining test files one at a time
  4. Removego-github-mock dependency when complete

Example Migration

Before (HTTP-level mocking):

mockedClient:=mock.NewMockedHTTPClient(mock.WithRequestMatch(mock.GetReposIssuesByOwnerByRepoByIssueNumber,mockIssue,    ),)client:=github.NewClient(mockedClient)

After (Interface-based mocking):

mockClient:=new(MockGitHubClient)mockClient.On("GetIssue",ctx,"owner","repo",42).Return(mockIssue,nil)

Related

<agent_instructions>You are working in the github/github-mcp-server repository.

  1. Understand the issue first

Read issue#1492 carefully, including comments.

Identify:

  • The expected behavior
  • The current behavior
  • Which MCP tools / code paths are affected
  • If anything is ambiguous, infer the most conservative and backward-compatible fix.
  1. Scope the change
    Keep the change minimal and focused on this issue.
    Avoid refactors unless strictly necessary.
    Do not change tool schemas or behavior unless required by the issue.

  2. Implement the fix

Make the required code changes.
Follow existing patterns in the codebase.
Ensure behavior is safe for agent usage (pagination, filtering, limits, auth).

  1. Run checks locally

Before opening the PR, run:

  • ./script/lint
  • ./script/test

If either command fails or cannot be run, explain why in the PR.

  1. Open a pull request

Open a PR from your branch to main.

Use the repository PR template and fill all sections.

Keep answers short and concrete.

When filling the PR template:

Summary: 1–2 sentences describing the fix

Why: Reference issue#1492

What changed: Bullet list of code changes

MCP impact: Explicitly state whether tools or APIs changed

Security / limits: Confirm considerations

Lint & tests: Check boxes based on what you ran

  1. Quality bar
    Code compiles
    Tests pass
    No unrelated changes
    PR description is complete and honest
    If something cannot be completed, clearly explain it in the PR description.</agent_instructions>

Comments on the Issue (you are@copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

CopilotAIand others added3 commitsDecember 15, 2025 14:39
…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 migrationCo-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 passCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
CopilotAI changed the title[WIP] Replace go-github-mock with stretchr/testify/mockChore: Add testify-based HTTP mocking infrastructure and pilot migrationDec 15, 2025
CopilotAI requested a review fromJoannaaKLDecember 15, 2025 14:53
@JoannaaKL
Copy link
Contributor

@copilot remove this file -docs/testing-migration.md. We don't want to commit it.

Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
Copy link
ContributorAuthor

@copilot remove this file -docs/testing-migration.md. We don't want to commit it.

Done inf4f426b

@JoannaaKLJoannaaKL marked this pull request as ready for reviewDecember 15, 2025 15:22
@JoannaaKLJoannaaKL requested a review froma team as acode ownerDecember 15, 2025 15:22
CopilotAI review requested due to automatic review settingsDecember 15, 2025 15:22
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

SamMorrowDrums
SamMorrowDrums previously approved these changesDec 15, 2025
Copy link
Collaborator

@SamMorrowDrumsSamMorrowDrums left a comment

Choose a reason for hiding this comment

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

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.

- 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 maintenanceCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
…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 dependencyCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
@JoannaaKLJoannaaKL merged commit5a42d7a intomainDec 17, 2025
16 checks passed
@JoannaaKLJoannaaKL deleted the copilot/replace-go-github-mock-again branchDecember 17, 2025 08:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@SamMorrowDrumsSamMorrowDrumsSamMorrowDrums approved these changes

+2 more reviewers

@Vysakh131101Vysakh131101Vysakh131101 left review comments

@JoannaaKLJoannaaKLJoannaaKL approved these changes

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Chore: replace migueleliasweb/go-github-mock with stretchr/testify/mock

4 participants

@JoannaaKL@SamMorrowDrums@Vysakh131101

[8]ページ先頭

©2009-2025 Movatter.jp