Configuration

test.Config defines the environment used by a test.Execute().

Allows to establish the initial session, to temporarily modify server.Config and control the options used during the Benchmarks.


Properties

PropertyDescription
SessionInitial status of the session.
OverrideConfigTemporary modification of the configuration.
iterationsMeasured iterations.
WarmoveWarm up.
BenchSampleRateAllocations sampling frequency.

Session

Session is a map that initializes the session status before the first step.

gox
config := test.Config{
	Session: test.Session{
		"user": "George",
		"authenticated": true,
	},
}

Handlers access these values by ctx.Session. Changes made during a pipeline are preserved until the end of the execution.


OverrideConfig

OverrideConfig gets a pointer to server.Config and allows to modify the configuration only for that execution.

gox
import (
	"github.com/gox-lang/gox/server"
	"github.com/gox-lang/gox/test"
)

config := test.Config{
	OverrideConfig: func(config *server.Config) {
		config.Dev.Enabled = true
	},
}

When using this property, GOX creates a runtime for the modified configuration. The base configuration of the project is not overwritten.


Benchmark configuration

Iterations, Warmup and BenchSampleRate are ignored during functional tests.

gox
config := test.Config{
	Iterations: 1000,
	Warmup: 100,
	BenchSampleRate: 0.1,
}

See Benchmarks to know the effect of each value and the metrics generated.


Isolation

The session and the runtime belong to a call from test.Execute(). A new execution begins with the values declared in its own test.Config.

This isolation allows you to test different configurations or users from the same function without accidentally sharing your status.


Integration with Go

OverrideConfig is an ordinary function that receives the public configuration structure of the server. You can modify any property exposed by server.Config before building the isolated runtime.

Session uses a value map compatible with the session system. The runner installs these values as an initial state and allows handlers to apply the normal life cycle of the session.


Best practices

  • Declares only the state of the session necessary for the case.
  • Use OverrideConfig for temporary variations, not to replace the normal project configuration.
  • Executs cases with different initial states through independent calls.
  • Keep the Benchmark options out of the functional tests.
  • Avoid depending on the state produced by another test function.

See also

Next step

Continue with Execution to discover, select and run project tests.

Execution