},
is_loopback_dev: function(dev) {
- let fd = fs.open(`/sys/class/net/${dev}/flags`, "r");
-
- if (!fd)
- return false;
-
- let flags = +fd.read("line");
-
- fd.close();
-
- return !!(flags & 0x8);
+ return !!(+fs.readfile(`/sys/class/net/${dev}/flags`) & 0x8);
},
is_loopback_addr: function(addr) {
}
' 2>/dev/null> timeout <null>
[call] fs.popen cmdline </usr/sbin/nft --terse --json list flowtables inet> mode <r>
-[call] fs.open path </sys/class/net/br-lan/flags> mode <r>
-[call] fs.open path </sys/class/net/br-lan/flags> mode <r>
+[call] fs.readfile path </sys/class/net/br-lan/flags> limit <null>
+[call] fs.readfile path </sys/class/net/br-lan/flags> limit <null>
-- End --
};
},
+ readfile: (fpath, limit) => {
+ let path = sprintf("fs/open~%s.txt", replace(fpath, /[^A-Za-z0-9_-]+/g, '_')),
+ mock = mocklib.read_data_file(path);
+
+ if (!mock) {
+ mocklib.I("No stdout fixture defined for fs.readfile() path %s.", fpath);
+ mocklib.I("Provide a mock output through the following text file:\n%s\n", path);
+
+ return null;
+ }
+
+ mocklib.trace_call("fs", "readfile", { path: fpath, limit });
+
+ return limit ? substr(mock, 0, limit) : mock;
+ },
+
opendir: (path) => {
let file = sprintf("fs/opendir~%s.json", replace(path, /[^A-Za-z0-9_-]+/g, '_')),
mock = mocklib.read_json_file(file),