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

clitest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package clitest provides an in-memory fake of a Backyard server's client surface (the deploy gateway protocol of SPEC §7, the CLI login handoff of §8.3 and POST /__backyard/api/tokens) for testing the CLI and the MCP server without running the real server.

Index

Constants

View Source
const GatewayPath = "/__backyard/api/deploy"

GatewayPath is where the fake mounts the gateway (as the real server).

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

type Gateway struct {
	Server *httptest.Server
	// URL is the server root (hub URL).
	URL string
	// Info is returned by GET /info (PublicURL and GatewayURL are filled
	// in by NewGateway).
	Info deploy.Info
	// Tokens maps valid bearer tokens to users.
	Tokens map[string]identity.User
	// Anonymous accepts requests without a token (as a guest).
	Anonymous bool
	// HTML makes every gateway route answer with an HTML login page, like
	// an identity-aware proxy in front of the server.
	HTML bool
	// CLIToken is issued by /__backyard/auth/cli (with CLITokenExpiry).
	CLIToken       string
	CLITokenExpiry time.Time
	// MintedToken is returned by POST /__backyard/api/tokens.
	MintedToken string
	// contains filtered or unexported fields
}

Gateway is a fake Backyard server. Configure its exported fields before issuing requests; use Lock/Unlock (or the helpers) when reading state while requests may be in flight.

func NewGateway

func NewGateway(t testing.TB) *Gateway

NewGateway starts a fake server; it is closed when the test ends.

func (*Gateway) AddSite

func (g *Gateway) AddSite(name string, files map[string]string, updatedBy string)

AddSite stores a site with files (path → content), last deployed by updatedBy.

func (*Gateway) AddToken

func (g *Gateway) AddToken(token string, u identity.User)

AddToken registers a valid bearer token (safe while requests are in flight).

func (*Gateway) Count

func (g *Gateway) Count(method, pathSuffix string) int

Count returns how many recorded requests match method and path suffix.

func (*Gateway) GatewayURL

func (g *Gateway) GatewayURL() string

GatewayURL returns the embedded gateway URL.

func (*Gateway) Meta

func (g *Gateway) Meta(name string) (sites.Meta, bool)

Meta returns a stored site's metadata.

func (*Gateway) Requests

func (g *Gateway) Requests() []Request

Requests returns the recorded requests.

func (*Gateway) SetFileRaw

func (g *Gateway) SetFileRaw(site, path string, content []byte)

SetFileRaw stores a file under any path (even an invalid one), to test client-side path validation.

func (*Gateway) SiteFiles

func (g *Gateway) SiteFiles(name string) map[string]string

Site returns a copy of a stored site's files (nil when missing).

func (*Gateway) SiteURL

func (g *Gateway) SiteURL(site string) string

SiteURL returns the path-mode URL of a site.

func (*Gateway) TokenRequests

func (g *Gateway) TokenRequests() []TokenRequest

TokenRequests returns the recorded token-mint requests.

func (*Gateway) Uploads

func (g *Gateway) Uploads() int

Uploads returns the number of PUT uploads received.

type Request

type Request struct {
	Method string
	Path   string
	Auth   string
	CSRF   string
	Query  url.Values
}

Request records one request received by the fake.

type Site

type Site struct {
	Meta  sites.Meta
	Files map[string][]byte
}

Site is a site stored by the fake.

type TokenRequest

type TokenRequest struct {
	Auth string
	Body map[string]any
}

TokenRequest records a POST /__backyard/api/tokens call.

Jump to

Keyboard shortcuts

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