fakes

package
v1.0.47331 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package fakes provides fake HTTP servers for acceptance testing.

Index

Constants

View Source
const DefaultRerunWorkflowID = "11111111-1111-4111-8111-111111111111"

DefaultRerunWorkflowID is the id of the workflow a rerun creates, unless a test overrides it with SetRerunNewWorkflowID.

It is deliberately not the id being rerun. A rerun creates a *new* workflow, and echoing the old id back would let a caller that mistakenly reports the id it was given pass its tests.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircleCI

type CircleCI struct {
	*httprecorder.RequestRecorder

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

CircleCI is a fake CircleCI API server.

func NewCircleCI

func NewCircleCI(t *testing.T) *CircleCI

NewCircleCI starts a fake CircleCI API server and registers t.Cleanup to close it.

func (*CircleCI) AddContext

func (f *CircleCI) AddContext(orgSlug string, ctx any)

AddContext registers a context object for GET /api/v2/context/{id}. ctx should be a map with at least "id", "name", and "created_at" fields. It is also indexed by org slug for list responses.

func (*CircleCI) AddContextEnvVar

func (f *CircleCI) AddContextEnvVar(contextID string, envVar any)

AddContextEnvVar registers an environment variable for a context.

func (*CircleCI) AddContextRestriction

func (f *CircleCI) AddContextRestriction(contextID string, restriction any)

AddContextRestriction registers a restriction for a context.

func (*CircleCI) AddDecisionLog

func (f *CircleCI) AddDecisionLog(ownerID, policyCtx string, log any)

AddDecisionLog appends a decision log entry for the given owner and context.

func (*CircleCI) AddDeployment added in v1.0.47331

func (f *CircleCI) AddDeployment(projectID string, deployment any)

AddDeployment registers a deployment for a project, returned by GET /api/v3/deploy/deployments. The deployment must be in V3 format: {"id": "...", "attributes": {...}, "references": {...}}.

func (*CircleCI) AddEnvVar

func (f *CircleCI) AddEnvVar(slug, name, value string, createdAt *time.Time)

AddEnvVar registers an env var for a project. slug should be in "vcs/org/repo" form.

func (*CircleCI) AddFollowedProject

func (f *CircleCI) AddFollowedProject(proj any)

AddFollowedProject registers a project returned by GET /api/v1.1/projects. proj should be a map or struct with at least "slug", "username", and "reponame" fields.

func (*CircleCI) AddGitHubAppRepository

func (f *CircleCI) AddGitHubAppRepository(orgID string, repo any)

AddGitHubAppRepository registers a repository returned by GET /api/v2/github-app/organization/{orgID}/repositories.

func (*CircleCI) AddIOSBundle

func (f *CircleCI) AddIOSBundle(orgID string, bundle any)

AddIOSBundle registers an iOS signing bundle for an org, returned by GET /api/v3/signing/configs?filter[org_id]=<orgID>.

func (*CircleCI) AddIOSCert

func (f *CircleCI) AddIOSCert(orgID string, cert any)

AddIOSCert registers an iOS certificate for an org, returned by GET /api/v3/signing/certificates?filter[org_id]=<orgID>. The cert is stored in its flat fixture shape and wrapped in the V3 entity envelope on read.

func (*CircleCI) AddJob

func (f *CircleCI) AddJob(slug string, jobNumber int64, job any)

AddJob registers a job detail response for GET /api/v2/project/<slug>/job/<number>. slug should be in "vcs/org/repo" form; jobNumber is the integer job number.

func (*CircleCI) AddJobArtifacts

func (f *CircleCI) AddJobArtifacts(slug string, jobNumber int64, artifactItems ...any)

AddJobArtifacts registers artifact responses for a job. slug should be in "vcs/org/repo" form; jobNumber is the integer job number.

func (*CircleCI) AddJobArtifactsV3

func (f *CircleCI) AddJobArtifactsV3(jobID string, items ...any)

AddJobArtifactsV3 registers V3 artifact data items for a job UUID. Each item should be a V3 data entity with "attributes" containing path, url, execution.

func (*CircleCI) AddJobStderr

func (f *CircleCI) AddJobStderr(id string, execution, stepNum int, content []byte)

AddJobStderr registers plain-text stderr for a step, served at GET /api/v3/jobs/<id>/stderr?filter[execution]=<execution>&filter[step_num]=<stepNum>.

func (*CircleCI) AddJobStdout

func (f *CircleCI) AddJobStdout(id string, execution, stepNum int, content []byte)

AddJobStdout registers plain-text stdout for a step, served at GET /api/v3/jobs/<id>/stdout?filter[execution]=<execution>&filter[step_num]=<stepNum>.

func (*CircleCI) AddJobStdoutCondensed

func (f *CircleCI) AddJobStdoutCondensed(id string, execution, stepNum int, content []byte)

AddJobStdoutCondensed registers the condensed stdout for a step, served at GET /api/v3/jobs/<id>/stdout/condensed?filter[execution]=<execution>&filter[step_num]=<stepNum>.

func (*CircleCI) AddJobTests

func (f *CircleCI) AddJobTests(id string, tests ...any)

AddJobTests registers test-result records for a job UUID, served as newline-delimited JSON (JSONL) at GET /api/v3/jobs/<id>/tests. Each record should be a map with classname, name, result, run_time and message fields.

func (*CircleCI) AddJobV1

func (f *CircleCI) AddJobV1(slug string, jobNumber int64, job any)

AddJobV1 registers a v1.1 job detail response. Use this alongside AddJob (with a job body that has no steps) to exercise the v2→v1.1 fallback path. slug should be in the v1.1 form, e.g. "github/org/repo".

func (*CircleCI) AddJobV3

func (f *CircleCI) AddJobV3(id string, job any)

AddJobV3 registers a V3 job detail response for GET /api/v3/jobs/<id>.

func (*CircleCI) AddNamespace

func (f *CircleCI) AddNamespace(id, name string)

AddNamespace registers a namespace for REST API queries. id and name form the namespace record returned by the /api/v3/namespaces endpoints.

func (*CircleCI) AddOrbCategory

func (f *CircleCI) AddOrbCategory(id, name string)

AddOrbCategory registers an orb category in the fake server.

func (*CircleCI) AddOrbPackage

func (f *CircleCI) AddOrbPackage(id, nsID, nsName, orbName string, isPrivate, isListed bool)

AddOrbPackage registers an orb package in the fake server.

func (*CircleCI) AddOrbVersion

func (f *CircleCI) AddOrbVersion(id, orbID, orbName, version, source, createdAt string)

AddOrbVersion registers an orb version in the fake server. createdAt can be empty (will default to a fixed timestamp).

func (*CircleCI) AddOrg

func (f *CircleCI) AddOrg(id, slug, name, vcsType string)

AddOrg registers an org resolvable by slug via GET /api/v3/orgs.

func (*CircleCI) AddPipelineDefinition

func (f *CircleCI) AddPipelineDefinition(projectID string, def any)

AddPipelineDefinition registers a pipeline definition for a project, returned by GET /api/v2/projects/{projectID}/pipeline-definitions.

func (*CircleCI) AddPolicyBundle

func (f *CircleCI) AddPolicyBundle(ownerID, policyCtx string, bundle map[string]string)

AddPolicyBundle registers a policy bundle for the given owner and context.

func (*CircleCI) AddProjectBySlug

func (f *CircleCI) AddProjectBySlug(slug, id, name, orgID string)

AddProjectBySlug registers a project resolved by GET /api/v3/projects?filter[slug]=<slug>, returning its UUID, name, and org UUID.

func (*CircleCI) AddProjectInfo

func (f *CircleCI) AddProjectInfo(slug string, info any)

AddProjectInfo registers a project info response for GET /api/v2/project/<slug>. slug should be in "vcs/org/repo" form.

func (*CircleCI) AddProjectRuns

func (f *CircleCI) AddProjectRuns(slug string, runs ...any)

AddProjectRuns registers runs for GET /api/v2/project/<slug>/pipeline. slug should be in "vcs/org/repo" form, e.g. "gh/myorg/myrepo".

func (*CircleCI) AddProjectV3

func (f *CircleCI) AddProjectV3(id string, project any)

AddProjectV3 registers a project returned by GET /api/v3/projects/<id>, keyed by the project's UUID. The response is wrapped as {"data": project}.

func (*CircleCI) AddResourceClass

func (f *CircleCI) AddResourceClass(rc any)

AddResourceClass adds a resource class to the fake server's list.

func (*CircleCI) AddRun

func (f *CircleCI) AddRun(id string, run any)

AddRun registers a run response for GET /api/v2/pipeline/<id>.

func (*CircleCI) AddRunV3

func (f *CircleCI) AddRunV3(id, projectID string, run any)

AddRunV3 registers a V3 run response and associates it with a project. The run must have an "id" and "references.project.id" field.

func (*CircleCI) AddRunWorkflowsV3

func (f *CircleCI) AddRunWorkflowsV3(runID string, workflows ...any)

AddRunWorkflowsV3 registers V3 workflow responses for a run.

func (*CircleCI) AddRunnerInstance

func (f *CircleCI) AddRunnerInstance(instance any)

AddRunnerInstance adds a runner instance to the fake server's list.

func (*CircleCI) AddRunnerToken

func (f *CircleCI) AddRunnerToken(resourceClass string, token any)

AddRunnerToken adds a token to the fake server for the given resource class.

func (*CircleCI) AddStaticFile

func (f *CircleCI) AddStaticFile(path, content string)

AddStaticFile registers a path that serves static content for artifact download tests. Must be called before any requests are made to the server (i.e. before RunCLI). The path should be relative, e.g. "/artifacts/foo.html".

func (*CircleCI) AddStepError

func (f *CircleCI) AddStepError(slug string, jobNumber int64, taskIndex, stepID int, content string)

AddStepError registers plain-text error content for a step action, served at GET /api/private/output/raw/{slug}/{number}/error/{taskIndex}/{stepID}.

func (*CircleCI) AddStepOutput

func (f *CircleCI) AddStepOutput(slug string, jobNumber int64, taskIndex, stepID int, content string)

AddStepOutput registers plain-text output content for a step action, served at GET /api/private/output/raw/{slug}/{number}/output/{taskIndex}/{stepID}. taskIndex is action.Index and stepID is action.Step from the job response.

func (*CircleCI) AddTrigger

func (f *CircleCI) AddTrigger(projectID, pipelineDefinitionID string, trigger any)

AddTrigger registers a trigger returned by GET /api/v2/projects/{projectID}/pipeline-definitions/{pipelineDefinitionID}/triggers.

func (*CircleCI) AddWorkflowJobs

func (f *CircleCI) AddWorkflowJobs(workflowID string, jobs ...any)

AddWorkflowJobs registers job responses for a workflow.

func (*CircleCI) AddWorkflowJobsV3

func (f *CircleCI) AddWorkflowJobsV3(workflowID string, jobs ...any)

AddWorkflowJobsV3 registers V3 job list items for a workflow.

func (*CircleCI) AddWorkflowV3

func (f *CircleCI) AddWorkflowV3(id string, workflow any)

AddWorkflowV3 registers a single V3 workflow response for GET /api/v3/workflows/<id>.

func (*CircleCI) DeletedIOSBundle

func (f *CircleCI) DeletedIOSBundle(id string) bool

DeletedIOSBundle reports whether the given bundle ID was deleted.

func (*CircleCI) DeletedIOSCert

func (f *CircleCI) DeletedIOSCert(certID string) bool

DeletedIOSCert reports whether the given cert ID was deleted.

func (*CircleCI) LastCompileOwnerID

func (f *CircleCI) LastCompileOwnerID() string

LastCompileOwnerID returns the owner_id sent on the most recent POST /compile-config-with-defaults request (empty if none yet). Tests use it to assert that --org resolved to the expected organization UUID.

func (*CircleCI) LastPARRequest

func (f *CircleCI) LastPARRequest() url.Values

LastPARRequest returns the form parameters of the most recent POST /oauth/par (RFC 9126), or nil if none has been received. Acceptance tests use it to recover the redirect_uri and state, which no longer travel in the browser-facing authorize URL.

func (*CircleCI) RerunWasFromFailed

func (f *CircleCI) RerunWasFromFailed(workflowID string) bool

RerunWasFromFailed reports whether the rerun request for workflowID actually set is_from_failed, as decoded from the wire.

Assert on this rather than on the raw request body: a body comparison passes as long as client and fake agree, which is how sending the v2 field name to a v3 endpoint went unnoticed. This reports what the *endpoint* would have acted on, so a wrong field name reads as false.

func (*CircleCI) SetCancelResponse

func (f *CircleCI) SetCancelResponse(workflowID string, status int)

SetCancelResponse sets the HTTP status code returned for POST /api/v3/workflows/<id>/cancel. Use http.StatusAccepted (202) for success.

func (*CircleCI) SetCollaborations

func (f *CircleCI) SetCollaborations(collabs []any)

SetCollaborations sets the response for GET /api/v2/me/collaborations.

func (*CircleCI) SetCompileResponse

func (f *CircleCI) SetCompileResponse(valid bool, outputYAML string, errors ...string)

SetCompileResponse configures what the fake returns for POST /compile-config-with-defaults. Pass valid=false and one or more error messages to simulate a compilation failure.

func (*CircleCI) SetCreateOrgResponse

func (f *CircleCI) SetCreateOrgResponse(resp any)

SetCreateOrgResponse registers the response body returned when POST /api/v2/organization is called. Pass nil to simulate a 422 error.

func (*CircleCI) SetCreatePipelineDefinitionResponse

func (f *CircleCI) SetCreatePipelineDefinitionResponse(projectID string, resp any)

SetCreatePipelineDefinitionResponse registers the response body returned when POST /api/v2/projects/{projectID}/pipeline-definitions is called. Pass nil to simulate a 404.

func (*CircleCI) SetCreateProjectConflict

func (f *CircleCI) SetCreateProjectConflict()

SetCreateProjectConflict makes POST /api/v2/organization/{vcs}/{org}/project answer 409, as the real API does when the organization already has a project with that name.

func (*CircleCI) SetCreateProjectResponse

func (f *CircleCI) SetCreateProjectResponse(resp any)

SetCreateProjectResponse registers the response body returned when POST /api/v2/organization/{vcs}/{org}/project is called. Pass nil to simulate a 422 error.

func (*CircleCI) SetCreateTriggerResponse

func (f *CircleCI) SetCreateTriggerResponse(projectID, pipelineDefinitionID string, resp any)

SetCreateTriggerResponse registers the response body returned when POST /api/v2/projects/{projectID}/pipeline-definitions/{pipelineDefinitionID}/triggers is called. Pass nil to simulate a 404.

func (*CircleCI) SetDLCPurgeStatus

func (f *CircleCI) SetDLCPurgeStatus(projectID string, status int)

SetDLCPurgeStatus sets the HTTP status returned for DELETE /private/output/project/{id}/dlc. Default is 204 (success). Use 410 to simulate the gone/deprecated response.

func (*CircleCI) SetDecisionResult

func (f *CircleCI) SetDecisionResult(ownerID, policyCtx string, result any)

SetDecisionResult sets the response returned by MakeDecision for the given owner and context.

func (*CircleCI) SetGitHubAppInstallResponse

func (f *CircleCI) SetGitHubAppInstallResponse(resp any)

SetGitHubAppInstallResponse registers the body returned by POST /api/v2/github-app/install.

func (*CircleCI) SetGitHubAppInstalled

func (f *CircleCI) SetGitHubAppInstalled(orgID string, installed bool)

SetGitHubAppInstalled controls whether GET /api/v2/github-app/organization/{orgID}/installation returns 200 (installed) or 404 (not installed) for the org.

func (*CircleCI) SetMe

func (f *CircleCI) SetMe(me any)

SetMe sets the data element for GET /api/v3/users?filter[user_id]=me. Pass a DataEntity-shaped map: {"id": "...", "attributes": {"name": "...", "login": "...", "avatar_url": "..."}}.

func (*CircleCI) SetOAuthTokenError

func (f *CircleCI) SetOAuthTokenError(status int, resp any)

SetOAuthTokenError configures POST /oauth/token to return the given status and JSON body. Use for testing token-exchange failure paths.

func (*CircleCI) SetOAuthTokenResponse

func (f *CircleCI) SetOAuthTokenResponse(resp any)

SetOAuthTokenResponse sets the response body for POST /oauth/token.

func (*CircleCI) SetOrbAddCategoryStatus

func (f *CircleCI) SetOrbAddCategoryStatus(status int)

SetOrbAddCategoryStatus makes every POST /api/v3/orb/packages/<id>/add-category fail with the given status, carrying the message the real registry returns when an orb is already at its category limit.

func (*CircleCI) SetOrbValidationResponse

func (f *CircleCI) SetOrbValidationResponse(yaml string, valid bool, errors []string, outputYAML string)

SetOrbValidationResponse configures the validate/process endpoints to return the given result when the request YAML matches yaml. Pass "" for yaml to match any request.

func (*CircleCI) SetOrgSettings

func (f *CircleCI) SetOrgSettings(orgUUID string, settings any)

SetOrgSettings registers advanced settings for GET /api/v3/orgs/:id/settings. orgUUID should be the org UUID string.

func (*CircleCI) SetPipelineCancelResponse

func (f *CircleCI) SetPipelineCancelResponse(pipelineID string, status int)

SetPipelineCancelResponse sets the HTTP status code returned for POST /api/v2/pipeline/<id>/cancel. Use http.StatusAccepted (202) for success.

func (*CircleCI) SetPolicyEnabled

func (f *CircleCI) SetPolicyEnabled(ownerID, policyCtx string, enabled bool)

SetPolicyEnabled sets the policy enforcement enabled flag for the given owner and context.

func (*CircleCI) SetProjectSettings

func (f *CircleCI) SetProjectSettings(projectID string, settings any)

SetProjectSettings registers advanced settings for GET /api/v3/projects/:id/settings. projectID should be the project UUID string.

func (*CircleCI) SetRerunNewWorkflowID

func (f *CircleCI) SetRerunNewWorkflowID(workflowID, newID string)

SetRerunNewWorkflowID sets the id that rerunning workflowID reports, for a test that needs to distinguish several reruns.

func (*CircleCI) SetRerunResponse

func (f *CircleCI) SetRerunResponse(workflowID string, status int)

SetRerunResponse sets the HTTP status code returned for POST /api/v2/workflow/<id>/rerun. Use http.StatusAccepted (202) for success.

func (*CircleCI) SetRunWorkflowsV3NotFound

func (f *CircleCI) SetRunWorkflowsV3NotFound(runID string)

SetRunWorkflowsV3NotFound makes GET /api/v3/workflows?filter[run_id]=<runID> return 404 for the given run, mirroring the real API for runs whose workflows have not materialised.

func (*CircleCI) SetRunnerTokenCreateResponse added in v1.0.47122

func (f *CircleCI) SetRunnerTokenCreateResponse(status int, body any)

SetRunnerTokenCreateResponse overrides the response to POST /runner/token, which otherwise answers 201 with a token whose value is "fake-runner-token-value". Use it to force a failure, or a 201 whose payload omits or lengthens the token value. A nil body sends a generic error message.

func (*CircleCI) SetTriggerPipelineRunResponse

func (f *CircleCI) SetTriggerPipelineRunResponse(slug string, resp any)

SetTriggerPipelineRunResponse registers the response body returned when POST /api/v2/project/<slug>/pipeline/run is called with a 201 status. slug should be in "vcs/org/repo" form.

func (*CircleCI) SetTriggerPipelineRunSkipped

func (f *CircleCI) SetTriggerPipelineRunSkipped(slug, message string)

SetTriggerPipelineRunSkipped registers a "not triggered" response (200) for POST /api/v2/project/<slug>/pipeline/run.

func (*CircleCI) SetTriggerResponse

func (f *CircleCI) SetTriggerResponse(slug string, resp any)

SetTriggerResponse registers the response body returned when POST /api/v2/project/<slug>/pipeline is called. slug should be in "vcs/org/repo" form.

func (*CircleCI) SetUserRuns

func (f *CircleCI) SetUserRuns(runs ...any)

SetUserRuns registers the V3 run data items returned by GET /api/v3/runs?filter[user_id]=me (i.e. "circleci my runs").

func (*CircleCI) URL

func (f *CircleCI) URL() string

URL returns the base URL of the fake server.

type ExtensionMeta

type ExtensionMeta struct {
	Version string
	Sha256  string
	Arch    string
	Sys     string
}

type ExtensionRegistry

type ExtensionRegistry struct {
	RequestRecorder *httprecorder.RequestRecorder
	// contains filtered or unexported fields
}

func NewExtensionRegistry

func NewExtensionRegistry(t *testing.T) *ExtensionRegistry

func (*ExtensionRegistry) Manifest

func (e *ExtensionRegistry) Manifest(binaryName string) extension.Manifest

func (*ExtensionRegistry) URL

func (e *ExtensionRegistry) URL() string

func (*ExtensionRegistry) WithExtension

func (e *ExtensionRegistry) WithExtension(t *testing.T, ext extension.Manifest, meta ExtensionMeta) *ExtensionRegistry

Jump to

Keyboard shortcuts

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