Documentation ¶
Index ¶
- func RunTest(t *testing.T, adapterInfo adapter.InfoFn, scenario Scenario)
- type Call
- type CallKind
- type Env
- func (e *Env) Errorf(format string, args ...interface{}) error
- func (e *Env) GetDoneChan() chan struct{}
- func (e *Env) GetLogs() []string
- func (e *Env) Infof(format string, args ...interface{})
- func (e *Env) Logger() adapter.Logger
- func (e *Env) ScheduleDaemon(fn adapter.DaemonFunc)
- func (e *Env) ScheduleWork(fn adapter.WorkFunc)
- func (e *Env) VerbosityLevel(level adapter.VerbosityLevel) bool
- func (e *Env) Warningf(format string, args ...interface{})
- type GetStateFn
- type Result
- type Return
- type Scenario
- type SetupFn
- type TeardownFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunTest ¶
RunTest performs a Mixer adapter integration test using in-memory Mixer and config store. NOTE: DO NOT invoke this using `t.Run(string, func)` because that would execute func in a separate go routine. Separate go routines would cause the test to fail randomly because fixed ports cannot be assigned and cleaned up deterministically on each iteration.
- adapterInfo provides the InfoFn for the adapter under test.
- Scenario provide the adapter/handler/rule configs along with the call parameters (check or report, and attributes) Optionally, it also takes the test specific SetupFn, TeardownFn, GetStateFn and list of supported templates.
Types ¶
type Call ¶
type Call struct { // CallKind can be either CHECK or REPORT CallKind CallKind // Attrs to call the Mixer with. Attrs map[string]interface{} // Quotas info to call the Mixer with. Quotas map[string]istio_mixer_v1.CheckRequest_QuotaParams }
Call represents the input to make a call to Mixer
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is an adapter environment that defers to the testing context t. Tracks all messages logged so they can be tested against.
func NewEnv ¶
NewEnv returns an adapter environment that redirects logging output to the given testing context.
func (*Env) GetDoneChan ¶
func (e *Env) GetDoneChan() chan struct{}
GetDoneChan returns the channel that returns notification when the async work is done.
func (*Env) GetLogs ¶
GetLogs returns a snapshot of all logs that've been written to this environment
func (*Env) ScheduleDaemon ¶
func (e *Env) ScheduleDaemon(fn adapter.DaemonFunc)
ScheduleDaemon runs the given function asynchronously.
func (*Env) ScheduleWork ¶
ScheduleWork runs the given function asynchronously.
func (*Env) VerbosityLevel ¶
func (e *Env) VerbosityLevel(level adapter.VerbosityLevel) bool
VerbosityLevel return true for test envs (all verbosity levels enabled).
type GetStateFn ¶
type GetStateFn func(ctx interface{}) (interface{}, error)
GetStateFn returns the adapter specific state upon test execution. The return value becomes part of expected Result.AdapterState.
type Result ¶
type Result struct { // AdapterState represents adapter specific baseline data. AdapterState is what the callback function // `getState`, passed to `RunTest`, returns. AdapterState interface{} `json:"AdapterState"` // Returns represents the return data from calls to Mixer Returns []Return `json:"Returns"` }
Result represents the test baseline
type Return ¶
type Return struct { // Check is the response from a check call to Mixer Check adapter.CheckResult `json:"Check"` // Quota is the response from a check call to Mixer Quota map[string]adapter.QuotaResult `json:"Quota"` // Error is the error from call to Mixer Error error `json:"Error"` }
Return represents the return data from a call to Mixer
type Scenario ¶
type Scenario struct { // Configs is a list of CRDs that Mixer will read. Configs []string // ParallelCalls is a list of test calls to be made to Mixer // in parallel. ParallelCalls []Call // Setup is a callback function that will be called at the beginning of the test. It is // meant to be used for things like starting a local backend server. Setup function returns a // context (interface{}) which is passed back into the Teardown and the GetState functions. // pass nil if no setup needed Setup SetupFn // Teardown is a callback function that will be called at the end of the test. It is // meant to be used for things like stopping a local backend server that might have been started during Setup. // pass nil if no teardown is needed Teardown TeardownFn // GetState lets the test provide any (interface{}) adapter specific data to be part of baseline. // Example: for prometheus adapter, the actual metric reported to the local backend can be embedded into the // expected json baseline. // pass nil if no adapter specific state is part of baseline. GetState GetStateFn // Templates supported by Mixer. // If `Templates` is not specified, the default templates inside istio.io/istio/mixer/template.SupportedTmplInfo // are made available to the Mixer. Templates map[string]template.Info // Want is the expected serialized json for the Result struct. // Result.AdapterState is what the callback function `getState`, passed to `RunTest`, returns. // // New test can start of with an empty "{}" string and then // get the baseline from the failure logs upon execution. Want string }
Scenario fully defines an adapter integration test
type SetupFn ¶
type SetupFn func() (ctx interface{}, err error)
SetupFn functions will be called at the beginning of the test
type TeardownFn ¶
type TeardownFn func(ctx interface{})
TeardownFn functions will be called at the end of the test