platformtest

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Overview

Package platformtest fakes the platform on 127.0.0.1, for the tests of aicoded: its sign-in, token, revocation and whoami endpoints, and the builder API that aicoded publish, status, logs, traces and preview call.

Index

Constants

View Source
const (
	Org   = "acme"
	Email = "ana@acme.example"
)

The organisation of the fake, and the person who signs in to it.

Variables

This section is empty.

Functions

func Browser

func Browser() (browse func(address string), pages <-chan string)

Browser returns what a person does with the address of a sign-in in a browser: in the background, open it and follow the sign-in back to aicoded. The text of the last page it got, or its error, goes to pages.

func Watch

func Watch(out io.Writer, act func(address string)) io.Writer

Watch returns a writer for aicoded's output that goes on to out and calls act with the address of each sign-in in a browser that aicoded prints on a line of its own.

Types

type Declined

type Declined struct {
	By     string `json:"by"`
	Reason string `json:"reason"`
	At     string `json:"at"`
}

Declined is the approver's decline of a publish's approval card.

type Parent

type Parent struct {
	ID  string `json:"id"`
	SHA string `json:"sha"`
}

Parent is the publish before another.

type Platform

type Platform struct {
	// URL is its address, http://127.0.0.1:<port>.
	URL string
	// contains filtered or unexported fields
}

Platform is a fake platform. Everyone who signs in gets the scope app:create, and the scopes app:<id>:release:request, app:<id>:status, app:<id>:logs and app:<id>:preview of each app they own that is not archived, as they are when the token is issued.

func New

func New(t testing.TB) *Platform

New starts a fake platform, closed when the test ends.

func (*Platform) AddApp

func (p *Platform) AddApp(name, owner string)

AddApp adds the app name, which the person with the email owner owns.

func (*Platform) AddPublish

func (p *Platform) AddPublish(name string) string

AddPublish adds a publish of a new commit of the app name, as if it had been uploaded, and returns its id.

func (*Platform) Answers

func (p *Platform) Answers(answers ...Publish)

Answers sets the answers of /v1/publishes/get: about each publish, the first get gets the first answer, the next the next, and the last answer repeats. Each answer gets the publish's id, app, commit, summary and time. By default every publish has Passed.

func (*Platform) Archive

func (p *Platform) Archive(name string)

Archive archives the app name.

func (*Platform) Close

func (p *Platform) Close()

Close stops the platform, so that it can no longer be reached.

func (*Platform) DeviceAnswer

func (p *Platform) DeviceAnswer(edit func(map[string]any))

DeviceAnswer lets edit change the answer of /oauth/device before it is sent.

func (*Platform) DeviceError

func (p *Platform) DeviceError(code string)

DeviceError answers every poll of a device sign-in with the error code.

func (*Platform) ExpiresIn

func (p *Platform) ExpiresIn(seconds int)

ExpiresIn sets the lifetime of the access tokens it issues, in seconds.

func (*Platform) NewAppLimit

func (p *Platform) NewAppLimit(n int)

NewAppLimit sets how many apps a person may create a day; 10 by default.

func (*Platform) Pending

func (p *Platform) Pending(n int)

Pending makes a device sign-in answer n polls with authorization_pending before it succeeds.

func (*Platform) Preview

func (p *Platform) Preview(name string) (string, bool)

Preview returns the publish the preview of the app name runs, and whether one runs.

func (*Platform) Reads

func (p *Platform) Reads() []string

Reads returns the reads of telemetry the fake answered, each its path and query, oldest first.

func (*Platform) RefreshError

func (p *Platform) RefreshError(status int, code string)

RefreshError answers every refresh with status and the RFC 6749 error code, or with a body that is not JSON when code is empty, and keeps the refresh token usable.

func (*Platform) Refuse

func (p *Platform) Refuse(code, description string)

Refuse ends every sign-in in the browser with an RFC 6749 error, as the platform does when it refuses the person.

func (*Platform) RefusePreview

func (p *Platform) RefusePreview(status int, errorCode, code, description string)

RefusePreview refuses the next start of a preview with status, the error errorCode, the framework's code and the description.

func (*Platform) RefuseTelemetry

func (p *Platform) RefuseTelemetry(status int, errorCode, code string)

RefuseTelemetry makes every read of telemetry answer status, the error errorCode and the framework's code, or, with status 0, answer again.

