Documentation
¶
Overview ¶
Package githubtest provides test fixtures and mocks for testing code that uses the github package. This follows the Go standard library pattern (e.g., net/http/httptest).
Example usage:
func TestMyFunction(t *testing.T) {
client := githubtest.NewMockGraphQLClient()
client.SetCommitAncestry("MyOrg", "my-repo", "main", []string{"abc123", "def456"})
// Use the mock client in your tests
commits, err := client.GetCommitAncestry(ctx, "MyOrg", "my-repo", "main", 10)
if err != nil {
t.Fatal(err)
}
// Verify interactions
if len(client.GetCommitAncestryCalls) != 1 {
t.Error("expected one call to GetCommitAncestry")
}
}
Index ¶
- type GetCommitAncestryCall
- type MockGraphQLClient
- func (m *MockGraphQLClient) CallCount() int
- func (m *MockGraphQLClient) ClearCache()
- func (m *MockGraphQLClient) GetCommitAncestry(ctx context.Context, owner, repo, ref string, depth int) ([]string, error)
- func (m *MockGraphQLClient) LastCall() *GetCommitAncestryCall
- func (m *MockGraphQLClient) Reset()
- func (m *MockGraphQLClient) SetCommitAncestry(owner, repo, ref string, commits []string)
- func (m *MockGraphQLClient) SetError(err error)
- func (m *MockGraphQLClient) SetErrorFor(owner, repo, ref string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GetCommitAncestryCall ¶
GetCommitAncestryCall records a GetCommitAncestry call.
type MockGraphQLClient ¶
type MockGraphQLClient struct {
// CommitAncestry maps "owner/repo:ref" -> []string (commit SHAs from newest to oldest)
CommitAncestry map[string][]string
// Call tracking
GetCommitAncestryCalls []GetCommitAncestryCall
ClearCacheCalls int
// Error injection
GetCommitAncestryError error
// Conditional error injection per owner/repo:ref
GetCommitAncestryErrorFor map[string]error
// contains filtered or unexported fields
}
MockGraphQLClient is a mock implementation of the GitHub GraphQL client for testing. It provides configurable commit ancestry responses and error injection.
func NewMockGraphQLClient ¶
func NewMockGraphQLClient() *MockGraphQLClient
NewMockGraphQLClient creates a new MockGraphQLClient with initialized maps.
func (*MockGraphQLClient) CallCount ¶
func (m *MockGraphQLClient) CallCount() int
CallCount returns the total number of GetCommitAncestry calls.
func (*MockGraphQLClient) ClearCache ¶
func (m *MockGraphQLClient) ClearCache()
ClearCache clears any cached data.
func (*MockGraphQLClient) GetCommitAncestry ¶
func (m *MockGraphQLClient) GetCommitAncestry( ctx context.Context, owner, repo, ref string, depth int, ) ([]string, error)
GetCommitAncestry retrieves the commit ancestry for a given ref. Returns commits from newest to oldest, limited by depth.
func (*MockGraphQLClient) LastCall ¶
func (m *MockGraphQLClient) LastCall() *GetCommitAncestryCall
LastCall returns the last GetCommitAncestry call, or nil if no calls were made.
func (*MockGraphQLClient) Reset ¶
func (m *MockGraphQLClient) Reset()
Reset clears all configured ancestry, errors, and call tracking.
func (*MockGraphQLClient) SetCommitAncestry ¶
func (m *MockGraphQLClient) SetCommitAncestry(owner, repo, ref string, commits []string)
SetCommitAncestry configures the commit ancestry for a specific owner/repo/ref. The commits should be ordered from newest to oldest.
func (*MockGraphQLClient) SetError ¶
func (m *MockGraphQLClient) SetError(err error)
SetError configures a global error to return for all GetCommitAncestry calls.
func (*MockGraphQLClient) SetErrorFor ¶
func (m *MockGraphQLClient) SetErrorFor(owner, repo, ref string, err error)
SetErrorFor configures an error to return for a specific owner/repo/ref.