From eb9c25aaae63b18cb22783c5ba3260b1aabbcb96 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 6 Feb 2022 00:29:54 +0100 Subject: [PATCH] tests: implement fs.opendir() mock interface Signed-off-by: Jo-Philipp Wich --- tests/lib/mocklib/fs.uc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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" }; -- 2.30.2