fakes

package
v0.7.186 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSSHKeypair added in v0.7.9

func GenerateSSHKeypair(t *testing.T) (keyFile string, pubKey ssh.PublicKey)

GenerateSSHKeypair generates an ed25519 keypair, writes the private and public key files to a temp directory, and returns the private key file path and the corresponding ssh.PublicKey.

func GenerateSSHKeypairAt added in v0.7.186

func GenerateSSHKeypairAt(t *testing.T, path string) ssh.PublicKey

GenerateSSHKeypairAt generates an ed25519 keypair at the given path (private key at path, public key at path+".pub") and returns the parsed public key. The destination directory is created if it does not exist.

Types

type Collaboration

type Collaboration struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	VCSType string `json:"vcs-type"`
	Slug    string `json:"slug"`
}

type CommandResponse added in v0.7.97

type CommandResponse struct {
	ID        string  `json:"id"`
	CreatedAt string  `json:"created_at"`
	EndedAt   *string `json:"ended_at,omitempty"`
	ExitCode  *int    `json:"exit_code,omitempty"`
	Outcome   *string `json:"outcome,omitempty"`
	Phase     string  `json:"phase"`
	SidecarID string  `json:"sidecar_id"`
}

type ExecResponse

type ExecResponse struct {
	CommandID string `json:"command_id"`
	PID       int    `json:"pid"`
	Stdout    string `json:"stdout"`
	Stderr    string `json:"stderr"`
	ExitCode  int    `json:"exit_code"`
	Signal    string `json:"signal,omitempty"`
}

type FakeAnthropic

type FakeAnthropic struct {
	http.Handler
	Recorder *recorder.RequestRecorder
	// contains filtered or unexported fields
}

FakeAnthropic serves canned responses for the Anthropic Messages API.

func NewFakeAnthropic

func NewFakeAnthropic(responses ...string) *FakeAnthropic

func (*FakeAnthropic) SetTokenLimitErrors

func (f *FakeAnthropic) SetTokenLimitErrors(n int)

SetTokenLimitErrors configures the fake to return n consecutive "prompt is too long" errors before returning normal responses.

type FakeCircleCI

type FakeCircleCI struct {
	http.Handler
	Recorder *recorder.RequestRecorder

	Collaborations  []Collaboration
	Projects        []Project
	Sidecars        []Sidecar
	Snapshots       []Snapshot
	RunResponse     *RunResponse
	AddKeyURL       string
	ExecResponse    *ExecResponse
	CommandResponse *CommandResponse
	RunStatusCode   int // override status code for trigger run endpoint

	// Per-endpoint status code overrides for testing error responses.
	CollaborationsStatusCode int    // override for GET /me/collaborations
	ListStatusCode           int    // override for GET /sidecar/instances
	CreateStatusCode         int    // override for POST /sidecar/instances
	CreateErrorAfter         int    // if > 0, fail creates after this many successes
	DeleteStatusCode         int    // override for DELETE /sidecar/instances/:id
	PruneStatusCode          int    // override for POST /sidecar/instances/prune
	ExecStatusCode           int    // override for POST /sidecar/instances/:id/exec
	ExecMessage              string // V3 error title when ExecStatusCode is set
	CommandOutputStatusCode  int    // override for GET /sidecar/commands/:id/output
	CommandOutputMessage     string // error message body when CommandOutputStatusCode is set
	// DropStreamsBeforeExit ends this many output streams after delivering their
	// output but before the terminal event, so client resume can be exercised.
	DropStreamsBeforeExit int
	// EmptyStreamsBeforeExit returns this many completely empty output responses
	// (status 200, no body) before serving the real stream. This simulates an
	// interrupted connection where no SSE frames arrive at all, which the client
	// must treat as a resume trigger rather than a failure.
	EmptyStreamsBeforeExit int
	AddKeyStatusCode       int             // override for POST /sidecar/instances/:id/ssh/add-key
	StaleIDs               map[string]bool // IDs that return 404 from the add-key endpoint
	NotFoundBeforeAddKey   map[string]int  // initial add-key calls that return 404 before succeeding
	OutdatedIDs            map[string]bool // IDs that return an out-of-date 410 from the add-key endpoint
	StaleAfterAddKey       map[string]int  // successful add-key calls allowed before an ID returns 404

	CreateSnapshotStatusCode int // override for POST /sidecar/snapshots
	GetSnapshotStatusCode    int // override for GET /sidecar/snapshots/:id
	ListSnapshotsStatusCode  int // override for GET /sidecar/snapshots
	GetCommandStatusCode     int // override for GET /sidecar/commands/:id
	CreateOrgStatusCode      int // override for POST /api/v2/organization

	// ExtraHeaders are added to every response. Use to inject Deprecation/Sunset
	// headers without changing individual handler logic.
	ExtraHeaders http.Header
	// contains filtered or unexported fields
}

