testkit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultPollStepTimeout  = 60 * time.Second
	DefaultPollStepInterval = time.Second
)

Default polling of ops registered with RegisterPollingOp (step args "timeoutMs" and "intervalMs" override them).

Variables

This section is empty.

Functions

func ArgBool

func ArgBool(args map[string]any, key string) bool

ArgBool returns args[key] as a bool (false when absent).

func ArgDuration

func ArgDuration(args map[string]any, key string, def time.Duration) time.Duration

ArgDuration returns args[key] (milliseconds) as a duration (def when absent).

func ArgInt

func ArgInt(args map[string]any, key string, def int) int

ArgInt returns args[key] as an int (def when absent or not a number).

func ArgMap

func ArgMap(args map[string]any, key string) map[string]any

ArgMap returns args[key] as an object (nil when absent).

func ArgString

func ArgString(args map[string]any, key string) string

ArgString returns args[key] as a string ("" when absent).

func ArgStrings

func ArgStrings(args map[string]any, key string) []string

ArgStrings returns args[key] as a string slice (nil when absent).

func Normalize

func Normalize(v any) any

Normalize converts v to its JSON form (maps, []any, float64, string, bool, nil).

func RegisterExpectation

func RegisterExpectation(name string, check ExpectationCheck)

RegisterExpectation adds a custom expectation key.

func RegisterOps

func RegisterOps(category string, ops map[string]OpHandler)

RegisterOps adds op handlers for a category. Category files call it from init().

func RegisterPollingOp

func RegisterPollingOp(category, op string)

RegisterPollingOp marks an op of a category as polling: its step is repeated every "intervalMs" (default 1 s) until the op succeeds and its expectations pass, or until "timeoutMs" (default 60 s) is over; then the last failure is reported. It suits reads of backends that index asynchronously (tracing listServices).

func Run

func Run(t *testing.T, dir string, opts Options)

Run executes the selected scenarios as subtests of t (one per scenario id).

func StringForm

func StringForm(v any) string

StringForm returns every printable form of v joined: %v, %+v, %#v, %s and JSON.

Types

type CoreTarget

type CoreTarget interface {
	Health(ctx context.Context) (oidc.HealthStatus, error)
	Ping(ctx context.Context) (time.Duration, error)
	ServerVersion(ctx context.Context) (string, error)
	Close() error
}

CoreTarget is what the "core" scenarios exercise (*oidc.Client implements it).

type Counted

type Counted interface {
	ConformanceCount() int
}

Counted lets an op result report its own size for "count"/"minCount" (for example a trace reports its number of spans).

type Env

type Env struct {
	// Run is the random 8-char lowercase id of this scenario run (${run}).
	Run string
	// Prefix is the provider prefix with ${run} expanded (${prefix}).
	Prefix string
	// ServiceName is the tracing service name (${serviceName}).
	ServiceName string
	// Scenario is the scenario being executed.
	Scenario *Scenario
	// Target is the value built by the category factory.
	Target any
	// Vars holds ${name} substitutions (run, prefix, serviceName and saved step results).
	Vars map[string]string
	// contains filtered or unexported fields
}

Env is the per-scenario environment handed to factories and op handlers.

func (*Env) AddCleanup

func (e *Env) AddCleanup(fn func())

AddCleanup registers fn to run (last in, first out) after the scenario.

func (*Env) Expand

func (e *Env) Expand(s string) string

Expand replaces ${name} variables in s.

func (*Env) ExpandValue

func (e *Env) ExpandValue(v any) any

ExpandValue expands variables in every string inside v, including object keys (maps and slices recursively).

type ExpectationCheck

type ExpectationCheck func(env *Env, result any, want any) error

ExpectationCheck evaluates one custom expectation key (for example "tree").

type Factories

type Factories map[string]Factory

Factories maps a category ("core", "secrets", "logging", "tracing") to its factory.

type Factory

type Factory func(ctx context.Context, env *Env) (any, error)

Factory builds the target of one category for one scenario run. Register cleanups (closing clients) with env.AddCleanup.

func CoreFactory

func CoreFactory(fn func(ctx context.Context) (CoreTarget, error)) Factory

CoreFactory adapts a client constructor to a Factory; the client is closed after the scenario.

type OpHandler

type OpHandler func(ctx context.Context, env *Env, args map[string]any) (any, error)

OpHandler executes one scenario op against env.Target. args already have variables expanded. The result is checked against the step's expectations.

type Options

type Options struct {
	// Categories to run. Empty means every category that has a factory.
	Categories []string
	// Factories per category.
	Factories Factories
	// Capabilities the target declares (write, versions, delete, query, ...).
	Capabilities []string
	// Prefix for secret names; default "grow-conformance/${run}/".
	Prefix string
	// ServiceName for tracing scenarios; default "grow-conformance".
	ServiceName string
	// ScenarioTimeout bounds one scenario; default 5 minutes.
	ScenarioTimeout time.Duration
	// Only restricts the run to these scenario ids (empty = all).
	Only []string
}

Options configures a conformance run.

type Report

type Report struct {
	Results []ScenarioResult `json:"results"`
	Passed  int              `json:"passed"`
	Failed  int              `json:"failed"`
	Skipped int              `json:"skipped"`
}

Report is the outcome of RunScenarios.

func RunScenarios

func RunScenarios(ctx context.Context, dir string, opts Options) (*Report, error)

RunScenarios runs the selected scenarios in dir and returns a report. It returns an error only when the scenarios cannot be loaded.

func (*Report) OK

func (r *Report) OK() bool

OK reports whether no scenario failed.

type Scenario

type Scenario struct {
	ID          string   `json:"id"`
	Category    string   `json:"category"`
	Description string   `json:"description"`
	Requires    []string `json:"requires"`
	Steps       []Step   `json:"steps"`
	// BatchOptions is the raw "batchOptions" object (logging); factories apply it.
	BatchOptions json.RawMessage `json:"batchOptions,omitempty"`
	// File is the path the scenario was loaded from.
	File string `json:"-"`
}

Scenario is one conformance scenario file (conformance/scenarios/*.json).

func LoadScenarios

func LoadScenarios(dir string) ([]*Scenario, error)

LoadScenarios reads every *.json scenario in dir, sorted by id.

type ScenarioResult

type ScenarioResult struct {
	ID       string        `json:"id"`
	Category string        `json:"category"`
	File     string        `json:"file"`
	Status   Status        `json:"status"`
	Reason   string        `json:"reason,omitempty"`
	Steps    []StepResult  `json:"steps,omitempty"`
	Duration time.Duration `json:"durationNs"`
}

ScenarioResult reports one scenario.

func RunScenario

func RunScenario(ctx context.Context, sc *Scenario, opts Options) (res ScenarioResult)

RunScenario executes one scenario.

type Status

type Status string

Status of one scenario run.

const (
	StatusPassed  Status = "passed"
	StatusFailed  Status = "failed"
	StatusSkipped Status = "skipped"
)

Scenario statuses.

type Step

type Step struct {
	Op       string         `json:"op"`
	Args     map[string]any `json:"args,omitempty"`
	Expect   map[string]any `json:"expect,omitempty"`
	Save     string         `json:"save,omitempty"`
	Requires []string       `json:"requires,omitempty"`
}

Step is one operation of a scenario.

type StepResult

type StepResult struct {
	Index  int    `json:"index"`
	Op     string `json:"op"`
	Status Status `json:"status"`
	Reason string `json:"reason,omitempty"`
}

StepResult reports one executed step.

Jump to

Keyboard shortcuts

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