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

fakeapi

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package fakeapi is a token-authenticated HTTPS API for tests: a stand-in for a provider such as a CDN or analytics service.

Index

Constants

View Source
const (
	Good = "fake-good-token"
	// Rotated is a second valid token for the same account, as after a
	// person rotates their token at the provider.
	Rotated = "fake-rotated-token"
	// OtherAccount is a valid token for a different account.
	OtherAccount = "fake-other-account-token"
	OtherID      = "acct-2"
	NoScope      = "fake-noscope-token"
	Limited      = "fake-limited-token"
	Broken       = "fake-broken-token"
	NotJSON      = "fake-notjson-token"
	AccountID    = "acct-1"
	Label        = "Acme Production"
	// Good expires at Expiry; Rotated does not expire; BadExpiry reports an
	// expiry that is not a timestamp.
	Expiry    = "2027-01-15T00:00:00Z"
	BadExpiry = "fake-badexpiry-token"
)

Tokens with fixed behaviour. Any other token is rejected with 401.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API is a running fake API.

func Start

func Start(t testing.TB) *API

Start starts the API and stops it when the test ends.

func (*API) Manifest

func (a *API) Manifest() provider.Manifest

Manifest returns a manifest whose base URL is the API.

func (*API) Provider

func (a *API) Provider(t testing.TB) *apikey.Provider

Provider returns an apikey provider for the API.

func (*API) Restore

func (a *API) Restore(tok string)

Restore makes a revoked token valid again.

func (*API) Revoke

func (a *API) Revoke(tok string)

Revoke makes a token invalid from now on; Restore undoes it.

func (*API) Seen

func (a *API) Seen() []string

Seen returns the Authorization headers received on /data.

Jump to

Keyboard shortcuts

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