zeek/testing/btest/core/event-groups/existence.zeek
Arne Welzel ba4b8faea2 zeek.bif: Add has_event_group() / has_module_events()
Introduce helpers to determine if a given attribute or module event
group exists given a string.
2022-12-09 16:59:07 +01:00

31 lines
1.2 KiB
Text

# @TEST-DOC: Test for has_module_events and has_event_group
# @TEST-EXEC: zeek -b %INPUT > output
# @TEST-EXEC: btest-diff output
module TestMyProtocol::Logging;
event http_request(c: connection, method: string, original_URI: string,
unescaped_URI: string, version: string) {}
module TestMyProtocol;
event http_request(c: connection, method: string, original_URI: string,
unescaped_URI: string, version: string) &group="test-my-protocol" {}
module Test;
function assert_expected(msg: string, expected: bool, actual: bool)
{
local prefix = expected == actual ? "PASS" : "FAIL";
print fmt("%s: %s (%s == %s)", prefix, msg, expected, actual);
}
event zeek_init()
{
assert_expected("eg: has test-my-protocol", T, has_event_group("test-my-protocol"));
assert_expected("eg: has not test-my-protocol-nope", F, has_event_group("test-my-protocol-nope"));
assert_expected("eg: has not eg TestMyProtocol::Logging", F, has_event_group("TestMyProtocol::Logging"));
assert_expected("me: has TestMyProtocol::Logging", T, has_module_events("TestMyProtocol::Logging"));
assert_expected("me: has not test-my-protocol", F, has_module_events("test-my-protocol"));
}