Documentation
¶
Overview ¶
Package api provides an API client for the Test Plan API.
Index ¶
- Variables
- type AuthError
- type BadRequestError
- type BillingError
- type Client
- func (c Client) CreateTestPlan(ctx context.Context, suiteSlug string, params TestPlanParams) (plan.TestPlan, error)
- func (c *Client) DoWithRetry(ctx context.Context, reqOptions httpRequest, v interface{}) (*http.Response, error)
- func (c Client) FetchCommitList(ctx context.Context, suiteSlug string, days int) ([]string, error)
- func (c Client) FetchFilesTiming(ctx context.Context, suiteSlug string, files []string) (map[string]time.Duration, error)
- func (c Client) FetchTestPlan(ctx context.Context, suiteSlug string, identifier string, jobRetryCount int) (*plan.TestPlan, error)
- func (c Client) FilterTests(ctx context.Context, suiteSlug string, params FilterTestsParams) ([]FilteredTest, error)
- func (c Client) PostTestPlanMetadata(ctx context.Context, suiteSlug string, identifier string, ...) error
- func (c Client) PresignUpload(ctx context.Context, suiteSlug string) (PresignedUploadResponse, error)
- func (c *Client) UploadTestResults(ctx context.Context, token string, filePath string, format string, ...) error
- type ClientConfig
- type FilterTestsParams
- type FilteredTest
- type FilteredTestResponse
- type ForbiddenError
- type NotFoundError
- type PresignedUploadResponse
- type SelectionParams
- type TestPlanMetadataParams
- type TestPlanParams
- type TestPlanParamsTest
- type Timeline
- type UnprocessableEntityError
Constants ¶
This section is empty.
Variables ¶
var ErrRetryTimeout = errors.New("request retry timeout")
Functions ¶
This section is empty.
Types ¶
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) DoWithRetry ¶
func (c *Client) DoWithRetry(ctx context.Context, reqOptions httpRequest, v interface{}) (*http.Response, error)
DoWithRetry sends http request with retries. Successful API response (status code 200) is JSON decoded and stored in the value pointed to by v. The request will be retried when the server returns 429 or 5xx status code, or when there is a network error. After reaching the retry timeout, the function will return ErrRetryTimeout. The request will not be retried when the server returns 4xx status code, and the error message will be returned as an error.
func (Client) FetchCommitList ¶
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 DoWithRetry because DoWithRetry assumes JSON responses and sets Content-Type: application/json. This endpoint requires a custom Accept: text/plain header and returns a plain-text body. Adding retry support would require refactoring DoWithRetry to support custom headers and non-JSON response parsing, which isn't warranted for this single 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 (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.
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 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 TestPlanMetadataParams ¶
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 UnprocessableEntityError ¶
type UnprocessableEntityError struct {
Message string
}
func (*UnprocessableEntityError) Error ¶
func (e *UnprocessableEntityError) Error() string