FakeCircleCI serves canned responses for the CircleCI API.

func NewFakeCircleCI

func NewFakeCircleCI() *FakeCircleCI

func (*FakeCircleCI) ServeHTTP added in v0.7.124

func (f *FakeCircleCI) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP injects ExtraHeaders into every response before delegating to the embedded gin handler. Headers must be set before the first Write or WriteHeader call, which gin does internally — setting them here satisfies that ordering.

type FakeGitHub

type FakeGitHub struct {
	http.Handler
	Recorder *recorder.RequestRecorder
	// contains filtered or unexported fields
}

FakeGitHub serves canned responses for GitHub's GraphQL API.

func NewFakeGitHub

func NewFakeGitHub() *FakeGitHub

func (*FakeGitHub) SetOrgRepos

func (f *FakeGitHub) SetOrgRepos(resp string)

func (*FakeGitHub) SetOrgValidation

func (f *FakeGitHub) SetOrgValidation(resp string)

func (*FakeGitHub) SetRateLimit

func (f *FakeGitHub) SetRateLimit(resp string)

func (*FakeGitHub) SetRepoError

func (f *FakeGitHub) SetRepoError(repo string, resp string)

func (*FakeGitHub) SetReviewActivity

func (f *FakeGitHub) SetReviewActivity(repo string, resp string)

type Project

type Project struct {
	VCSType  string `json:"vcs_type"`
	Username string `json:"username"`
	Reponame string `json:"reponame"`
}

type RunResponse

type RunResponse struct {
	RunID      string `json:"runId,omitempty"`
	PipelineID string `json:"pipelineId,omitempty"`
}

type SSHServer added in v0.7.9

type SSHServer struct {
	// contains filtered or unexported fields
}

SSHServer is a WebSocket+SSH server for testing SSH-based sidecar interactions. It accepts a single authorized public key and records exec requests.

func NewSSHServer added in v0.7.9

func NewSSHServer(t *testing.T, authorizedKey ssh.PublicKey) *SSHServer

NewSSHServer starts a WebSocket+SSH server that accepts connections authenticated with authorizedKey. The server is shut down automatically when the test ends.

func NewSSHServerAcceptingAnyKey added in v0.7.186

func NewSSHServerAcceptingAnyKey(t *testing.T) *SSHServer

NewSSHServerAcceptingAnyKey starts a server like NewSSHServer but authorises whichever key the client presents. Use it when chunk generates the keypair itself, so the test cannot know the public key in advance. Pair it with RestrictToKey once the generated key is known.

func (*SSHServer) Addr added in v0.7.9

func (s *SSHServer) Addr() string

Addr returns the "host:port" address the server is listening on. sidecar.OpenSession stores this as Session.URL; toWebSocketURL converts it to ws://host:port/ssh/tunnel before dialling.

func (*SSHServer) Commands added in v0.7.9

func (s *SSHServer) Commands() []string

Commands returns a copy of all exec command strings received so far.

func (*SSHServer) EnvVars added in v0.7.57

func (s *SSHServer) EnvVars() map[string]string

EnvVars returns a copy of all environment variables received via "env" requests.

func (*SSHServer) Reset added in v0.7.122

func (s *SSHServer) Reset()

Reset clears the recorded commands so a test can assert on a fresh sync.

func (*SSHServer) RestrictToKey added in v0.7.186

func (s *SSHServer) RestrictToKey(authorizedKey ssh.PublicKey)

RestrictToKey narrows the server to accept only authorizedKey from now on. Keeping the same server (and so the same host key and address) lets a test first let chunk generate a keypair, then prove the private key chunk kept is the pair of the public key it registered.

func (*SSHServer) SetResult added in v0.7.9

func (s *SSHServer) SetResult(stdout string, exitCode int)

SetResult configures the stdout output and exit code returned for exec requests.

func (*SSHServer) SetResultFn added in v0.7.147

func (s *SSHServer) SetResultFn(fn func(command string) (stdout string, exitCode int))

SetResultFn configures a per-command result and takes precedence over SetResult. Use it when a test needs one command in a sequence to behave differently from the rest — a validate command exiting 127 while the sync commands before it succeed, say. The function is called outside the server's lock, so it may block to simulate a command that never returns.

type Sidecar added in v0.7.31

type Sidecar struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	OrgID     string    `json:"org_id"`
	Provider  string    `json:"provider,omitempty"`
	Image     string    `json:"image,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
}

type Snapshot added in v0.7.27

type Snapshot struct {
	ID       string `json:"id"`
	OrgID    string `json:"org_id"`
	Name     string `json:"name"`
	Tag      string `json:"tag,omitempty"`
	IsSystem bool   `json:"is_system,omitempty"`
}

Jump to

Keyboard shortcuts

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