k6test

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package k6test provides mock implementations of k6 elements for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

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? ToGojaValue can be a helper function that takes a goja.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

func NewVU(tb testing.TB, opts ...any) *VU

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

func (v *VU) AssertSamples(assertSample func(s k6metrics.Sample)) int

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

func (v *VU) EndIteration(tb testing.TB, opts ...any)

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) StartIteration added in v1.0.0

func (v *VU) StartIteration(tb testing.TB, opts ...any)

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).

func (*VU) ToGojaValue

func (v *VU) ToGojaValue(i any) goja.Value

ToGojaValue is a convenience method for converting any value to a goja value.

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.

type WithVUID added in v1.0.0

type WithVUID = uint64

WithVUID is used to set the VU id in the IterData for the 'IterStart' event.

Jump to

Keyboard shortcuts

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