Help us shape the future of Go! Take the 2026 Go Developer Survey

githubtest

package
v1.3.80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetCommitAncestryCall

type GetCommitAncestryCall struct {
	Owner string
	Repo  string
	Ref   string
	Depth int
}

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL