githubtest

package
v0.0.0-...-58f053a Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githubtest provides an in-memory GitHub server for tests.

Index

Constants

View Source
const Access = "fixture-only-token-not-a-real-credential"

Access is the only token the fake accepts; it is not a real credential.

View Source
const RepoID int64 = 41

RepoID is the numeric identity of the fixture repository.

Variables

This section is empty.

Functions

func SHA

func SHA(s string) string

SHA returns the deterministic fake object ID for s.

Types

type Commit

type Commit struct{ Tree, Parent string }

Commit is a fake commit: the tree it names and its parent.

type Fake

type Fake struct {
	Mu           sync.Mutex
	Private      bool
	Denied       bool
	Fail         bool
	Reject       bool
	LoseResponse bool
	AfterCommit  func()
	Head         string
	Counter      int
	Writes       int
	BlobWrites   int
	Blobs        map[string][]byte
	Trees        map[string]map[string]string
	Commits      map[string]Commit
	Server       *httptest.Server
	Force        bool
	Name         string
	// Renamed is the repository's previous name after a rename on GitHub:
	// requests for it answer with a redirect, as GitHub does.
	Renamed string
	RepoID  int64
}

Fake is an in-memory GitHub REST and GraphQL server for tests. Its exported fields are fixture knobs; change them inside Modify.

func New

func New(t *testing.T, files map[string]string) *Fake

New starts a fake GitHub server serving files as its first commit.

func (*Fake) Advance

func (f *Fake) Advance(files map[string]string)

Advance records a new commit whose tree holds exactly files.

func (*Fake) Client

func (f *Fake) Client() *github.Client

Client returns a GitHub client that talks to this fake server.

func (*Fake) Contents

func (f *Fake) Contents() map[string]string

Contents returns the files at the current head.

func (*Fake) Modify

func (f *Fake) Modify(fn func())

Modify runs fn while holding the fake's lock.

func (*Fake) Serve

func (f *Fake) Serve(w http.ResponseWriter, r *http.Request)

Serve answers the GitHub API requests the client makes.

func (*Fake) WriteCount

func (f *Fake) WriteCount() int

WriteCount returns the number of write requests served.

Jump to

Keyboard shortcuts

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