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

fakemeshstack

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package fakemeshstack stands in for one meshStack: its API, its Keycloak and its API docs.

Its main consumer is the demo in docs/demo, which records the CLI against it. Tests use it rarely, as the rule "Test against a live meshStack" in AGENTS.md says.

It serves only what its callers need. A test that needs another answer sets it with Server.Route, so that this package does not grow into a meshStack simulator.

Index

Constants

View Source
const (
	ApiDocsPath = "/api/meshstack-openapi-docs.json"
)
View Source
const DefaultVersion = "2026.39.0"

DefaultVersion is at least client.MinMeshStackVersion, or the CLI refuses the backend.

View Source
const Token = "eyJhbGciOiJub25lIn0.eyJleHAiOjQxMDI0NDQ4MDB9." //nolint:gosec // G101: unsigned, it authorizes nothing but a fake meshStack

Token is an unsigned JWT that expires in 2100, so the CLI sends it rather than asking for a new one: a token without an expiry counts as expired. Every Server honors it.

Variables

View Source
var UserAgent = http.UserAgent{GitHubRepo: "meshcloud/fakemeshstack", Version: "test"}

UserAgent is for the client of a test, which no front end builds.

Functions

This section is empty.

Types

type ApiKey

type ApiKey struct {
	ClientId     string `json:"clientId"`
	ClientSecret string `json:"clientSecret"`
}

type Counts

type Counts struct {
	Logins        int64
	Authorized    int64
	RevokedTokens int64
	// UnknownTokens counts the 401s for a token the Server never minted, or for no token at all.
	UnknownTokens int64
}

type Options

type Options struct {
	// Version is what /mesh/info reports, DefaultVersion if empty.
	Version        string
	AdminWorkspace string
	// Issuer makes the Server the Keycloak of meshStack as well, under the path of the issuer. A
	// caller that serves the issuer's host elsewhere routes that host to the Server too.
	Issuer  string
	ApiKeys []ApiKey

	// The objects are marshaled on every request, so a test may change one between steps. A
	// workspace is found by metadata.name, every other object by metadata.uuid.
	Workspaces        []any
	BuildingBlocks    []any
	BuildingBlockRuns []any
	EventLogs         []any
	// PageSize is the largest page a list serves, defaultPageSize if 0, as meshStack caps the
	// size a client asks for.
	PageSize int

	TfStates map[TfState][]byte
	// ApiDocs is served at ApiDocsPath as last modified when New was called, so a conditional GET
	// gets a 304.
	ApiDocs []byte
}

type Request

type Request struct {
	Method string
	Host   string
	URL    *url.URL
	Header gohttp.Header
	Body   []byte
}

type Server

type Server struct {
	// URL is set by Start, and empty for a Server that New made.
	URL string
	// contains filtered or unexported fields
}

func New

func New(options Options) *Server

func Start

func Start(t *testing.T, options Options) *Server

func (*Server) Counts

func (s *Server) Counts() Counts

func (*Server) MintToken

func (s *Server) MintToken(validFor time.Duration) string

func (*Server) RevokeNewestToken

func (s *Server) RevokeNewestToken() (revoked bool)

RevokeNewestToken revokes the newest token still honored, as that is the one a cache most likely holds, so revoking it makes a caller refresh.

No request may be in flight while this runs. An authorized client retries a 401 once, and the token it retries with can be one it took from the cache of another process, so revoking during a request can leave a 401 that nothing recovers from.

func (*Server) Route

func (s *Server) Route(pattern string, handler gohttp.HandlerFunc)

Route answers the requests that match pattern with handler, whatever token they carry, ahead of the Server's own answers. It replaces an earlier handler for the same pattern, and a nil handler removes it.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w gohttp.ResponseWriter, r *gohttp.Request)

func (*Server) TakeRequests

func (s *Server) TakeRequests() []Request

TakeRequests returns the requests since the last call.

func (*Server) TfState

func (s *Server) TfState(key TfState) []byte

type TfState

type TfState struct {
	Workspace, BuildingBlockUuid string
}

Jump to

Keyboard shortcuts

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