mockgithub

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mockgithub provides an in-process GitHub API mock for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ts *httptest.Server) (*github.Client, error)

NewClient creates a github.Client that talks to the given TLS test server.

func Usage

func Usage(addr string) string

Usage prints instructions for using the mock server.

Types

type Dataset

type Dataset struct {
	Org       string
	Teams     []github.Team
	Repos     []github.Repository
	Workflows map[string][]github.Workflow    // "owner/repo" → workflows
	Runs      map[string][]github.WorkflowRun // "owner/repo/<workflowID>" → runs
}

Dataset holds all mock GitHub data served by the Server.

func LoadFromDeploymentCSV

func LoadFromDeploymentCSV(path string) (*Dataset, error)

LoadFromDeploymentCSV loads a Dataset from a GitHub deployment throughput CSV. The CSV format is: period_start,period_end,count (output of --save-raw-data). Each row's count is expanded into individual workflow runs spread across the period.

func NewDataset

func NewDataset(org, teamSlug, owner, repo string) *Dataset

NewDataset creates a Dataset with a single org/team/repo/workflow.

func RealisticDataset

func RealisticDataset() *Dataset

RealisticDataset returns ~12 weeks of deployment data for two repos, anchored to the current time so it falls within any recent default date range.

func SmallDataset

func SmallDataset() *Dataset

SmallDataset returns a small deterministic dataset with ~3 weeks of deployments anchored to the current time, so it falls within any recent default date range.

func (*Dataset) AddRun

func (ds *Dataset) AddRun(owner, repo string, workflowID int64, run github.WorkflowRun)

AddRun adds a workflow run to the dataset.

type Server

type Server struct {
	Dataset     *Dataset
	MaxPageSize int
	// contains filtered or unexported fields
}

Server is a mock GitHub API server backed by a Dataset.

func New

func New(ds *Dataset) *Server

New creates a new mock GitHub server with the given dataset.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the server on the given address (e.g., ":8081").

func (*Server) Start

func (s *Server) Start() *httptest.Server

Start returns an httptest.Server for use in go tests.

type WorkflowRunBuilder

type WorkflowRunBuilder struct {
	// contains filtered or unexported fields
}

WorkflowRunBuilder provides a fluent API for constructing test workflow runs.

func NewRun

func NewRun(id int64) *WorkflowRunBuilder

NewRun starts building a new workflow run.

func (*WorkflowRunBuilder) Build

Build returns the constructed WorkflowRun.

func (*WorkflowRunBuilder) WithBranch

func (b *WorkflowRunBuilder) WithBranch(branch string) *WorkflowRunBuilder

func (*WorkflowRunBuilder) WithConclusion

func (b *WorkflowRunBuilder) WithConclusion(c string) *WorkflowRunBuilder

func (*WorkflowRunBuilder) WithName

func (b *WorkflowRunBuilder) WithName(name string) *WorkflowRunBuilder

func (*WorkflowRunBuilder) WithTimes

func (b *WorkflowRunBuilder) WithTimes(createdAt, updatedAt time.Time) *WorkflowRunBuilder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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