Skip to main content

Selection functions

var

Commentary

added in 0.0.5

Look up a variable defined in the top-level vars or varsOnce sections, optionally drilling into its subvalue with path. Vars may refer to other variables. If you make multiple references to the same var in a single generator, you are guaranteed to get the same value each time. Values in varsOnce are only ever evaluated once, and then locked for the duration of the generator, as the name implies.


Examples

Retrieving a variable

{
"generators": [
{
"topic": "users",
"vars": {
"val1": {
"_gen": "boolean"
}
},
"varsOnce": {
"val2": {
"_gen": "boolean"
}
},
"value": {
"val1": {
"_gen": "var",
"var": "val1"
},
"val2": {
"_gen": "var",
"var": "val2"
}
}
}
],
"connections": {
"kafka": {
"kind": "kafka",
"producerConfigs": {
"bootstrap.servers": "localhost:9092",
"key.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer",
"value.serializer": "io.shadowtraffic.kafka.serdes.JsonSerializer"
}
}
}
}
[
{
"val1": false,
"val2": false
},
{
"val1": true,
"val2": false
},
{
"val1": true,
"val2": false
},
{
"val1": false,
"val2": false
},
{
"val1": true,
"val2": false
}
]

Specification

JSON schema

{
"type": "object",
"properties": {
"var": {
"type": "string"
},
"path": {
"type": "array",
"items": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string"
}
]
}
}
},
"required": [
"var"
]
}