diff options
| author | Jo-Philipp Wich | 2022-02-05 23:29:54 +0000 |
|---|---|---|
| committer | Jo-Philipp Wich | 2022-02-05 23:33:04 +0000 |
| commit | eb9c25aaae63b18cb22783c5ba3260b1aabbcb96 (patch) | |
| tree | 396ad8e30318e4e74fbe034cb28bb8472c61d2b3 | |
| parent | d30ff48e175fde570ffce5709bf4bf7a9893d00d (diff) | |
| download | firewall4-eb9c25aaae63b18cb22783c5ba3260b1aabbcb96.tar.gz | |
tests: implement fs.opendir() mock interface
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
| -rw-r--r-- | tests/lib/mocklib/fs.uc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/lib/mocklib/fs.uc b/tests/lib/mocklib/fs.uc index 134673e..97521cc 100644 --- a/tests/lib/mocklib/fs.uc +++ b/tests/lib/mocklib/fs.uc @@ -136,5 +136,40 @@ }; }, + opendir: (path) => { + let file = sprintf("fs/opendir~%s.json", replace(path, /[^A-Za-z0-9_-]+/g, '_')), + mock = mocklib.read_json_file(file), + index = 0; + + if (!mock || mock != mock) { + mocklib.I("No stat result fixture defined for fs.opendir() call on %s.", path); + mocklib.I("Provide a mock result through the following JSON file:\n%s\n", file); + + mock = []; + } + + mocklib.trace_call("fs", "opendir", { path }); + + return { + read: function() { + return mock[index++]; + }, + + tell: function() { + return index; + }, + + seek: function(i) { + index = i; + }, + + close: function() {}, + + error: function() { + return null; + } + }; + }, + error: () => "Unspecified error" }; |