Running Tests With Port Contexts
What Is a Port Context?
A port context is a key-value pair set to a specific test port. When port contexts are configured, these configured values are sent to the ioBuster test framework and they are accessible from test scripts.
Similar to port contexts, a user may set --input
option when running a test
using test run
command, however the values received from --input
option will
be applied to all test ports.
How a Port Context Can Be Configured?
ioBuster coordinator comes with three commands for managing port contexts:
Using port add-context
command, a key-value pair can be added to a test port.
The following example shows how to add {hello:'world'}
to a test port port1
.
coordinator # port add-context port1 hello world
You can display all configured port contexts using port list
command.
coordinator # port list
╔══════════════════╤══════════════╤══════╤═══════════════════════════════════╤═══════════════╗
║ Port Name │ Host │ Port │ Tags │ Contexts ║
╟──────────────────┼──────────────┼──────┼───────────────────────────────────┼───────────────╢
║ host1-port1 │ port1 │ 1 │ host1-port1 │ hello : world ║
╚══════════════════╧══════════════╧══════╧═══════════════════════════════════╧═══════════════╝
When both --input
option and a port context are configured, --input
has
higher procedence.
For example, when test run
command is used with --input '{"hello":"abc"}'
with a port context
{"hello":"def"}, the test will run with
{"hello":"abc"}`.
How Can a Test Script Access Contexts
The ioBuster framework API,
utility.getTaskInfo()
,
returns an object that has inputContext
property.
For example, when a port context is configured as {"chamberChannel":"0"}
, a
test script may access the configured value as the following:
const { inputContext } = utility.getTaskInfo()
const { chamberChannel } = inputContext