Documentation
¶
Overview ¶
Package fakes provides fake HTTP servers for acceptance testing.
Index ¶
- type CircleCI
- func (f *CircleCI) AddContext(orgSlug string, ctx any)
- func (f *CircleCI) AddContextEnvVar(contextID string, envVar any)
- func (f *CircleCI) AddContextRestriction(contextID string, restriction any)
- func (f *CircleCI) AddDecisionLog(ownerID, policyCtx string, log any)
- func (f *CircleCI) AddDeploy(projectID string, deploy any)
- func (f *CircleCI) AddEnvVar(slug, name, value string, createdAt *time.Time)
- func (f *CircleCI) AddFollowedProject(proj any)
- func (f *CircleCI) AddIOSBundle(orgID string, bundle any)
- func (f *CircleCI) AddIOSCert(orgID string, cert any)
- func (f *CircleCI) AddJob(slug string, jobNumber int64, job any)
- func (f *CircleCI) AddJobArtifacts(slug string, jobNumber int64, artifactItems ...any)
- func (f *CircleCI) AddJobArtifactsV3(jobID string, items ...any)
- func (f *CircleCI) AddJobStderr(id string, execution, stepNum int, content []byte)
- func (f *CircleCI) AddJobStdout(id string, execution, stepNum int, content []byte)
- func (f *CircleCI) AddJobTests(id string, tests ...any)
- func (f *CircleCI) AddJobV1(slug string, jobNumber int64, job any)
- func (f *CircleCI) AddJobV3(id string, job any)
- func (f *CircleCI) AddNamespace(id, name string)
- func (f *CircleCI) AddOrbCategory(id, name string)
- func (f *CircleCI) AddOrbPackage(id, nsID, nsName, orbName string, isPrivate, isListed bool)
- func (f *CircleCI) AddOrbVersion(id, orbID, orbName, version, source, createdAt string)
- func (f *CircleCI) AddOrg(id, slug, name, vcsType string)
- func (f *CircleCI) AddPipelineDefinition(projectID string, def any)
- func (f *CircleCI) AddPolicyBundle(ownerID, policyCtx string, bundle map[string]string)
- func (f *CircleCI) AddProjectBySlug(slug, id, name, orgID string)
- func (f *CircleCI) AddProjectInfo(slug string, info any)
- func (f *CircleCI) AddProjectRuns(slug string, runs ...any)
- func (f *CircleCI) AddProjectV3(id string, project any)
- func (f *CircleCI) AddResourceClass(rc any)
- func (f *CircleCI) AddRun(id string, run any)
- func (f *CircleCI) AddRunV3(id, projectID string, run any)
- func (f *CircleCI) AddRunWorkflowsV3(runID string, workflows ...any)
- func (f *CircleCI) AddRunnerInstance(instance any)
- func (f *CircleCI) AddRunnerToken(resourceClass string, token any)
- func (f *CircleCI) AddStaticFile(path, content string)
- func (f *CircleCI) AddStepError(slug string, jobNumber int64, taskIndex, stepID int, content string)
- func (f *CircleCI) AddStepOutput(slug string, jobNumber int64, taskIndex, stepID int, content string)
- func (f *CircleCI) AddTrigger(projectID, pipelineDefinitionID string, trigger any)
- func (f *CircleCI) AddWorkflowJobs(workflowID string, jobs ...any)
- func (f *CircleCI) AddWorkflowJobsV3(workflowID string, jobs ...any)
- func (f *CircleCI) AddWorkflowV3(id string, workflow any)
- func (f *CircleCI) DeletedIOSBundle(id string) bool
- func (f *CircleCI) DeletedIOSCert(certID string) bool
- func (f *CircleCI) LastCompileOwnerID() string
- func (f *CircleCI) LastPARRequest() url.Values
- func (f *CircleCI) SetCancelResponse(workflowID string, status int)
- func (f *CircleCI) SetCollaborations(collabs []any)
- func (f *CircleCI) SetCompileResponse(valid bool, outputYAML string, errors ...string)
- func (f *CircleCI) SetCreateOrgResponse(resp any)
- func (f *CircleCI) SetCreatePipelineDefinitionResponse(projectID string, resp any)
- func (f *CircleCI) SetCreateProjectResponse(resp any)
- func (f *CircleCI) SetCreateTriggerResponse(projectID, pipelineDefinitionID string, resp any)
- func (f *CircleCI) SetDLCPurgeStatus(projectID string, status int)
- func (f *CircleCI) SetDecisionResult(ownerID, policyCtx string, result any)
- func (f *CircleCI) SetMe(me any)
- func (f *CircleCI) SetOAuthTokenError(status int, resp any)
- func (f *CircleCI) SetOAuthTokenResponse(resp any)
- func (f *CircleCI) SetOrbValidationResponse(yaml string, valid bool, errors []string, outputYAML string)
- func (f *CircleCI) SetOrgSettings(orgUUID string, settings any)
- func (f *CircleCI) SetPipelineCancelResponse(pipelineID string, status int)
- func (f *CircleCI) SetPolicyEnabled(ownerID, policyCtx string, enabled bool)
- func (f *CircleCI) SetProjectSettings(projectID string, settings any)
- func (f *CircleCI) SetRerunResponse(workflowID string, status int)
- func (f *CircleCI) SetRunWorkflowsV3NotFound(runID string)
- func (f *CircleCI) SetTriggerPipelineRunResponse(slug string, resp any)
- func (f *CircleCI) SetTriggerPipelineRunSkipped(slug, message string)
- func (f *CircleCI) SetTriggerResponse(slug string, resp any)
- func (f *CircleCI) SetUserRuns(runs ...any)
- func (f *CircleCI) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircleCI ¶
type CircleCI struct {
*httprecorder.RequestRecorder
// contains filtered or unexported fields
}
CircleCI is a fake CircleCI API server.
func NewCircleCI ¶
NewCircleCI starts a fake CircleCI API server and registers t.Cleanup to close it.
func (*CircleCI) AddContext ¶
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 ¶
AddContextEnvVar registers an environment variable for a context.
func (*CircleCI) AddContextRestriction ¶
AddContextRestriction registers a restriction for a context.
func (*CircleCI) AddDecisionLog ¶
AddDecisionLog appends a decision log entry for the given owner and context.
func (*CircleCI) AddDeploy ¶
AddDeploy registers a deploy for a project, returned by GET /api/v2/deploy/projects/{project_id}/releases.
func (*CircleCI) AddEnvVar ¶
AddEnvVar registers an env var for a project. slug should be in "vcs/org/repo" form.
func (*CircleCI) AddFollowedProject ¶
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) AddIOSBundle ¶
AddIOSBundle registers an iOS signing bundle for an org, returned by GET /api/v3/signing/configs?filter[org_id]=<orgID>.
func (*CircleCI) AddIOSCert ¶
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 ¶
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 ¶
AddJobArtifacts registers artifact responses for a job. slug should be in "vcs/org/repo" form; jobNumber is the integer job number.
func (*CircleCI) AddJobArtifactsV3 ¶
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 ¶
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 ¶
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) AddJobTests ¶
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 ¶
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) AddNamespace ¶
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 ¶
AddOrbCategory registers an orb category in the fake server.
func (*CircleCI) AddOrbPackage ¶
AddOrbPackage registers an orb package in the fake server.
func (*CircleCI) AddOrbVersion ¶
AddOrbVersion registers an orb version in the fake server. createdAt can be empty (will default to a fixed timestamp).
func (*CircleCI) AddPipelineDefinition ¶
AddPipelineDefinition registers a pipeline definition for a project, returned by GET /api/v2/projects/{projectID}/pipeline-definitions.
func (*CircleCI) AddPolicyBundle ¶
AddPolicyBundle registers a policy bundle for the given owner and context.
func (*CircleCI) AddProjectBySlug ¶
AddProjectBySlug registers a project resolved by GET /api/v3/projects?filter[slug]=<slug>, returning its UUID, name, and org UUID.
func (*CircleCI) AddProjectInfo ¶
AddProjectInfo registers a project info response for GET /api/v2/project/<slug>. slug should be in "vcs/org/repo" form.
func (*CircleCI) AddProjectRuns ¶
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 ¶
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 ¶
AddResourceClass adds a resource class to the fake server's list.
func (*CircleCI) AddRunV3 ¶
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 ¶
AddRunWorkflowsV3 registers V3 workflow responses for a run.
func (*CircleCI) AddRunnerInstance ¶
AddRunnerInstance adds a runner instance to the fake server's list.
func (*CircleCI) AddRunnerToken ¶
AddRunnerToken adds a token to the fake server for the given resource class.
func (*CircleCI) AddStaticFile ¶
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 ¶
AddTrigger registers a trigger returned by GET /api/v2/projects/{projectID}/pipeline-definitions/{pipelineDefinitionID}/triggers.
func (*CircleCI) AddWorkflowJobs ¶
AddWorkflowJobs registers job responses for a workflow.
func (*CircleCI) AddWorkflowJobsV3 ¶
AddWorkflowJobsV3 registers V3 job list items for a workflow.
func (*CircleCI) AddWorkflowV3 ¶
AddWorkflowV3 registers a single V3 workflow response for GET /api/v3/workflows/<id>.
func (*CircleCI) DeletedIOSBundle ¶
DeletedIOSBundle reports whether the given bundle ID was deleted.
func (*CircleCI) DeletedIOSCert ¶
DeletedIOSCert reports whether the given cert ID was deleted.
func (*CircleCI) LastCompileOwnerID ¶
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 ¶
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) SetCancelResponse ¶
SetCancelResponse sets the HTTP status code returned for POST /api/v3/workflows/<id>/cancel. Use http.StatusAccepted (202) for success.
func (*CircleCI) SetCollaborations ¶
SetCollaborations sets the response for GET /api/v2/me/collaborations.
func (*CircleCI) SetCompileResponse ¶
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 ¶
SetCreateOrgResponse registers the response body returned when POST /api/v2/organization is called. Pass nil to simulate a 422 error.
func (*CircleCI) SetCreatePipelineDefinitionResponse ¶
SetCreatePipelineDefinitionResponse registers the response body returned when POST /api/v2/projects/{projectID}/pipeline-definitions is called. Pass nil to simulate a 404.
func (*CircleCI) SetCreateProjectResponse ¶
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 ¶
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 ¶
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 ¶
SetDecisionResult sets the response returned by MakeDecision for the given owner and context.
func (*CircleCI) SetMe ¶
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 ¶
SetOAuthTokenError configures POST /oauth/token to return the given status and JSON body. Use for testing token-exchange failure paths.
func (*CircleCI) SetOAuthTokenResponse ¶
SetOAuthTokenResponse sets the response body for POST /oauth/token.
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 ¶
SetOrgSettings registers advanced settings for GET /api/v3/orgs/:id/settings. orgUUID should be the org UUID string.
func (*CircleCI) SetPipelineCancelResponse ¶
SetPipelineCancelResponse sets the HTTP status code returned for POST /api/v2/pipeline/<id>/cancel. Use http.StatusAccepted (202) for success.
func (*CircleCI) SetPolicyEnabled ¶
SetPolicyEnabled sets the policy enforcement enabled flag for the given owner and context.
func (*CircleCI) SetProjectSettings ¶
SetProjectSettings registers advanced settings for GET /api/v3/projects/:id/settings. projectID should be the project UUID string.
func (*CircleCI) SetRerunResponse ¶
SetRerunResponse sets the HTTP status code returned for POST /api/v2/workflow/<id>/rerun. Use http.StatusAccepted (202) for success.
func (*CircleCI) SetRunWorkflowsV3NotFound ¶
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) SetTriggerPipelineRunResponse ¶
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 ¶
SetTriggerPipelineRunSkipped registers a "not triggered" response (200) for POST /api/v2/project/<slug>/pipeline/run.
func (*CircleCI) SetTriggerResponse ¶
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 ¶
SetUserRuns registers the V3 run data items returned by GET /api/v3/runs?filter[user_id]=me (i.e. "circleci my runs").