fakeactions

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package fakeactions is a stand-in for GitHub's Actions service.

It exists because "it needs a GitHub organization" was wrong, and believing it left the code that talks to GitHub the least tested thing in the repository. The vendored client tests itself exactly this way, so the approach is the upstream one rather than an invention.

What it buys is the class of bug that unit tests over billet's own types cannot reach. The worst defect in this project so far was calling AcquireJobs with ids taken from JobAssigned instead of JobAvailable: billet's types were self-consistent, every test passed, and the mistake existed only in the relationship between billet and the wire. A fake that speaks the wire catches it.

It is a real package rather than a _test.go file because two different test suites need it — the scale-set client's own, and the end-to-end one that runs the control plane, the node and a real container together. It has no production callers and must not acquire any.

IT IS DELIBERATELY NOT A SIMULATOR OF GITHUB'S BEHAVIOUR. It answers the handshake and serves whatever a test tells it to. Nothing here should be read as evidence of what the real service does; where billet depends on real behaviour, that behaviour was measured against the real API and written down where it is relied upon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JitConfigJSON

func JitConfigJSON(runnerID int, name, encoded string) map[string]any

JitConfigJSON is what generatejitconfig returns.

The encoded config is opaque to billet — it is handed to the runner verbatim — so a placeholder is honest here in a way that a hand-built runner config would not be.

func JobJSON

func JobJSON(messageType string, requestID int64, event string, labels ...string) map[string]any

JobJSON is one message inside a batch.

messageType is one of JobAvailable, JobAssigned, JobStarted or JobCompleted. The distinction that matters most is the first two: an AVAILABLE job is one billet may bid for, and an ASSIGNED job is one it has been given. Acquiring by the wrong one is the defect this whole fake was built to catch.

func ListJSON

func ListJSON(values ...map[string]any) map[string]any

ListJSON wraps values the way the service returns collections.

func MessageJSON

func MessageJSON(t *testing.T, id int, stats map[string]any, jobs ...map[string]any) map[string]any

MessageJSON is the envelope the long poll returns.

THE BODY IS A JSON STRING, not a nested object. That is the real wire format — the client json.Unmarshals `body` a second time — and a fake that nests the array instead produces a parse error that reads like billet's bug.

func ScaleSetJSON

func ScaleSetJSON(id int, name, group string, labels ...string) map[string]any

ScaleSetJSON is the shape the service returns for a scale set.

func SessionJSON

func SessionJSON(sessionID, owner string, set map[string]any, queueURL, queueToken string) map[string]any

SessionJSON is what the service returns when a listener opens a session.

The message queue URL points back at this same server, because a test that stood a second listener up somewhere else would be testing its own plumbing.

func StatisticsJSON

func StatisticsJSON(available, assigned int) map[string]any

StatisticsJSON is the capacity signal the service attaches to sessions and messages. Only the two fields billet reads are parameterised.

func WriteJSON

func WriteJSON(t *testing.T, w http.ResponseWriter, v any)

WriteJSON encodes a response body.

Types

type Request

type Request struct {
	Method string
	Path   string
	Query  string
	Body   string
}

Request is one call the client made, so a test can assert on what billet actually put on the wire rather than on what it meant to.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server is a fake Actions service, good enough to drive the REAL vendored client through a real HTTP round trip.

func New

func New(t *testing.T, handler http.HandlerFunc) *Server

New starts a fake service. The handler serves the scale-set API; the authentication handshake is answered here, because every test needs it and none of them are about it.

func (*Server) AdminToken

func (f *Server) AdminToken(t *testing.T) string

AdminToken mints the RS256 token the client reads an expiry out of.

func (*Server) Calls

func (f *Server) Calls(fragment string) []Request

Calls returns every request whose path contains the fragment, so an assertion can name the endpoint it cares about rather than an index.

func (*Server) PrivateKeyPEM

func (f *Server) PrivateKeyPEM() string

PrivateKeyPEM is the throwaway App key this server signs with, so a caller can build a client config that authenticates against it.

Jump to

Keyboard shortcuts

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