mockstainless

package
v0.1.0-alpha.87 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOrg     = "acme-corp"
	DefaultProject = "acme-api"
)

Variables

This section is empty.

Functions

func WithCommitData

func WithCommitData(owner, repo, sha string, additions, deletions int) func(M)

func WithMergeConflictPR

func WithMergeConflictPR(owner, repo string, number int) func(M)

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

type M = map[string]any

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 CheckStepCompleted(conclusion string, opts ...func(M)) M

func CheckStepInProgress

func CheckStepInProgress() M

func CheckStepNotStarted

func CheckStepNotStarted() M

func CommitCompleted

func CommitCompleted(conclusion string, opts ...func(M)) M

func CommitInProgress

func CommitInProgress() M

func CommitNotStarted

func CommitNotStarted() M

func CompletedTarget

func CompletedTarget(owner, repo, sha string, additions, deletions int) M

func Diagnostic

func Diagnostic(code, level, message string, opts ...DiagnosticOption) M

func ErrorTarget

func ErrorTarget(owner, repo, sha string, additions, deletions int) M

func FatalTarget

func FatalTarget() M

func InProgressTarget

func InProgressTarget() M

func MergeConflictTarget

func MergeConflictTarget(owner, repo string, prNum int) M

func NotStartedTarget

func NotStartedTarget() M

func Page

func Page(data []M) M

Page wraps data in a paginated response envelope.

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

func WarningTarget(owner, repo, sha string, additions, deletions int) M

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) Cleanup

func (m *Mock) Cleanup()

Cleanup removes temporary resources (git repos).

func (*Mock) CreateBuildFromTemplate

func (m *Mock) CreateBuildFromTemplate(template *ProgressiveBuild) *ProgressiveBuild

func (*Mock) Diagnostics

func (m *Mock) Diagnostics(id string) []M

func (*Mock) GetBuild

func (m *Mock) GetBuild(id string) *ProgressiveBuild

func (*Mock) GetGitRepo

func (m *Mock) GetGitRepo(owner, name string) (path, ref string, ok bool)

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()

func (*Mock) Server

func (m *Mock) Server() http.Handler

Server returns an http.Handler serving the mock's endpoints.

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 WithOrg

func WithOrg(org MockOrg) MockOption

WithOrg adds an organization to the mock.

func WithProject

func WithProject(project MockProject) MockOption

WithProject adds a project (and its builds) to the mock.

type MockOrg

type MockOrg struct {
	Name        string // slug, required
	DisplayName string // defaults to Name
}

MockOrg describes an organization to register in 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 RecordedRequest struct {
	Method   string
	Path     string
	RawQuery string
	Body     string
}

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

Jump to

Keyboard shortcuts

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