assert
Assert that two expressions are equal during pipeline execution
assert
The assert action compares two expressions and rejects the request if they are not equal. Use it to verify that variables, attributes, or computed values match expected results during pipeline execution.
Syntax
assert <expected> <actual>;
assert <expected> <actual> "optional message";
The first expression is the expected value and the second is the actual value. If the two values are not equal, the pipeline stops with an error. An optional third argument provides a custom message included in the error output.
Examples
Assert a variable value
backend {
name "JSON_FILE";
query "FIND_USER";
}
assert "admin" user.username;
Assert with a custom error message
assert "expected_group" user.group "User group did not match";
Assert with none
assert none vars.non_existent;
Assert with numeric values
assert 42 vars.answer;
Assert with regex
You can use a regex literal as the expected value to test whether the actual value matches a pattern:
assert /^foo.*bar$/ vars.value;
Assert after filter expressions
assert "bar" vars.test_json | jsonpath("$.foo");
assert "default_value" vars.non_existent | default("default_value");
assert "HELLO" vars.greeting | uppercase;