mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
Redis: Add btests for the redis backend
This commit is contained in:
parent
52d94b781a
commit
08bebaa426
10 changed files with 252 additions and 0 deletions
|
@ -0,0 +1,49 @@
|
|||
# @TEST-DOC: Tests that Redis storage backend defaults back to sync mode reading pcaps
|
||||
|
||||
# @TEST-REQUIRES: have-redis
|
||||
# @TEST-PORT: REDIS_PORT
|
||||
|
||||
# Generate a redis.conf file with the port defined above, but without the /tcp at the end of
|
||||
# it. This also sets some paths in the conf to the testing directory.
|
||||
# @TEST-EXEC: cat $FILES/redis.conf | sed "s|%REDIS_PORT%|${REDIS_PORT%/tcp}|g" | sed "s|%RUN_PATH%|$(pwd)|g" > ./redis.conf
|
||||
# @TEST-EXEC: btest-bg-run redis redis-server ../redis.conf
|
||||
# @TEST-EXEC: zeek -r $TRACES/http/get.trace -b %INPUT > out
|
||||
# @TEST-EXEC: btest-bg-wait -k 0
|
||||
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
@load base/frameworks/storage
|
||||
@load policy/frameworks/storage/backend/redis
|
||||
|
||||
# Create a typename here that can be passed down into open_backend()
|
||||
type str: string;
|
||||
|
||||
event zeek_init() {
|
||||
local opts : Storage::Backend::Redis::Options;
|
||||
opts$server_host = "127.0.0.1";
|
||||
opts$server_port = to_port(getenv("REDIS_PORT"));
|
||||
opts$key_prefix = "testing";
|
||||
opts$async_mode = T;
|
||||
|
||||
local key = "key1234";
|
||||
local value = "value5678";
|
||||
|
||||
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
|
||||
|
||||
when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) {
|
||||
print "put result", res;
|
||||
|
||||
when [b, key, value] ( local res2 = Storage::get(b, key) ) {
|
||||
print "get result", res2;
|
||||
print "get result same as inserted", value == (res2 as string);
|
||||
|
||||
Storage::close_backend(b);
|
||||
}
|
||||
timeout 5 sec {
|
||||
print "get requeest timed out";
|
||||
}
|
||||
}
|
||||
timeout 5 sec {
|
||||
print "put request timed out";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
# @TEST-DOC: Tests basic Redis storage backend functions in async mode
|
||||
|
||||
# @TEST-REQUIRES: have-redis
|
||||
# @TEST-PORT: REDIS_PORT
|
||||
|
||||
# Generate a redis.conf file with the port defined above, but without the /tcp at the end of
|
||||
# it. This also sets some paths in the conf to the testing directory.
|
||||
# @TEST-EXEC: cat $FILES/redis.conf | sed "s|%REDIS_PORT%|${REDIS_PORT%/tcp}|g" | sed "s|%RUN_PATH%|$(pwd)|g" > ./redis.conf
|
||||
# @TEST-EXEC: btest-bg-run redis redis-server ../redis.conf
|
||||
# @TEST-EXEC: zeek -b %INPUT > out
|
||||
# @TEST-EXEC: btest-bg-wait -k 0
|
||||
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
@load base/frameworks/storage
|
||||
@load policy/frameworks/storage/backend/redis
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
# Create a typename here that can be passed down into open_backend()
|
||||
type str: string;
|
||||
|
||||
event zeek_init() {
|
||||
local opts : Storage::Backend::Redis::Options;
|
||||
opts$server_host = "127.0.0.1";
|
||||
opts$server_port = to_port(getenv("REDIS_PORT"));
|
||||
opts$key_prefix = "testing";
|
||||
opts$async_mode = T;
|
||||
|
||||
local key = "key1234";
|
||||
local value = "value5678";
|
||||
|
||||
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
|
||||
|
||||
when [b, key, value] ( local res = Storage::put(b, [$key=key, $value=value]) ) {
|
||||
print "put result", res;
|
||||
|
||||
when [b, key, value] ( local res2 = Storage::get(b, key) ) {
|
||||
print "get result", res2;
|
||||
print "get result same as inserted", value == (res2 as string);
|
||||
|
||||
Storage::close_backend(b);
|
||||
|
||||
terminate();
|
||||
}
|
||||
timeout 5 sec {
|
||||
print "get requeest timed out";
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
timeout 5 sec {
|
||||
print "put request timed out";
|
||||
terminate();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
# @TEST-DOC: Tests basic Redis storage backend functions in sync mode, including overwriting
|
||||
|
||||
# @TEST-REQUIRES: have-redis
|
||||
# @TEST-PORT: REDIS_PORT
|
||||
|
||||
# Generate a redis.conf file with the port defined above, but without the /tcp at the end of
|
||||
# it. This also sets some paths in the conf to the testing directory.
|
||||
# @TEST-EXEC: cat $FILES/redis.conf | sed "s|%REDIS_PORT%|${REDIS_PORT%/tcp}|g" | sed "s|%RUN_PATH%|$(pwd)|g" > ./redis.conf
|
||||
# @TEST-EXEC: btest-bg-run redis redis-server ../redis.conf
|
||||
# @TEST-EXEC: zeek -b %INPUT > out
|
||||
# @TEST-EXEC: btest-bg-wait -k 0
|
||||
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
@load base/frameworks/storage
|
||||
@load policy/frameworks/storage/backend/redis
|
||||
|
||||
# Create a typename here that can be passed down into open_backend()
|
||||
type str: string;
|
||||
|
||||
event zeek_init() {
|
||||
local opts : Storage::Backend::Redis::Options;
|
||||
opts$server_host = "127.0.0.1";
|
||||
opts$server_port = to_port(getenv("REDIS_PORT"));
|
||||
opts$key_prefix = "testing";
|
||||
opts$async_mode = F;
|
||||
|
||||
local key = "key1234";
|
||||
local value = "value1234";
|
||||
|
||||
local b = Storage::open_backend(Storage::REDIS, opts, str, str);
|
||||
|
||||
local res = Storage::put(b, [$key=key, $value=value, $async_mode=F]);
|
||||
print "put result", res;
|
||||
|
||||
local res2 = Storage::get(b, key, F);
|
||||
print "get result", res2;
|
||||
print "get result same as inserted", value == (res2 as string);
|
||||
|
||||
local value2 = "value5678";
|
||||
res = Storage::put(b, [$key=key, $value=value2, $overwrite=T, $async_mode=F]);
|
||||
print "overwrite put result", res;
|
||||
|
||||
res2 = Storage::get(b, key, F);
|
||||
print "get result", res2;
|
||||
print "get result same as inserted after overwrite", value == (res2 as string);
|
||||
|
||||
Storage::close_backend(b);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue