Documentation ¶
Overview ¶
Package k6test provides mock implementations of k6 elements for testing purposes.
Index ¶
- func ToPromise(tb testing.TB, gv sobek.Value) *sobek.Promise
- type TestExecutor
- func (te *TestExecutor) GetDescription(*k6lib.ExecutionTuple) string
- func (te *TestExecutor) GetExecutionRequirements(*k6lib.ExecutionTuple) []k6lib.ExecutionStep
- func (te *TestExecutor) HasWork(*k6lib.ExecutionTuple) bool
- func (te *TestExecutor) NewExecutor(*k6lib.ExecutionState, *logrus.Entry) (k6lib.Executor, error)
- type VU
- func (v *VU) ActivateVU()
- func (v *VU) AssertSamples(assertSample func(s k6metrics.Sample)) int
- func (v *VU) EndIteration(tb testing.TB, opts ...any)
- func (v *VU) RunAsync(tb testing.TB, js string, args ...any) (sobek.Value, error)
- func (v *VU) RunOnEventLoop(tb testing.TB, js string, args ...any) (sobek.Value, error)
- func (v *VU) RunPromise(tb testing.TB, js string, args ...any) *sobek.Promise
- func (v *VU) SetVar(tb testing.TB, name string, value any)
- func (v *VU) StartIteration(tb testing.TB, opts ...any)
- func (v *VU) ToSobekValue(i any) sobek.Value
- type WithIteration
- type WithSamples
- type WithScenarioName
- type WithTracerProvider
- type WithVUID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type TestExecutor ¶ added in v1.0.0
type TestExecutor struct {
k6executor.BaseConfig
}
TestExecutor is a k6lib.ExecutorConfig implementation for testing purposes.
func (*TestExecutor) GetDescription ¶ added in v1.0.0
func (te *TestExecutor) GetDescription(*k6lib.ExecutionTuple) string
GetDescription returns a mock Executor description.
func (*TestExecutor) GetExecutionRequirements ¶ added in v1.0.0
func (te *TestExecutor) GetExecutionRequirements(*k6lib.ExecutionTuple) []k6lib.ExecutionStep
GetExecutionRequirements is a dummy implementation that just returns nil.
func (*TestExecutor) HasWork ¶ added in v1.0.0
func (te *TestExecutor) HasWork(*k6lib.ExecutionTuple) bool
HasWork is a dummy implementation that returns true.
func (*TestExecutor) NewExecutor ¶ added in v1.0.0
func (te *TestExecutor) NewExecutor(*k6lib.ExecutionState, *logrus.Entry) (k6lib.Executor, error)
NewExecutor is a dummy implementation that just returns nil.
type VU ¶
type VU struct { *k6modulestest.VU Loop *k6eventloop.EventLoop TestRT *k6modulestest.Runtime // contains filtered or unexported fields }
VU is a k6 VU instance. TODO: Do we still need this VU wrapper? ToSobekValue can be a helper function that takes a sobek.Runtime (although it's not much of a helper from calling ToValue(i) directly...), and we can access EventLoop from modulestest.Runtime.EventLoop.
func NewVU ¶
NewVU returns a mock k6 VU.
opts can be one of the following:
- WithSamples: a bidirectional channel that will be used to emit metrics.
- env.LookupFunc: a lookup function that will be used to lookup environment variables.
- WithTracerProvider: a TracerProvider that will be set as the VU TracerProvider.
func (*VU) ActivateVU ¶ added in v1.0.0
func (v *VU) ActivateVU()
ActivateVU mimicks activation of the VU as in k6. It transitions the VU from the init stage to the execution stage by setting the VU's state to the state that was passed to NewVU.
func (*VU) AssertSamples ¶ added in v0.6.0
AssertSamples asserts each sample VU received since AssertSamples is last called, then it returns the number of received samples.
func (*VU) EndIteration ¶ added in v1.0.0
EndIteration generates a new IterEnd event through the VU event system.
opts can be used to parameterize the iteration data such as:
- WithScenarioName: sets the scenario name (default is 'default').
- WithVUID: sets the VUID (default 1).
- WithIteration: sets the iteration (default 0).
func (*VU) RunAsync ¶ added in v1.6.0
RunAsync runs the given JavaScript code on the VU's event loop and returns the result as a sobek.Value.
func (*VU) RunOnEventLoop ¶ added in v1.6.0
RunOnEventLoop runs the given JavaScript code on the VU's event loop and returns the result as a sobek.Value.
func (*VU) RunPromise ¶ added in v1.6.0
RunPromise runs the given JavaScript code on the VU's event loop and returns the result as a *sobek.Promise.
func (*VU) SetVar ¶ added in v1.6.0
SetVar sets a variable in the VU's sobek runtime's global scope.
func (*VU) StartIteration ¶ added in v1.0.0
StartIteration generates a new IterStart event through the VU event system.
opts can be used to parameterize the iteration data such as:
- WithScenarioName: sets the scenario name (default is 'default').
- WithVUID: sets the VUID (default 1).
- WithIteration: sets the iteration (default 0).
type WithIteration ¶ added in v1.0.0
type WithIteration = int64
WithIteration is used to set the iteration in the IterData for the 'IterStart' event.
type WithSamples ¶ added in v1.0.0
type WithSamples chan k6metrics.SampleContainer
WithSamples is used to indicate we want to use a bidirectional channel so that the test can read the metrics being emitted to the channel.
type WithScenarioName ¶ added in v1.0.0
type WithScenarioName = string
WithScenarioName is used to set the scenario name in the IterData for the 'IterStart' event.
type WithTracerProvider ¶ added in v1.3.0
type WithTracerProvider k6lib.TracerProvider
WithTracerProvider allows to set the VU TracerProvider.