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

githubtest

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package githubtest provides an in-process fake of the GitHub REST endpoints Octomaton uses, for tests. It verifies App JWTs and installation tokens and records everything it is asked to do.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key() *rsa.PrivateKey

Key returns an RSA key shared by all tests in the process.

Types

type CheckRun

type CheckRun struct {
	ID          int64
	SuiteID     int64
	Repo        string
	Name        string
	HeadSHA     string
	Status      string
	Conclusion  string
	ExternalID  string
	DetailsURL  string
	Title       string
	Summary     string
	Text        string
	StartedAt   string
	CompletedAt string
	Actions     []map[string]any
	// Updates counts PATCH requests received for this check run.
	Updates int
}

CheckRun is a check run stored by the fake.

type IssueComment

type IssueComment struct {
	Repo   string
	Number int
	Body   string
}

IssueComment records a comment posted on an issue or pull request.

type PullRequest

type PullRequest struct {
	Number            int
	State             string
	Draft             bool
	HeadRef           string
	HeadSHA           string
	HeadRepo          string
	BaseRef           string
	BaseSHA           string
	Author            string
	AuthorAssociation string
}

PullRequest is a pull request served by the fake.

type Reaction

type Reaction struct {
	Repo      string
	CommentID int64
	Content   string
}

Reaction records a reaction added to a comment.

type Repository

type Repository struct {
	ID            int64
	Owner         string
	Name          string
	DefaultBranch string
	Archived      bool
}

Repository is an installation repository served by the fake.

type Server

type Server struct {
	*httptest.Server
	AppID int64

	// Files maps "owner/repo@ref:path" to file content.
	Files map[string]string
	// PullRequestFiles maps "owner/repo#number" to changed file names.
	PullRequestFiles map[string][]string
	// Comparisons maps "owner/repo:base...head" to changed file names.
	Comparisons map[string][]string
	// Permissions maps "owner/repo:login" to a permission level.
	Permissions map[string]string
	// TeamMembers maps "org/team-slug" to the logins of its active members.
	TeamMembers map[string][]string
	// contains filtered or unexported fields
}

Server is a fake GitHub API.

func NewServer

func NewServer(t testing.TB, appID int64) *Server

NewServer starts a fake GitHub API for appID; it is closed when the test ends.

func (*Server) AddCheckRun

func (s *Server) AddCheckRun(cr CheckRun) int64

AddCheckRun stores an existing check run and returns its ID.

func (*Server) AddFile

func (s *Server) AddFile(repo, ref, path, content string)

AddFile stores a file of repo ("owner/name") at ref.

func (*Server) AddInstallation

func (s *Server) AddInstallation(id int64, account string, repos ...Repository)

AddInstallation registers an installation of the App on an account with its repositories.

func (*Server) CheckRun

func (s *Server) CheckRun(id int64) (CheckRun, bool)

CheckRun returns a copy of the check run with the given ID.

func (*Server) CheckRuns

func (s *Server) CheckRuns() []CheckRun

CheckRuns returns copies of all check runs, ordered by ID.

func (*Server) Comments

func (s *Server) Comments() []IssueComment

Comments returns the comments posted.

func (*Server) Reactions

func (s *Server) Reactions() []Reaction

Reactions returns the reactions added to comments.

func (*Server) Requests

func (s *Server) Requests() []string

Requests returns "METHOD path" for every request received.

func (*Server) SetBranch

func (s *Server) SetBranch(repo, branch, sha string)

SetBranch points a branch of repo at sha ("" deletes it).

func (*Server) SetComparison

func (s *Server) SetComparison(repo, base, head string, files []string)

SetComparison sets the files changed between base and head.

func (*Server) SetFailFiles

func (s *Server) SetFailFiles(fail bool)

SetFailFiles makes content requests fail with HTTP 500.

func (*Server) SetFailTokens

func (s *Server) SetFailTokens(fail func(TokenRequest) bool)

SetFailTokens makes token requests for which fail returns true fail with HTTP 422.

func (*Server) SetPermission

func (s *Server) SetPermission(repo, login, level string)

SetPermission sets login's permission level on repo.

func (*Server) SetPullRequest

func (s *Server) SetPullRequest(repo string, pr PullRequest)

SetPullRequest stores a pull request of repo.

func (*Server) SetPullRequestFiles

func (s *Server) SetPullRequestFiles(repo string, number int, files []string)

SetPullRequestFiles sets the files changed by a pull request.

func (*Server) SuiteID

func (s *Server) SuiteID(repo, sha string) int64

SuiteID returns the check suite of repo's commit sha.

func (*Server) TokenRequests

func (s *Server) TokenRequests() []TokenRequest

TokenRequests returns the installation token requests received.

type TokenRequest

type TokenRequest struct {
	InstallationID int64
	RepositoryIDs  []int64
	Permissions    map[string]string
}

TokenRequest records a POST /app/installations/{id}/access_tokens call.

Jump to

Keyboard shortcuts

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