func (*Platform) RefuseUpload

func (p *Platform) RefuseUpload(status int, errorCode, code string)

RefuseUpload refuses the next upload, once it is read, with status, the error errorCode and, unless it is "", the framework's code.

func (*Platform) RejectTokens

func (p *Platform) RejectTokens(n int)

RejectTokens answers the next n requests to the builder API with 401 invalid_token, as the platform does for a token it does not accept, such as one sent from a computer whose clock is off.

func (*Platform) Requests

func (p *Platform) Requests(path string) int

Requests returns how many requests the builder API path, such as /v1/publishes/create, got.

func (*Platform) ResetPreviewData

func (p *Platform) ResetPreviewData()

ResetPreviewData makes the next start of a preview report that it reset the preview's data.

func (*Platform) Revoked

func (p *Platform) Revoked() []string

Revoked returns the tokens it was asked to revoke.

func (*Platform) SetMigrations

func (p *Platform) SetMigrations(name string, steps ...migrate.Step)

SetMigrations makes /v1/apps/migrations answer steps about the app name, as they are, from now on.

func (*Platform) SignIn

func (p *Platform) SignIn(t testing.TB)

SignIn keeps a sign-in to the fake in the test's home, as aicoded login does.

func (*Platform) StaleBase

func (p *Platform) StaleBase(name string, bases ...string)

StaleBase makes the next answers of /v1/apps/get about the app name give the bases, one each, in place of its base.

func (*Platform) Telemetry

func (p *Platform) Telemetry(path string, rows ...map[string]any)

Telemetry makes the read of path, such as /v1/apps/demo/logs, answer the rows whose env is the query's, whatever the rest of its query.

func (*Platform) TokenRequests

func (p *Platform) TokenRequests() int

TokenRequests returns how many requests its token endpoint got.

func (*Platform) Uploads

func (p *Platform) Uploads() []Upload

Uploads returns the publishes the fake took, oldest first.

type Problem

type Problem struct {
	Code    string `json:"code"`
	Pos     string `json:"pos"`
	Message string `json:"message"`
	Fix     string `json:"fix"`
	Docs    string `json:"docs"`
}

Problem is a problem the delivery pipeline found.

type Publish

type Publish struct {
	ID               string    `json:"id"`
	App              string    `json:"app"`
	SHA              string    `json:"sha"`
	Summary          string    `json:"summary"`
	Status           string    `json:"status"`
	Reason           string    `json:"reason,omitempty"`
	Created          string    `json:"created"`
	Ended            string    `json:"ended,omitempty"`
	Parent           *Parent   `json:"parent,omitempty"`
	HistoryRewritten bool      `json:"history_rewritten"`
	Checks           string    `json:"checks"`
	Steps            []Step    `json:"steps"`
	Problems         []Problem `json:"problems"`
	// Notes are left out when empty, as an older platform does.
	Notes    []Problem `json:"notes,omitempty"`
	Record   int       `json:"record,omitempty"`
	Release  *Release  `json:"release,omitempty"`
	Declined *Declined `json:"declined,omitempty"`
}

Publish is a publish as /v1/publishes/get answers it.

func Failed

func Failed(n, size int) Publish

Failed is the answer about a publish that failed with n problems, each with a message of size letters.

func Passed

func Passed() Publish

Passed is the answer about a publish that passed.

type Release

type Release struct {
	Tier    string    `json:"tier"`
	AppType string    `json:"app_type"`
	Reasons []Problem `json:"reasons"`
	State   string    `json:"state"`
	Reason  string    `json:"reason,omitempty"`
	Live    bool      `json:"live"`
	URL     string    `json:"url,omitempty"`
}

Release is the decision on releasing a publish and what became of it.

func Live added in v0.12.0

func Live(app string) *Release

Live is the decision on releasing a publish of app that is Pre-approved and live, at the address of app in production.

type Step

type Step struct {
	Name    string `json:"name"`
	Outcome string `json:"outcome"`
}

Step is a step of the delivery pipeline and its outcome.

func Steps

func Steps(checkout, modules, check, tests string) []Step

Steps returns the four steps, each with its outcome.

type Upload

type Upload struct {
	App, SHA, Summary, Migration string
	// MigrationSent is whether the upload's meta held the key migration.
	MigrationSent bool
	Bundle        []byte
}

Upload is a publish the fake took.

Jump to

Keyboard shortcuts

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