Documentation
¶
Overview ¶
Package planfake provides a deterministic in-process REST scan-planning server for tests. It intentionally uses independent JSON responses instead of the production REST wire structs.
Index ¶
- Constants
- type ExpectedTarget
- type Request
- type Response
- type ResponseSequence
- type Scenario
- type Server
- func (s *Server) AcknowledgeScenarioErrors(want ...string) error
- func (s *Server) CancelCount(planID string) int
- func (s *Server) Close()
- func (s *Server) PollCount(planID string) int
- func (s *Server) Requests() []Request
- func (s *Server) ScenarioErrors() []string
- func (s *Server) TaskCount(planTask string) int
- func (s *Server) URL() string
- func (s *Server) WaitForPollCount(ctx context.Context, planID string, atLeast int) error
Constants ¶
const ( PlanTableScanEndpoint = "POST /v1/{prefix}/namespaces/{namespace}/tables/{table}/plan" FetchPlanningResultEndpoint = "GET /v1/{prefix}/namespaces/{namespace}/tables/{table}/plan/{plan-id}" CancelPlanningEndpoint = "DELETE /v1/{prefix}/namespaces/{namespace}/tables/{table}/plan/{plan-id}" FetchScanTasksEndpoint = "POST /v1/{prefix}/namespaces/{namespace}/tables/{table}/tasks" )
Scan-planning endpoint strings as advertised by GET /v1/config. These are literal protocol fixtures, deliberately independent from catalog/rest's endpoint constants so a production wire-format regression cannot update both sides of a test unnoticed.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpectedTarget ¶
ExpectedTarget is the decoded REST planning target accepted by a Scenario. Namespace uses the REST namespace path representation (components joined by the unit separator), while Prefix and Table are decoded path values.
type Request ¶
type Request struct {
Method string
Path string
RawQuery string
Header http.Header
Body []byte
Prefix string
Namespace string
Table string
PlanID string
PlanTask string
}
Request is one request captured by the fake server. Path is the escaped wire path, which preserves opaque plan IDs containing slashes or dot segments. RawQuery is captured separately without decoding. Prefix, Namespace, Table, PlanID, and PlanTask are decoded routing values when applicable.
type Response ¶
type Response struct {
Status int
Header http.Header
Body json.RawMessage
Gate <-chan struct{}
}
Response is one HTTP response in a scenario. A zero Status means 200 OK. Header and Body are cloned when the server is created and again before a response is written, so callers may safely reuse or mutate their fixtures. When Gate is non-nil, the server waits for it to close or receive a value before writing the response. Cancelling the request releases the waiter; closing the Server aborts the gated connection without manufacturing a successful response.
func ConfigResponse ¶
ConfigResponse returns a successful catalog configuration response that advertises endpoints exactly as supplied.
type ResponseSequence ¶
ResponseSequence is an ordered sequence of responses for one scenario key. Each request consumes the next response. Once exhausted, a sequence returns a non-retryable scenario error unless RepeatLast is true, in which case its final response is returned for every later request.
type Scenario ¶
type Scenario struct {
ExpectedTarget *ExpectedTarget
ConfigResponse Response
PlanResponse Response
PollResponses map[string]ResponseSequence
TaskResponses map[string]ResponseSequence
CancelResponses map[string]ResponseSequence
}
Scenario declares the responses returned by a Server. ExpectedTarget is required for every planning operation; requests for another target, or a planning request made without an expected target, receive a non-retryable scenario error.
Poll responses are keyed by decoded plan ID, task responses by the plan-task value in the request body, and cancel responses by decoded plan ID. A missing key, empty sequence, or exhausted non-repeating sequence returns a clear, non-retryable scenario error.
An all-zero ConfigResponse or PlanResponse means that response was not configured. Use Response{Status: http.StatusOK} to model an intentional empty 200 response. Scenario errors fail the owning test during cleanup unless a test explicitly acknowledges their exact values with Server.AcknowledgeScenarioErrors.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a concurrency-safe in-process REST scan-planning server.
func (*Server) AcknowledgeScenarioErrors ¶
AcknowledgeScenarioErrors marks the currently pending scenario errors as expected only when they exactly equal want in order. A mismatch leaves every error pending so cleanup still fails, as do any errors observed later.
func (*Server) CancelCount ¶
CancelCount returns the number of cancellation requests received for planID.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the fake server. It is safe to call more than once.
func (*Server) ScenarioErrors ¶
ScenarioErrors returns a defensive copy of unacknowledged scenario-contract errors observed by the server. Any errors left pending fail the owning test during cleanup.
func (*Server) TaskCount ¶
TaskCount returns the number of task-fetch requests received for planTask.
func (*Server) WaitForPollCount ¶
WaitForPollCount waits until at least the requested number of poll requests have been received for planID. It returns ctx.Err if the context ends first, or http.ErrServerClosed if the server closes before the threshold is reached.