1 let mocklib = global.mocklib;
8 call: (object, method, args) => {
9 let signature = [ object + "~" + method ];
11 if (type(args) == "object") {
12 for (let i, k in sort(keys(args))) {
13 switch (type(args[k])) {
18 push(signature, k + "-" + replace(args[k], /[^A-Za-z0-9_-]+/g, "_"));
22 push(signature, type(args[k]));
29 for (let i = length(signature); i > 0; i--) {
30 let path = sprintf("ubus/%s.json", join("~", signature)),
31 mock = mocklib.read_json_file(path);
34 self._error = "Invalid argument";
39 mocklib.trace_call("ctx", "call", { object, method, args });
44 push(candidates, path);
48 mocklib.I("No response fixture defined for ubus call %s/%s with arguments %s.", object, method, args);
49 mocklib.I("Provide a mock response through one of the following JSON files:\n%s\n", join("\n", candidates));
51 self._error = "Method not found";
56 disconnect: () => null,
58 error: () => self.error()