From: Jo-Philipp Wich Date: Sat, 5 Feb 2022 23:29:54 +0000 (+0100) Subject: tests: implement fs.opendir() mock interface X-Git-Url: http://git.openwrt.org/openwrt/docs.git?a=commitdiff_plain;h=eb9c25aaae63b18cb22783c5ba3260b1aabbcb96;p=project%2Ffirewall4.git tests: implement fs.opendir() mock interface Signed-off-by: Jo-Philipp Wich --- 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" };