Make backend options a record, move actual options to be sub-records

This commit is contained in:
Tim Wojtulewicz 2025-02-06 14:30:10 -07:00
parent 64f3969434
commit a485b1d237
23 changed files with 71 additions and 73 deletions

View file

@ -1,4 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/storage.zeek, line 41: Failed to retrieve data: Failed to find key
error in <...>/sync.zeek, line 74: Failed to open backend Storage::STORAGEDUMMY: open_fail was set to true, returning error (Storage::Sync::__open_backend(Storage::Sync::btype, Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type))
error in <...>/sync.zeek, line 79: Invalid storage handle (Storage::Sync::__close_backend(Storage::Sync::backend) and F)
error in <...>/storage.zeek, line 45: Failed to retrieve data: Failed to find key
error in <...>/sync.zeek, line 75: Failed to open backend Storage::STORAGEDUMMY: open_fail was set to true, returning error (Storage::Sync::__open_backend(Storage::Sync::btype, to_any_coerce Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type))
error in <...>/sync.zeek, line 80: Invalid storage handle (Storage::Sync::__close_backend(Storage::Sync::backend) and F)

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/sync.zeek, line 74: Failed to open backend Storage::SQLITE: SQLite call failed: unable to open database file (Storage::Sync::__open_backend(Storage::Sync::btype, Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type))
error in <...>/sync.zeek, line 84: Failed to store data: type of key passed (count) does not match backend's key type (str) (Storage::Sync::__put(Storage::Sync::backend, Storage::Sync::args$key, Storage::Sync::args$value, Storage::Sync::args$overwrite, Storage::Sync::args$expire_time))
error in <...>/sync.zeek, line 75: Failed to open backend Storage::SQLITE: SQLite call failed: unable to open database file (Storage::Sync::__open_backend(Storage::Sync::btype, to_any_coerce Storage::Sync::options, Storage::Sync::key_type, Storage::Sync::val_type))
error in <...>/sync.zeek, line 85: Failed to store data: type of key passed (count) does not match backend's key type (str) (Storage::Sync::__put(Storage::Sync::backend, Storage::Sync::args$key, Storage::Sync::args$value, Storage::Sync::args$overwrite, Storage::Sync::args$expire_time))

View file

@ -19,7 +19,8 @@ zeek::storage::BackendPtr StorageDummy::Instantiate(std::string_view tag) {
* with a corresponding message.
*/
zeek::storage::ErrorResult StorageDummy::DoOpen(zeek::RecordValPtr options, zeek::storage::OpenResultCallback* cb) {
bool open_fail = options->GetField<zeek::BoolVal>("open_fail")->Get();
zeek::RecordValPtr backend_options = options->GetField<zeek::RecordVal>("dummy");
bool open_fail = backend_options->GetField<zeek::BoolVal>("open_fail")->Get();
if ( open_fail )
return "open_fail was set to true, returning error";

View file

@ -17,9 +17,13 @@ type StorageDummyOpts : record {
open_fail: bool;
};
redef record Storage::BackendOptions += {
dummy: StorageDummyOpts &optional;
};
event zeek_init() {
local opts : StorageDummyOpts;
opts$open_fail = F;
local opts : Storage::BackendOptions;
opts$dummy = [$open_fail = F];
local key = "key1234";
local value = "value5678";
@ -49,7 +53,7 @@ event zeek_init() {
get_res?$val, put_res, erase_res));
# Test failing to open the handle and test closing an invalid handle.
opts$open_fail = T;
opts$dummy$open_fail = T;
local b2 = Storage::Sync::open_backend(Storage::STORAGEDUMMY, opts, str, str);
Storage::Sync::close_backend(b2);
}

View file

@ -37,9 +37,8 @@ type tbl: table[count] of string;
event zeek_init() {
# Create a database file in the .tmp directory with a 'testing' table
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "types_test.sqlite";
opts$table_name = "types_testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "types_test.sqlite", $table_name = "types_testing"];
local key : Rec;
key$hello = "hello";

View file

@ -12,9 +12,8 @@ type str: string;
event zeek_init() {
# Create a database file in the .tmp directory with a 'testing' table
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "storage-test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "storage-test.sqlite", $table_name = "testing"];
local key = "key1234";

View file

@ -28,9 +28,8 @@ event check_removed() {
}
event setup_test() {
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "storage-test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "storage-test.sqlite", $table_name = "testing"];
backend = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);

View file

@ -11,9 +11,8 @@
type str: string;
event zeek_init() {
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "storage-test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "storage-test.sqlite", $table_name = "testing"];
local key = "key1234";
local value = "value7890";

View file

@ -20,11 +20,8 @@
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 opts : Storage::BackendOptions;
opts$redis = [$server_host = "127.0.0.1", $server_port = to_port(getenv("REDIS_PORT")), $key_prefix = "testing", $async_mode = T];
local key = "key1234";
local value = "value5678";

View file

@ -22,11 +22,8 @@ redef exit_only_after_terminate = T;
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 opts : Storage::BackendOptions;
opts$redis = [$server_host = "127.0.0.1", $server_port = to_port(getenv("REDIS_PORT")), $key_prefix = "testing", $async_mode = T];
local key = "key1234";
local value = "value5678";

View file

@ -40,11 +40,8 @@ global backend: opaque of Storage::BackendHandle;
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 opts : Storage::BackendOptions;
opts$redis = [$server_host = "127.0.0.1", $server_port = to_port(getenv("REDIS_PORT")), $key_prefix = "testing", $async_mode = F];
backend = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
}

View file

@ -34,11 +34,8 @@ event check_removed() {
}
event setup_test() {
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 opts : Storage::BackendOptions;
opts$redis = [$server_host = "127.0.0.1", $server_port = to_port(getenv("REDIS_PORT")), $key_prefix = "testing", $async_mode = F];
b = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);

View file

@ -19,11 +19,8 @@
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 opts : Storage::BackendOptions;
opts$redis = [$server_host = "127.0.0.1", $server_port = to_port(getenv("REDIS_PORT")), $key_prefix = "testing", $async_mode = F];
local key = "key1234";
local value = "value1234";

View file

@ -14,9 +14,8 @@ type str: string;
event zeek_init() {
# Create a database file in the .tmp directory with a 'testing' table
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "test.sqlite", $table_name = "testing"];
local key = "key1234";
local value = "value5678";

View file

@ -13,9 +13,8 @@ type str: string;
event zeek_init() {
# Create a database file in the .tmp directory with a 'testing' table
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "test.sqlite", $table_name="testing"];
local key = "key1234";
local value = "value5678";

View file

@ -12,15 +12,15 @@ type str: string;
event zeek_init() {
# Test opening a database with an invalid path
local opts : Storage::Backend::SQLite::Options;
opts$database_path = "/this/path/should/not/exist/test.sqlite";
opts$table_name = "testing";
local opts : Storage::BackendOptions;
opts$sqlite = [$database_path = "/this/path/should/not/exist/test.sqlite",
$table_name = "testing"];
# This should report an error in .stderr and reporter.log
local b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
# Open a valid database file
opts$database_path = "test.sqlite";
opts$sqlite$database_path = "test.sqlite";
b = Storage::Sync::open_backend(Storage::SQLITE, opts, str, str);
local bad_key: count = 12345;