api

package
v2.8.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package api provides an API client for the Test Plan API.

Index

Constants

This section is empty.

Variables

View Source
var ErrRetryTimeout = errors.New("request retry timeout")

Functions

This section is empty.

Types

type AuthError

type AuthError struct {
	Message string
}

func (*AuthError) Error

func (e *AuthError) Error() string

type BadRequestError

type BadRequestError struct {
	Message string
}

func (*BadRequestError) Error

func (e *BadRequestError) Error() string

type BillingError

type BillingError struct {
	Message string
}

func (*BillingError) Error

func (e *BillingError) Error() string

type Client

type Client struct {
	OrganizationSlug string
	ServerBaseURL    string
	UploadBaseURL    string
	// contains filtered or unexported fields
}

client is a client for the test plan API. It contains the organization slug, server base URL, and an HTTP client.

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient creates a new client for the test plan API with the given configuration. It also creates an HTTP client with an authTransport middleware.

func (Client) CreateTestPlan

func (c Client) CreateTestPlan(ctx context.Context, suiteSlug string, params TestPlanParams) (plan.TestPlan, error)

CreateTestPlan creates a test plan from the server. ErrRetryTimeout is returned if the client failed to communicate with the server after exceeding the retry limit.

func (Client) FetchCommitList

func (c Client) FetchCommitList(ctx context.Context, suiteSlug string, days int) ([]string, error)

FetchCommitList fetches the list of commit SHAs that need metadata from the commits API endpoint.

Endpoint: GET /v2/analytics/organizations/:org/suites/:suite/commits?days=N Uses Accept: text/plain to receive newline-delimited SHAs for simpler parsing.

This method does not use doJSONWithRetry because that assumes JSON responses and sets Content-Type: application/json, while this endpoint needs a custom Accept: text/plain header and returns a plain-text body. It could be wired through the generic doWithRetry engine with its own request/response handlers, but that isn't warranted for this single, non-retried call site. The authTransport middleware (Bearer token + User-Agent) is still applied via the client's httpClient.

func (Client) FetchFilesTiming

func (c Client) FetchFilesTiming(ctx context.Context, suiteSlug string, files []string) (map[string]time.Duration, error)

FetchFilesTiming fetches the timing of the requested files from the server. The server only returns timings for the files that has been run before. ErrRetryTimeout is returned if the client failed to communicate with the server after exceeding the retry limit.

func (Client) FetchTestPlan

func (c Client) FetchTestPlan(ctx context.Context, suiteSlug string, identifier string, jobRetryCount int) (*plan.TestPlan, error)

FetchTestPlan fetchs a test plan from the server. ErrRetryTimeout is returned if the client failed to communicate with the server after exceeding the retry limit.

func (Client) FilterTests

func (c Client) FilterTests(ctx context.Context, suiteSlug string, params FilterTestsParams) ([]FilteredTest, error)

FilterTests fetches test files from the server. It returns a list of test files that need to be split by example.

Currently, it only fetches tests file that are slow and test files that have tests marked for skipping.

The splitByExample flag is passed through to the server, which is false will only return test files that contain skipped tests, while true will also return slow test files.

func (Client) PostTestPlanMetadata

func (c Client) PostTestPlanMetadata(ctx context.Context, suiteSlug string, identifier string, params TestPlanMetadataParams) error

func (Client) PresignUpload

func (c Client) PresignUpload(ctx context.Context, suiteSlug string) (PresignedUploadResponse, error)

PresignUpload requests a presigned S3 upload URL for commit metadata.

Endpoint: POST /v2/analytics/organizations/:org/suites/:suite/commit-metadata-backfill/presigned-upload

func (*Client) UploadTestResults added in v2.7.0

func (c *Client) UploadTestResults(ctx context.Context, token string, filePath string, format string, locationPrefix string, tags map[string]string) error

UploadTestResults POSTs the raw result file from the runner to the Test Engine analytics API at <c.UploadBaseURL>/v1/uploads. The format parameter tells the ingestion gear how to parse the file (e.g. "rspec-json", "jest-json"). Errors are returned to the caller to be logged and suppressed — this upload is best-effort and must not fail the build.

Transient failures (network errors, 429, 5xx) are retried via doWithRetry before giving up. The multipart body is built once and re-sent on each attempt.

type ClientConfig

type ClientConfig struct {
	AccessToken      string
	UploadBaseURL    string
	OrganizationSlug string
	ServerBaseURL    string
}

ClientConfig is the configuration for the test plan API client.

type FilterTestsParams

type FilterTestsParams struct {
	Files []plan.TestCase `json:"files"`
	Env   *config.Config  `json:"env"`
}

type FilteredTest

type FilteredTest struct {
	Path string `json:"path"`
}

type FilteredTestResponse

type FilteredTestResponse struct {
	Tests []FilteredTest `json:"tests"`
}

type ForbiddenError

type ForbiddenError struct {
	Message string
}

func (*ForbiddenError) Error

func (e *ForbiddenError) Error() string

type NotFoundError

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type PresignedUploadResponse

type PresignedUploadResponse struct {
	URI  string                     `json:"uri"`
	Form upload.PresignedUploadForm `json:"form"`
}

PresignedUploadResponse is the response from the presigned upload endpoint.

type SelectionParams

type SelectionParams struct {
	Strategy string            `json:"strategy"`
	Params   map[string]string `json:"params,omitempty"`
}

type TestPlanMetadataParams

type TestPlanMetadataParams struct {
	Version    string               `json:"version"`
	Env        *config.Config       `json:"env"`
	Timeline   []Timeline           `json:"timeline"`
	Statistics runner.RunStatistics `json:"statistics"`
}

type TestPlanParams

type TestPlanParams struct {
	Runner         string             `json:"runner"`
	Identifier     string             `json:"identifier"`
	Parallelism    int                `json:"parallelism"`
	MaxParallelism int                `json:"max_parallelism,omitempty"`
	TargetTime     float64            `json:"target_time,omitempty"`
	Branch         string             `json:"branch"`
	Tests          TestPlanParamsTest `json:"tests"`
	Selection      *SelectionParams   `json:"selection,omitempty"`
	Metadata       map[string]string  `json:"metadata,omitempty"`
}

TestPlanParams represents the config params sent when fetching a test plan.

type TestPlanParamsTest

type TestPlanParamsTest struct {
	Files    []plan.TestCase `json:"files"`
	Examples []plan.TestCase `json:"examples,omitempty"`
}

type Timeline

type Timeline struct {
	Timestamp string `json:"timestamp"`
	Event     string `json:"event"`
}

type UnprocessableEntityError

type UnprocessableEntityError struct {
	Message string
}

func (*UnprocessableEntityError) Error

func (e *UnprocessableEntityError) Error() string

Jump to

Keyboard shortcuts

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