- Notifications
You must be signed in to change notification settings - Fork3.1k
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:
Dependency Consolidation: We already use
stretchr/testifyfor assertions (assertandrequire). Usingtestify/mockwould consolidate our testing dependencies.Interface-based Mocking:
testify/mockencourages interface-based mocking, which leads to better separation of concerns and more flexible test design.Maintenance & Activity:
stretchr/testifyis one of the most widely used Go testing libraries with active maintenance.Type Safety: Interface-based mocking provides compile-time type checking, whereas HTTP-level mocking relies on runtime matching.
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
- Define interfaces for GitHub client operations (if not already present)
- Create mock implementations using
testify/mock - Update the codebase to depend on interfaces rather than concrete clients
Phase 2: Migrate Tests Incrementally
- Start with a single test file to establish patterns
- Create helper functions for common mock setups
- Migrate remaining test files one at a time
- Remove
go-github-mockdependency 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
- stretchr/testify documentation
- Current testing guidelines:
docs/testing.md