Documentation
¶
Index ¶
- Constants
- func WithCommitData(owner, repo, sha string, additions, deletions int) func(M)
- func WithMergeConflictPR(owner, repo string, number int) func(M)
- type BuildOption
- type CallCounter
- type CompareBuildConfig
- type DiagnosticOption
- type M
- func Build(id string, opts ...BuildOption) M
- func CheckStepCompleted(conclusion string, opts ...func(M)) M
- func CheckStepInProgress() M
- func CheckStepNotStarted() M
- func CommitCompleted(conclusion string, opts ...func(M)) M
- func CommitInProgress() M
- func CommitNotStarted() M
- func CompletedTarget(owner, repo, sha string, additions, deletions int) M
- func Diagnostic(code, level, message string, opts ...DiagnosticOption) M
- func ErrorTarget(owner, repo, sha string, additions, deletions int) M
- func FatalTarget() M
- func InProgressTarget() M
- func MergeConflictTarget(owner, repo string, prNum int) M
- func NotStartedTarget() M
- func Page(data []M) M
- func Target(status string, commit M, opts ...TargetOption) M
- func WarningTarget(owner, repo, sha string, additions, deletions int) M
- type Mock
- func (m *Mock) Cleanup()
- func (m *Mock) CreateBuildFromTemplate(template *ProgressiveBuild) *ProgressiveBuild
- func (m *Mock) Diagnostics(id string) []M
- func (m *Mock) GetBuild(id string) *ProgressiveBuild
- func (m *Mock) GetGitRepo(owner, name string) (path, ref string, ok bool)
- func (m *Mock) RecordRequest(request RecordedRequest)
- func (m *Mock) Requests() []RecordedRequest
- func (m *Mock) ResetRequests()
- func (m *Mock) Server() http.Handler
- type MockOption
- func WithAutomaticDeviceAuth() MockOption
- func WithCompareBuild(cfg CompareBuildConfig) MockOption
- func WithDefaultCompareBuild() MockOption
- func WithDefaultOrg() MockOption
- func WithDefaultProject() MockOption
- func WithDeviceAuth(pendingCount int) MockOption
- func WithGitRepos() MockOption
- func WithOrg(org MockOrg) MockOption
- func WithProject(project MockProject) MockOption
- type MockOrg
- type MockProject
- type ProgressiveBuild
- type RecordedRequest
- type TargetOption
Constants ¶
const ( DefaultOrg = "acme-corp" DefaultProject = "acme-api" )
Variables ¶
This section is empty.
Functions ¶
func WithCommitData ¶
func WithMergeConflictPR ¶
Types ¶
type BuildOption ¶
type BuildOption func(M)
func WithConfigCommit ¶
func WithConfigCommit(sha string) BuildOption
func WithCreatedAt ¶
func WithCreatedAt(t time.Time) BuildOption
func WithTarget ¶
func WithTarget(name string, target M) BuildOption
type CallCounter ¶
type CallCounter struct {
// contains filtered or unexported fields
}
CallCounter is a thread-safe call counter.
func (*CallCounter) Increment ¶
func (c *CallCounter) Increment() int
type CompareBuildConfig ¶
type CompareBuildConfig struct {
Base M
Head M
PreviewBuild *ProgressiveBuild
}
CompareBuildConfig configures the POST /v0/builds/compare endpoint.
type DiagnosticOption ¶
type DiagnosticOption func(M)
func WithConfigRef ¶
func WithConfigRef(ref string) DiagnosticOption
func WithMore ¶
func WithMore(markdown string) DiagnosticOption
func WithOASRef ¶
func WithOASRef(ref string) DiagnosticOption
type M ¶
M is a shorthand for map[string]any, used throughout for JSON-serializable data.
func Build ¶
func Build(id string, opts ...BuildOption) M
Build creates a build with sensible defaults.
func CheckStepCompleted ¶
func CheckStepInProgress ¶
func CheckStepInProgress() M
func CheckStepNotStarted ¶
func CheckStepNotStarted() M
func CommitCompleted ¶
func CommitInProgress ¶
func CommitInProgress() M
func CommitNotStarted ¶
func CommitNotStarted() M
func CompletedTarget ¶
func Diagnostic ¶
func Diagnostic(code, level, message string, opts ...DiagnosticOption) M
func ErrorTarget ¶
func FatalTarget ¶
func FatalTarget() M
func InProgressTarget ¶
func InProgressTarget() M
func MergeConflictTarget ¶
func NotStartedTarget ¶
func NotStartedTarget() M
func Target ¶
func Target(status string, commit M, opts ...TargetOption) M
Target creates a build target with the given status and commit state. Lint, build, and test default to not_started.
func WarningTarget ¶
type Mock ¶
type Mock struct {
Builds []*ProgressiveBuild
Orgs []M
Projects []M
ProjectConfigs M
CompareBuild *CompareBuildConfig
AuthPendingCount int
// contains filtered or unexported fields
}
Mock holds all data for a mock Stainless API server.
func NewMock ¶
func NewMock(opts ...MockOption) *Mock
NewMock creates a new mock with the given options.
func (*Mock) CreateBuildFromTemplate ¶
func (m *Mock) CreateBuildFromTemplate(template *ProgressiveBuild) *ProgressiveBuild
func (*Mock) Diagnostics ¶
func (*Mock) GetBuild ¶
func (m *Mock) GetBuild(id string) *ProgressiveBuild
func (*Mock) GetGitRepo ¶
GetGitRepo returns the local git repo info for a given owner/name, if available.
func (*Mock) RecordRequest ¶
func (m *Mock) RecordRequest(request RecordedRequest)
func (*Mock) Requests ¶
func (m *Mock) Requests() []RecordedRequest
func (*Mock) ResetRequests ¶
func (m *Mock) ResetRequests()
type MockOption ¶
type MockOption func(*Mock)
MockOption configures a Mock via NewMock.
func WithAutomaticDeviceAuth ¶
func WithAutomaticDeviceAuth() MockOption
WithAutomaticDeviceAuth configures instant auth success (zero pending responses).
func WithCompareBuild ¶
func WithCompareBuild(cfg CompareBuildConfig) MockOption
WithCompareBuild enables the POST /v0/builds/compare endpoint.
func WithDefaultCompareBuild ¶
func WithDefaultCompareBuild() MockOption
WithDefaultCompareBuild adds a compare endpoint with a preview build.
func WithDefaultOrg ¶
func WithDefaultOrg() MockOption
WithDefaultOrg adds the default acme-corp organization.
func WithDefaultProject ¶
func WithDefaultProject() MockOption
WithDefaultProject adds the default acme-api project with 4 demo builds and config files.
func WithDeviceAuth ¶
func WithDeviceAuth(pendingCount int) MockOption
WithDeviceAuth sets how many "authorization_pending" responses the token endpoint returns before succeeding.
func WithGitRepos ¶
func WithGitRepos() MockOption
WithGitRepos creates local git repos for each target in the mock's builds. This enables the build_target_outputs endpoint to return file:// URLs that work with git fetch. Call Mock.Cleanup() when done to remove temp directories.
func WithProject ¶
func WithProject(project MockProject) MockOption
WithProject adds a project (and its builds) to the mock.
type MockProject ¶
type MockProject struct {
Name string // slug, required
DisplayName string // defaults to Name
Org string // defaults to first configured org's slug
Targets []string // defaults to ["typescript", "python", "go"]
Builds []*ProgressiveBuild // added to the mock's build list
Configs M // project config files
}
MockProject describes a project to register in the mock.
type ProgressiveBuild ¶
type ProgressiveBuild struct {
ID string
ConfigCommit string
Targets []string // target names in completion order
CompletedData map[string]M // final state per target
Diagnostics []M // diagnostics returned for this build
Delay time.Duration
StartTime time.Time
// contains filtered or unexported fields
}
ProgressiveBuild returns a build that fills in incrementally over time. Each target progresses through 7 phases:
not_started → codegen → committed → lint → build → test → completed
Target i begins its first phase at Delay*i, and each phase lasts Delay. So target i reaches "completed" at Delay*(i+6).
func (*ProgressiveBuild) Reset ¶
func (p *ProgressiveBuild) Reset()
Reset restarts the progression from now.
func (*ProgressiveBuild) Snapshot ¶
func (p *ProgressiveBuild) Snapshot() M
Snapshot returns the build state at the current time. If StartTime is zero the build has not been activated yet and all targets are returned as not_started.
type RecordedRequest ¶
type TargetOption ¶
type TargetOption func(M)
func WithBuild ¶
func WithBuild(step M) TargetOption
func WithLint ¶
func WithLint(step M) TargetOption
func WithTest ¶
func WithTest(step M) TargetOption