Version: v0.0.0-...-46d7da7 Latest Latest

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 22 Imported by: 0




This section is empty.


This section is empty.


func RunTest

func RunTest(
	t *testing.T,
	adapterInfo adapter.InfoFn,
	scenario Scenario,

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.


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 CallKind

type CallKind int32

CallKind represents the call to make; check or report.

const (
	// CHECK for  Mixer Check
	CHECK CallKind = iota
	// REPORT for  Mixer Report

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

func NewEnv(t *testing.T) *Env

NewEnv returns an adapter environment that redirects logging output to the given testing context.

func (*Env) DebugEnabled

func (e *Env) DebugEnabled() bool

DebugEnabled logs the provided message.

func (*Env) Debugf

func (e *Env) Debugf(format string, args ...interface{})

Debugf logs the provided message.

func (*Env) ErrorEnabled

func (e *Env) ErrorEnabled() bool

ErrorEnabled logs the provided message.

func (*Env) Errorf

func (e *Env) Errorf(format string, args ...interface{}) error

Errorf logs the provided message and returns it as an error.

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

func (e *Env) GetLogs() []string

GetLogs returns a snapshot of all logs that've been written to this environment

func (*Env) InfoEnabled

func (e *Env) InfoEnabled() bool

InfoEnabled logs the provided message.

func (*Env) Infof

func (e *Env) Infof(format string, args ...interface{})

Infof logs the provided message.

func (*Env) Logger

func (e *Env) Logger() adapter.Logger

Logger returns a logger that writes to testing.T.Log

func (*Env) ScheduleDaemon

func (e *Env) ScheduleDaemon(fn adapter.DaemonFunc)

ScheduleDaemon runs the given function asynchronously.

func (*Env) ScheduleWork

func (e *Env) ScheduleWork(fn adapter.WorkFunc)

ScheduleWork runs the given function asynchronously.

func (*Env) WarnEnabled

func (e *Env) WarnEnabled() bool

WarnEnabled logs the provided message.

func (*Env) Warningf

func (e *Env) Warningf(format string, args ...interface{})

Warningf logs the provided message.

type GetConfigFn

type GetConfigFn func(ctx interface{}) ([]string, error)

GetConfigFn returns configuration that is generated

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

	// GetConfig specifies a way fetch configuration after the initial  setup
	GetConfig GetConfigFn

	// ParallelCalls is a list of test calls to be made to Mixer
	// in parallel.
	ParallelCalls []Call

	// SingleThreaded makes only one call at a time.
	SingleThreaded bool

	// 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

type VerifyResultFn

type VerifyResultFn func(ctx interface{}, result *Result) error

VerifyResultFn if specified is used to do verification.

Jump to

Keyboard shortcuts

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