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

@ -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);
}