X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=tests%2Flib%2Fmocklib%2Fubus.uc;h=67be90299570381c1c8002ab77810c72dec35b10;hb=fde80708d63d54be18037c598d1e6aef0c65ca08;hp=985e004a9d825ba157a6197835d2693b92804839;hpb=53caa1a762125a71389a486aa913e4fbdf3650cf;p=project%2Ffirewall4.git diff --git a/tests/lib/mocklib/ubus.uc b/tests/lib/mocklib/ubus.uc index 985e004..67be902 100644 --- a/tests/lib/mocklib/ubus.uc +++ b/tests/lib/mocklib/ubus.uc @@ -1,69 +1,68 @@ -{% - let mocklib = global.mocklib; - - return { - connect: function() { - let self = this; - - return { - call: (object, method, args) => { - let signature = [ object + "~" + method ]; - - if (type(args) == "object") { - for (let i, k in sort(keys(args))) { - switch (type(args[k])) { - case "string": - case "double": - case "bool": - case "int": - push(signature, k + "-" + replace(args[k], /[^A-Za-z0-9_-]+/g, "_")); - break; - - default: - push(signature, type(args[k])); - } +let mocklib = global.mocklib; + +return { + connect: function() { + let self = this; + + return { + call: (object, method, args) => { + let signature = [ object + "~" + method ]; + + if (type(args) == "object") { + for (let i, k in sort(keys(args))) { + switch (type(args[k])) { + case "string": + case "double": + case "bool": + case "int": + push(signature, k + "-" + replace(args[k], /[^A-Za-z0-9_-]+/g, "_")); + break; + + default: + push(signature, type(args[k])); } } + } - let candidates = []; + let candidates = []; - for (let i = length(signature); i > 0; i--) { - let path = sprintf("ubus/%s.json", join("~", signature)), - mock = mocklib.read_json_file(path); + for (let i = length(signature); i > 0; i--) { + let path = sprintf("ubus/%s.json", join("~", signature)), + mock = mocklib.read_json_file(path); - if (mock != mock) { - self._error = "Invalid argument"; + if (mock != mock) { + self._error = "Invalid argument"; - return null; - } - else if (mock) { - mocklib.trace_call("ctx", "call", { object, method, args }); - - return mock; - } + return null; + } + else if (mock) { + mocklib.trace_call("ctx", "call", { object, method, args }); - push(candidates, path); - pop(signature); + return mock; } - mocklib.I("No response fixture defined for ubus call %s/%s with arguments %s.", object, method, args); - mocklib.I("Provide a mock response through one of the following JSON files:\n%s\n", join("\n", candidates)); + push(candidates, path); + pop(signature); + } + + mocklib.I("No response fixture defined for ubus call %s/%s with arguments %s.", object, method, args); + mocklib.I("Provide a mock response through one of the following JSON files:\n%s\n", join("\n", candidates)); - self._error = "Method not found"; + self._error = "Method not found"; - return null; - }, + return null; + }, - disconnect: () => null, + disconnect: () => null, - error: () => self.error() - }; - }, + error: () => self.error() + }; + }, - error: function() { - let e = this._error; - delete this._error; + error: function() { + let e = this._error; + delete this._error; - return e; - } - }; + return e; + } +};