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
| Property | Description |
|---|---|
| Session | Initial status of the session. |
| OverrideConfig | Temporary modification of the configuration. |
| iterations | Measured iterations. |
| Warmove | Warm up. |
| BenchSampleRate | Allocations sampling frequency. |
Session
Session is a map that initializes the session status before the first step.
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.
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.
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
OverrideConfigfor 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.