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
- func Browser() (browse func(address string), pages <-chan string)
- func Watch(out io.Writer, act func(address string)) io.Writer
- type Declined
- type Parent
- type Platform
- func (p *Platform) AddApp(name, owner string)
- func (p *Platform) AddPublish(name string) string
- func (p *Platform) Answers(answers ...Publish)
- func (p *Platform) Archive(name string)
- func (p *Platform) Close()
- func (p *Platform) DeviceAnswer(edit func(map[string]any))
- func (p *Platform) DeviceError(code string)
- func (p *Platform) ExpiresIn(seconds int)
- func (p *Platform) NewAppLimit(n int)
- func (p *Platform) Pending(n int)
- func (p *Platform) Preview(name string) (string, bool)
- func (p *Platform) Reads() []string
- func (p *Platform) RefreshError(status int, code string)
- func (p *Platform) Refuse(code, description string)
- func (p *Platform) RefusePreview(status int, errorCode, code, description string)
- func (p *Platform) RefuseTelemetry(status int, errorCode, code string)
- func (p *Platform) RefuseUpload(status int, errorCode, code string)
- func (p *Platform) RejectTokens(n int)
- func (p *Platform) Requests(path string) int
- func (p *Platform) ResetPreviewData()
- func (p *Platform) Revoked() []string
- func (p *Platform) SetMigrations(name string, steps ...migrate.Step)
- func (p *Platform) SignIn(t testing.TB)
- func (p *Platform) StaleBase(name string, bases ...string)
- func (p *Platform) Telemetry(path string, rows ...map[string]any)
- func (p *Platform) TokenRequests() int
- func (p *Platform) Uploads() []Upload
- type Problem
- type Publish
- type Release
- type Step
- type Upload
Constants ¶
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 ¶
Types ¶
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 (*Platform) AddPublish ¶
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 ¶
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) Close ¶
func (p *Platform) Close()
Close stops the platform, so that it can no longer be reached.
func (*Platform) DeviceAnswer ¶
DeviceAnswer lets edit change the answer of /oauth/device before it is sent.
func (*Platform) DeviceError ¶
DeviceError answers every poll of a device sign-in with the error code.
func (*Platform) ExpiresIn ¶
ExpiresIn sets the lifetime of the access tokens it issues, in seconds.
func (*Platform) NewAppLimit ¶
NewAppLimit sets how many apps a person may create a day; 10 by default.
func (*Platform) Pending ¶
Pending makes a device sign-in answer n polls with authorization_pending before it succeeds.
func (*Platform) Preview ¶
Preview returns the publish the preview of the app name runs, and whether one runs.
func (*Platform) Reads ¶
Reads returns the reads of telemetry the fake answered, each its path and query, oldest first.
func (*Platform) RefreshError ¶
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 ¶
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 ¶
RefusePreview refuses the next start of a preview with status, the error errorCode, the framework's code and the description.
func (*Platform) RefuseTelemetry ¶
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 ¶
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 ¶
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 ¶
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) SetMigrations ¶
SetMigrations makes /v1/apps/migrations answer steps about the app name, as they are, from now on.
func (*Platform) SignIn ¶
SignIn keeps a sign-in to the fake in the test's home, as aicoded login does.
func (*Platform) StaleBase ¶
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 ¶
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 ¶
TokenRequests returns how many requests its token endpoint got.
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.
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.