mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Use double quotes
Convert existing mix of double quotes and single quotes to only use double quotes unless the string contains double quotes.
This commit is contained in:
1 parent
efd759bec5
commit
34aaeee354
48 files changed
+708
-712
No files matched your search
+11
-11
@@ -1,10 +1,10 @@
|
||||
const assert = require('assert').strict;
|
||||
const chalk = require('chalk');
|
||||
const assert = require("assert").strict;
|
||||
const chalk = require("chalk");
|
||||
|
||||
const errors = require('lib/errors');
|
||||
const { testLines } = require('./lib/factorio/lines');
|
||||
const clusterctl = require('../clusterctl.js');
|
||||
const mock = require('./mock');
|
||||
const errors = require("lib/errors");
|
||||
const { testLines } = require("./lib/factorio/lines");
|
||||
const clusterctl = require("../clusterctl.js");
|
||||
const mock = require("./mock");
|
||||
|
||||
|
||||
describe("clusterctl", function() {
|
||||
@@ -24,13 +24,13 @@ describe("clusterctl", function() {
|
||||
});
|
||||
|
||||
let mockConnector = new mock.MockConnector();
|
||||
mockConnector.on('send', function(message) {
|
||||
if (message.type === 'list_instances_request') {
|
||||
this.emit('message', {
|
||||
seq: 1, type: 'list_instances_response',
|
||||
mockConnector.on("send", function(message) {
|
||||
if (message.type === "list_instances_request") {
|
||||
this.emit("message", {
|
||||
seq: 1, type: "list_instances_response",
|
||||
data: {
|
||||
seq: message.seq,
|
||||
list: [{ id: 57, assigned_slave: 4, name: 'Test Instance' }],
|
||||
list: [{ id: 57, assigned_slave: 4, name: "Test Instance" }],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const validateHTML = require('html5-validator');
|
||||
const parallel = require('mocha.parallel');
|
||||
const validateHTML = require("html5-validator");
|
||||
const parallel = require("mocha.parallel");
|
||||
|
||||
const link = require("lib/link");
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
|
||||
await fs.ensureDir(writePath);
|
||||
logFile = fs.createWriteStream(path.join(writePath, "log.txt"), "utf8");
|
||||
server.on('output', function(output) {
|
||||
server.on("output", function(output) {
|
||||
logFile.write(JSON.stringify(output) + "\n");
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
log(".sendRcon()");
|
||||
|
||||
let result = await server.sendRcon("/sc rcon.print('success')");
|
||||
assert.equal(result, 'success\n');
|
||||
assert.equal(result, "success\n");
|
||||
});
|
||||
it("throws on non-empty response when enabled", async function() {
|
||||
slowTest(this);
|
||||
@@ -155,14 +155,14 @@ describe("Integration of lib/factorio/server", function() {
|
||||
pass = true;
|
||||
}
|
||||
}
|
||||
server.on('output', filter);
|
||||
server.on("output", filter);
|
||||
|
||||
await server.startScenario("test_scenario");
|
||||
|
||||
log(".stop()");
|
||||
await server.stop();
|
||||
|
||||
server.off('output', filter);
|
||||
server.off("output", filter);
|
||||
assert(pass, "server did not output line from test scenario");
|
||||
});
|
||||
});
|
||||
@@ -191,7 +191,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
|
||||
await server.start("test.zip");
|
||||
if (!server._rconReady) {
|
||||
await events.once(server, 'rcon-ready');
|
||||
await events.once(server, "rcon-ready");
|
||||
}
|
||||
server.sendRcon("/c while true do end").catch(() => {});
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
@@ -210,7 +210,7 @@ describe("Integration of lib/factorio/server", function() {
|
||||
log(".start() for kill detection");
|
||||
|
||||
let startPromise = server.start("test.zip");
|
||||
server.once('output', () => server._server.kill('SIGKILL'));
|
||||
server.once("output", () => server._server.kill("SIGKILL"));
|
||||
|
||||
await assert.rejects(
|
||||
startPromise,
|
||||
|
||||
+37
-37
@@ -19,14 +19,14 @@ describe("lib/database", function() {
|
||||
|
||||
it("should throw convert a map to an object", function() {
|
||||
assert.deepEqual(
|
||||
database.mapToObject(new Map([['a', 1], ['b', true]])),
|
||||
{'a': 1, 'b': true}
|
||||
database.mapToObject(new Map([["a", 1], ["b", true]])),
|
||||
{"a": 1, "b": true}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadJsonAsMap()", function() {
|
||||
let badTypes = ['null', 'array', 'number', 'string', 'boolean'];
|
||||
let badTypes = ["null", "array", "number", "string", "boolean"];
|
||||
|
||||
for (let type of badTypes) {
|
||||
it(`should reject on ${type} JSON`, async function() {
|
||||
@@ -47,7 +47,7 @@ describe("lib/database", function() {
|
||||
it("should work on object JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonAsMap(path.join("test", "file", "json", "load_map.json")),
|
||||
new Map([['a', 1], ['b', true]])
|
||||
new Map([["a", 1], ["b", true]])
|
||||
);
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ describe("lib/database", function() {
|
||||
await fs.unlink(testFile);
|
||||
} catch (err) {
|
||||
/* istanbul ignore if */
|
||||
if (err.code !== 'ENOENT') {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -75,18 +75,18 @@ describe("lib/database", function() {
|
||||
|
||||
await deleteTestFile();
|
||||
await database.saveMapAsJson(
|
||||
testFile, new Map([['c', {}], ['d', "foo"]])
|
||||
testFile, new Map([["c", {}], ["d", "foo"]])
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
await fs.readFile(testFile, {encoding: 'utf-8'}),
|
||||
await fs.readFile(testFile, {encoding: "utf-8"}),
|
||||
'{\n "c": {},\n "d": "foo"\n}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadJsonArrayAsMap()", function() {
|
||||
let badTypes = ['null', 'object', 'number', 'string', 'boolean'];
|
||||
let badTypes = ["null", "object", "number", "string", "boolean"];
|
||||
|
||||
for (let type of badTypes) {
|
||||
it(`should reject on ${type} JSON`, async function() {
|
||||
@@ -121,7 +121,7 @@ describe("lib/database", function() {
|
||||
it("should work on array JSON", async function() {
|
||||
assert.deepEqual(
|
||||
await database.loadJsonArrayAsMap(path.join("test", "file", "json", "load_array_map.json")),
|
||||
new Map([['a', {id: 'a'}], ['b', {id: 'b'}]])
|
||||
new Map([["a", {id: "a"}], ["b", {id: "b"}]])
|
||||
);
|
||||
});
|
||||
|
||||
@@ -141,7 +141,7 @@ describe("lib/database", function() {
|
||||
await fs.unlink(testFile);
|
||||
} catch (err) {
|
||||
/* istanbul ignore if */
|
||||
if (err.code !== 'ENOENT') {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -149,11 +149,11 @@ describe("lib/database", function() {
|
||||
|
||||
await deleteTestFile();
|
||||
await database.saveMapAsJsonArray(
|
||||
testFile, new Map([['c', {id: 'c'}], ['d', {id: 'd'}]])
|
||||
testFile, new Map([["c", {id: "c"}], ["d", {id: "d"}]])
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
await fs.readFile(testFile, {encoding: 'utf-8'}),
|
||||
await fs.readFile(testFile, {encoding: "utf-8"}),
|
||||
'[\n {\n "id": "c"\n },\n {\n "id": "d"\n }\n]'
|
||||
);
|
||||
});
|
||||
@@ -167,18 +167,18 @@ describe("lib/database", function() {
|
||||
});
|
||||
|
||||
it("should restore the passed serialized database", function() {
|
||||
let items = new database.ItemDatabase({'a': 1, 'b': 2});
|
||||
assert.deepEqual(items._items, new Map([['a', 1], ['b', 2]]));
|
||||
let items = new database.ItemDatabase({"a": 1, "b": 2});
|
||||
assert.deepEqual(items._items, new Map([["a", 1], ["b", 2]]));
|
||||
});
|
||||
|
||||
it("should throw on invalid serialized database", function() {
|
||||
assert.throws(
|
||||
() => new database.ItemDatabase({'a': NaN}),
|
||||
() => new database.ItemDatabase({"a": NaN}),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => new database.ItemDatabase({'a': 'a'}),
|
||||
() => new database.ItemDatabase({"a": "a"}),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
});
|
||||
@@ -186,32 +186,32 @@ describe("lib/database", function() {
|
||||
|
||||
describe(".serialize()", function() {
|
||||
it("should return a serialized database", function() {
|
||||
let items = new database.ItemDatabase({'a': 10});
|
||||
assert.deepEqual(items.serialize(), {'a': 10});
|
||||
let items = new database.ItemDatabase({"a": 10});
|
||||
assert.deepEqual(items.serialize(), {"a": 10});
|
||||
});
|
||||
|
||||
it("should remove zero count entries", function() {
|
||||
let items = new database.ItemDatabase({'a': 0});
|
||||
let items = new database.ItemDatabase({"a": 0});
|
||||
assert.deepEqual(items.serialize(), {});
|
||||
});
|
||||
});
|
||||
|
||||
describe(".size", function() {
|
||||
it("should give an approximate size of the database", function() {
|
||||
let items = new database.ItemDatabase({'a': 10});
|
||||
let items = new database.ItemDatabase({"a": 10});
|
||||
assert.equal(items.size, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".getItemCount()", function() {
|
||||
it("should return the count of the given item", function() {
|
||||
let items = new database.ItemDatabase({'a': 10});
|
||||
assert.equal(items.getItemCount('a'), 10);
|
||||
let items = new database.ItemDatabase({"a": 10});
|
||||
assert.equal(items.getItemCount("a"), 10);
|
||||
});
|
||||
|
||||
it("should return zero if item does not exist", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
assert.equal(items.getItemCount('b'), 0);
|
||||
assert.equal(items.getItemCount("b"), 0);
|
||||
});
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
@@ -226,14 +226,14 @@ describe("lib/database", function() {
|
||||
describe(".addItem()", function() {
|
||||
it("should add a new item", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
items.addItem('a', 10);
|
||||
assert.deepEqual(items._items, new Map([['a', 10]]));
|
||||
items.addItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 10]]));
|
||||
})
|
||||
|
||||
it("should add an existing item", function() {
|
||||
let items = new database.ItemDatabase({'a': 10});
|
||||
items.addItem('a', 10);
|
||||
assert.deepEqual(items._items, new Map([['a', 20]]));
|
||||
let items = new database.ItemDatabase({"a": 10});
|
||||
items.addItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 20]]));
|
||||
})
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
@@ -247,11 +247,11 @@ describe("lib/database", function() {
|
||||
it("should throw on invalid count", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.addItem('a', NaN),
|
||||
() => items.addItem("a", NaN),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
assert.throws(
|
||||
() => items.addItem('a', "1"),
|
||||
() => items.addItem("a", "1"),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
});
|
||||
@@ -259,15 +259,15 @@ describe("lib/database", function() {
|
||||
|
||||
describe(".removeItem()", function() {
|
||||
it("should remove an existing item", function() {
|
||||
let items = new database.ItemDatabase({'a': 20});
|
||||
items.removeItem('a', 10);
|
||||
assert.deepEqual(items._items, new Map([['a', 10]]));
|
||||
let items = new database.ItemDatabase({"a": 20});
|
||||
items.removeItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", 10]]));
|
||||
})
|
||||
|
||||
it("should turn a non-existing item negative", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
items.removeItem('a', 10);
|
||||
assert.deepEqual(items._items, new Map([['a', -10]]));
|
||||
items.removeItem("a", 10);
|
||||
assert.deepEqual(items._items, new Map([["a", -10]]));
|
||||
})
|
||||
|
||||
it("should throw on invalid name", function() {
|
||||
@@ -281,11 +281,11 @@ describe("lib/database", function() {
|
||||
it("should throw on invalid count", function() {
|
||||
let items = new database.ItemDatabase();
|
||||
assert.throws(
|
||||
() => items.removeItem('a', 'b'),
|
||||
() => items.removeItem("a", "b"),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
assert.throws(
|
||||
() => items.removeItem('a', "1"),
|
||||
() => items.removeItem("a", "1"),
|
||||
new Error("count must be a number")
|
||||
);
|
||||
});
|
||||
|
||||
+35
-35
@@ -4,10 +4,10 @@ let testLines = new Map([
|
||||
[
|
||||
" 1.306 Info RemoteCommandProcessor.cpp:131: Starting RCON interface at port 4000",
|
||||
{
|
||||
format: 'seconds',
|
||||
time: '1.306',
|
||||
type: 'log',
|
||||
level: 'Info',
|
||||
format: "seconds",
|
||||
time: "1.306",
|
||||
type: "log",
|
||||
level: "Info",
|
||||
file: "RemoteCommandProcessor.cpp:131",
|
||||
message: "Starting RCON interface at port 4000",
|
||||
}
|
||||
@@ -15,10 +15,10 @@ let testLines = new Map([
|
||||
[
|
||||
" 0.622 Warning FileUtil.cpp:527: test not found; using test.zip",
|
||||
{
|
||||
format: 'seconds',
|
||||
time: '0.622',
|
||||
type: 'log',
|
||||
level: 'Warning',
|
||||
format: "seconds",
|
||||
time: "0.622",
|
||||
type: "log",
|
||||
level: "Warning",
|
||||
file: "FileUtil.cpp:527",
|
||||
message: "test not found; using test.zip",
|
||||
}
|
||||
@@ -26,10 +26,10 @@ let testLines = new Map([
|
||||
[
|
||||
" 0.554 Error Main.cpp:839: require_user_verification must be enabled for public games.",
|
||||
{
|
||||
format: 'seconds',
|
||||
time: '0.554',
|
||||
type: 'log',
|
||||
level: 'Error',
|
||||
format: "seconds",
|
||||
time: "0.554",
|
||||
type: "log",
|
||||
level: "Error",
|
||||
file: "Main.cpp:839",
|
||||
message: "require_user_verification must be enabled for public games.",
|
||||
}
|
||||
@@ -37,27 +37,27 @@ let testLines = new Map([
|
||||
[
|
||||
" 640.910 Quitting: remote-quit.",
|
||||
{
|
||||
format: 'seconds',
|
||||
time: '640.910',
|
||||
type: 'generic',
|
||||
format: "seconds",
|
||||
time: "640.910",
|
||||
type: "generic",
|
||||
message: "Quitting: remote-quit.",
|
||||
}
|
||||
],
|
||||
[
|
||||
"1641.421 Goodbye",
|
||||
{
|
||||
format: 'seconds',
|
||||
time: '1641.421',
|
||||
type: 'generic',
|
||||
format: "seconds",
|
||||
time: "1641.421",
|
||||
type: "generic",
|
||||
message: "Goodbye",
|
||||
}
|
||||
],
|
||||
[
|
||||
"2019-01-20 10:30:04 [JOIN] User joined the game",
|
||||
{
|
||||
format: 'date',
|
||||
time: '2019-01-20 10:30:04',
|
||||
type: 'action',
|
||||
format: "date",
|
||||
time: "2019-01-20 10:30:04",
|
||||
type: "action",
|
||||
action: "JOIN",
|
||||
message: "User joined the game",
|
||||
}
|
||||
@@ -65,9 +65,9 @@ let testLines = new Map([
|
||||
[
|
||||
"2019-01-20 10:30:07 [CHAT] User: chat message",
|
||||
{
|
||||
format: 'date',
|
||||
time: '2019-01-20 10:30:07',
|
||||
type: 'action',
|
||||
format: "date",
|
||||
time: "2019-01-20 10:30:07",
|
||||
type: "action",
|
||||
action: "CHAT",
|
||||
message: "User: chat message",
|
||||
}
|
||||
@@ -75,9 +75,9 @@ let testLines = new Map([
|
||||
[
|
||||
"2019-01-20 10:30:14 [COMMAND] User (command): blah",
|
||||
{
|
||||
format: 'date',
|
||||
time: '2019-01-20 10:30:14',
|
||||
type: 'action',
|
||||
format: "date",
|
||||
time: "2019-01-20 10:30:14",
|
||||
type: "action",
|
||||
action: "COMMAND",
|
||||
message: "User (command): blah",
|
||||
}
|
||||
@@ -85,18 +85,18 @@ let testLines = new Map([
|
||||
[
|
||||
"2019-01-20 10:30:14 Cannot execute command. Error: [string \"blah\"]:1: syntax error near <eof>",
|
||||
{
|
||||
format: 'date',
|
||||
time: '2019-01-20 10:30:14',
|
||||
type: 'generic',
|
||||
format: "date",
|
||||
time: "2019-01-20 10:30:14",
|
||||
type: "generic",
|
||||
message: "Cannot execute command. Error: [string \"blah\"]:1: syntax error near <eof>",
|
||||
}
|
||||
],
|
||||
[
|
||||
"2019-01-20 10:30:21 [LEAVE] User left the game",
|
||||
{
|
||||
format: 'date',
|
||||
time: '2019-01-20 10:30:21',
|
||||
type: 'action',
|
||||
format: "date",
|
||||
time: "2019-01-20 10:30:21",
|
||||
type: "action",
|
||||
action: "LEAVE",
|
||||
message: "User left the game",
|
||||
}
|
||||
@@ -104,8 +104,8 @@ let testLines = new Map([
|
||||
[
|
||||
"Error while running event level::on_nth_tick(1)",
|
||||
{
|
||||
format: 'none',
|
||||
type: 'generic',
|
||||
format: "none",
|
||||
type: "generic",
|
||||
message: "Error while running event level::on_nth_tick(1)",
|
||||
}
|
||||
],
|
||||
|
||||
+30
-30
@@ -50,20 +50,20 @@ describe("lib/factorio", function() {
|
||||
|
||||
describe("generateLoader()", function() {
|
||||
let reference = [
|
||||
'-- Auto generated scenario module loader created by Clusterio',
|
||||
'-- Modifications to this file will be lost when loaded in Clusterio',
|
||||
'clusterio_patch_number = 1',
|
||||
'',
|
||||
"-- Auto generated scenario module loader created by Clusterio",
|
||||
"-- Modifications to this file will be lost when loaded in Clusterio",
|
||||
"clusterio_patch_number = 1",
|
||||
"",
|
||||
'local event_handler = require("event_handler")',
|
||||
'',
|
||||
'-- Scenario modules',
|
||||
"",
|
||||
"-- Scenario modules",
|
||||
'event_handler.add_lib(require("foo"))',
|
||||
'',
|
||||
'-- Clusterio modules',
|
||||
"",
|
||||
"-- Clusterio modules",
|
||||
'event_handler.add_lib(require("modules/spam/bar"))',
|
||||
'require("modules/spam/spam")',
|
||||
'',
|
||||
].join('\n');
|
||||
"",
|
||||
].join("\n");
|
||||
let patchInfo = {
|
||||
"patch_number": 1,
|
||||
"scenario": { "modules": ["foo"] },
|
||||
@@ -85,15 +85,15 @@ describe("lib/factorio", function() {
|
||||
describe("reorderDependencies()", function() {
|
||||
it("should reorder to satisfy simple dependency", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: 'b', version: '1.0.0', dependencies: {} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {} },
|
||||
];
|
||||
factorio._reorderDependencies(modules);
|
||||
assert(modules[0].name === 'b', "Dependency was not reorederd");
|
||||
assert(modules[0].name === "b", "Dependency was not reorederd");
|
||||
});
|
||||
it("should throw on invalid version", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: 'foo', dependencies: {} },
|
||||
{ name: "a", version: "foo", dependencies: {} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
@@ -102,7 +102,7 @@ describe("lib/factorio", function() {
|
||||
});
|
||||
it("should throw on invalid version range", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': 'invalid'} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "invalid"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
@@ -111,16 +111,16 @@ describe("lib/factorio", function() {
|
||||
});
|
||||
it("should throw on missing dependency", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
new Error("Missing dependency b for module a")
|
||||
);
|
||||
modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: 'b', version: '1.0.0', dependencies: {'c': '*'} },
|
||||
{ name: 'c', version: '1.0.0', dependencies: {'d': '*'} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {"c": "*"} },
|
||||
{ name: "c", version: "1.0.0", dependencies: {"d": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
@@ -129,8 +129,8 @@ describe("lib/factorio", function() {
|
||||
});
|
||||
it("should throw on outdated dependency", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {} },
|
||||
{ name: 'b', version: '1.0.0', dependencies: {'a': '>=2'} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {"a": ">=2"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
@@ -139,18 +139,18 @@ describe("lib/factorio", function() {
|
||||
});
|
||||
it("should throw on dependency loops", function() {
|
||||
let modules = [
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: 'b', version: '1.0.0', dependencies: {'a': '*'} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {"a": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
new Error("Module dependency loop detected: a -> b -> a")
|
||||
);
|
||||
modules = [
|
||||
{ name: 'd', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: 'a', version: '1.0.0', dependencies: {'b': '*'} },
|
||||
{ name: 'b', version: '1.0.0', dependencies: {'c': '*'} },
|
||||
{ name: 'c', version: '1.0.0', dependencies: {'a': '*'} },
|
||||
{ name: "d", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
|
||||
{ name: "b", version: "1.0.0", dependencies: {"c": "*"} },
|
||||
{ name: "c", version: "1.0.0", dependencies: {"a": "*"} },
|
||||
];
|
||||
assert.throws(
|
||||
() => factorio._reorderDependencies(modules),
|
||||
@@ -170,7 +170,7 @@ describe("lib/factorio", function() {
|
||||
}
|
||||
}
|
||||
|
||||
let names = ['a', 'b', 'c'];
|
||||
let names = ["a", "b", "c"];
|
||||
let successCount = 0;
|
||||
const bitCount = names.length * (names.length - 1);
|
||||
for (let i=0; i < 2**bitCount; i++) {
|
||||
@@ -186,10 +186,10 @@ describe("lib/factorio", function() {
|
||||
let dependencies = {};
|
||||
for (let k=0; k < names.length - 1; k++) {
|
||||
if (bits[k + j * (names.length - 1)]) {
|
||||
dependencies[names[k + (k >= j)]] = '*';
|
||||
dependencies[names[k + (k >= j)]] = "*";
|
||||
}
|
||||
}
|
||||
modules.push({ name, version: '1.0.0', dependencies });
|
||||
modules.push({ name, version: "1.0.0", dependencies });
|
||||
}
|
||||
let success = false;
|
||||
try {
|
||||
|
||||
+11
-11
@@ -157,8 +157,8 @@ describe("lib/factorio/server", function() {
|
||||
describe("parseOutput()", function() {
|
||||
it("should parse the test lines", function() {
|
||||
for (let [line, reference] of testLines) {
|
||||
reference.source = 'test';
|
||||
let output = factorio._parseOutput(line, 'test');
|
||||
reference.source = "test";
|
||||
let output = factorio._parseOutput(line, "test");
|
||||
delete output.received;
|
||||
assert.deepEqual(output, reference);
|
||||
}
|
||||
@@ -187,46 +187,46 @@ describe("lib/factorio/server", function() {
|
||||
|
||||
describe("._handleIpc()", function() {
|
||||
it("should emit the correct ipc event", async function() {
|
||||
let waiter = events.once(server, 'ipc-channel');
|
||||
let waiter = events.once(server, "ipc-channel");
|
||||
await server._handleIpc(Buffer.from('\f$ipc:channel?j"value"'));
|
||||
let result = await waiter;
|
||||
assert.equal(result[0], "value");
|
||||
});
|
||||
it("should handle special characters in channel name", async function() {
|
||||
let waiter = events.once(server, 'ipc-$ ?\x00\x0a:');
|
||||
let waiter = events.once(server, "ipc-$ ?\x00\x0a:");
|
||||
await server._handleIpc(Buffer.from('\f$ipc:$ \\x3f\\x00\\x0a:?j"value"'));
|
||||
let result = await waiter;
|
||||
assert.equal(result[0], "value");
|
||||
});
|
||||
it("should throw on malformed ipc line", async function() {
|
||||
await assert.rejects(
|
||||
server._handleIpc(Buffer.from('\f$ipc:blah')),
|
||||
server._handleIpc(Buffer.from("\f$ipc:blah")),
|
||||
new Error('Malformed IPC line "\f$ipc:blah"')
|
||||
);
|
||||
})
|
||||
it("should throw on unknown type", async function() {
|
||||
await assert.rejects(
|
||||
server._handleIpc(Buffer.from('\f$ipc:channel??')),
|
||||
server._handleIpc(Buffer.from("\f$ipc:channel??")),
|
||||
new Error("Unknown IPC type '?'")
|
||||
);
|
||||
})
|
||||
it("should throw on unknown file type", async function() {
|
||||
await assert.rejects(
|
||||
server._handleIpc(Buffer.from('\f$ipc:channel?ffoo.invalid')),
|
||||
server._handleIpc(Buffer.from("\f$ipc:channel?ffoo.invalid")),
|
||||
new Error("Unknown IPC file format 'invalid'")
|
||||
);
|
||||
})
|
||||
it("should throw on file name with slash", async function() {
|
||||
await assert.rejects(
|
||||
server._handleIpc(Buffer.from('\f$ipc:channel?fa/b')),
|
||||
server._handleIpc(Buffer.from("\f$ipc:channel?fa/b")),
|
||||
new Error("Invalid IPC file name 'a/b'")
|
||||
);
|
||||
})
|
||||
it("should load and delete json file", async function() {
|
||||
let filePath = server.writePath('script-output', 'data.json');
|
||||
let filePath = server.writePath("script-output", "data.json");
|
||||
await fs.outputFile(filePath, '{"data":"spam"}');
|
||||
let waiter = events.once(server, 'ipc-channel');
|
||||
await server._handleIpc(Buffer.from('\f$ipc:channel?fdata.json'));
|
||||
let waiter = events.once(server, "ipc-channel");
|
||||
await server._handleIpc(Buffer.from("\f$ipc:channel?fdata.json"));
|
||||
let result = await waiter;
|
||||
assert.deepEqual(result[0], { "data": "spam" });
|
||||
assert(!await fs.pathExists(filePath), "File was not deleted");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const assert = require('assert').strict;
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const fileOps = require('lib/fileOps');
|
||||
const fileOps = require("lib/fileOps");
|
||||
|
||||
describe("fileOps.js", function(){
|
||||
let baseDir = path.join("temp", "test", "fileOps");
|
||||
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
const assert = require('assert').strict;
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const stream = require('stream');
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const stream = require("stream");
|
||||
|
||||
const hash = require('lib/hash');
|
||||
const hash = require("lib/hash");
|
||||
|
||||
|
||||
describe("lib/hash", function() {
|
||||
|
||||
+12
-12
@@ -1,8 +1,8 @@
|
||||
const assert = require('assert').strict;
|
||||
const events = require('events');
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
|
||||
const mock = require('../../mock');
|
||||
const link = require('lib/link');
|
||||
const mock = require("../../mock");
|
||||
const link = require("lib/link");
|
||||
|
||||
|
||||
describe("lib/link/connectors", function() {
|
||||
@@ -33,7 +33,7 @@ describe("lib/link/connectors", function() {
|
||||
});
|
||||
|
||||
describe("class WebSocketClientConnector", function() {
|
||||
let testConnector = new link.WebSocketClientConnector('url', 1);
|
||||
let testConnector = new link.WebSocketClientConnector("url", 1);
|
||||
testConnector._socket = new mock.MockSocket();
|
||||
|
||||
describe(".register()", function() {
|
||||
@@ -49,10 +49,10 @@ describe("lib/link/connectors", function() {
|
||||
it("calls send on the socket", function() {
|
||||
testConnector._state = "handshake";
|
||||
testConnector._socket.sentMessages = [];
|
||||
testConnector.sendHandshake('test', { test: true });
|
||||
testConnector.sendHandshake("test", { test: true });
|
||||
assert.deepEqual(
|
||||
testConnector._socket.sentMessages.map(JSON.parse),
|
||||
[{ seq: null, type: 'test', data: { test: true }}]
|
||||
[{ seq: null, type: "test", data: { test: true }}]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -61,10 +61,10 @@ describe("lib/link/connectors", function() {
|
||||
it("calls send on the socket", function() {
|
||||
testConnector._state = "connected";
|
||||
testConnector._socket.sentMessages = [];
|
||||
let seq = testConnector.send('test', { test: true });
|
||||
let seq = testConnector.send("test", { test: true });
|
||||
assert.deepEqual(
|
||||
testConnector._socket.sentMessages.map(JSON.parse),
|
||||
[{ seq, type: 'test', data: { test: true }}]
|
||||
[{ seq, type: "test", data: { test: true }}]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -86,13 +86,13 @@ describe("lib/link/connectors", function() {
|
||||
it("should call register on hello", function() {
|
||||
let called = false;
|
||||
testConnector.register = () => { called = true; };
|
||||
testConnector._processHandshake({ seq: 1, type: 'hello', data: { version: "test", plugins: {} }});
|
||||
testConnector._processHandshake({ seq: 1, type: "hello", data: { version: "test", plugins: {} }});
|
||||
assert(called, "register was not called");
|
||||
});
|
||||
it("should emit connect on ready", async function() {
|
||||
let result = events.once(testConnector, "connect");
|
||||
testConnector._processHandshake(
|
||||
{ seq: 1, type: 'ready', data: { session_token: "x", heartbeat_interval: 10 }}
|
||||
{ seq: 1, type: "ready", data: { session_token: "x", heartbeat_interval: 10 }}
|
||||
);
|
||||
await result;
|
||||
clearInterval(testConnector._heartbeatId);
|
||||
@@ -121,7 +121,7 @@ describe("lib/link/connectors", function() {
|
||||
it("should emit message on message in connected state", async function() {
|
||||
testConnector._socket.sentMessages = [];
|
||||
testConnector._state = "connected";
|
||||
let result = events.once(testConnector, 'message');
|
||||
let result = events.once(testConnector, "message");
|
||||
testConnector._socket.events.get("message")('{"message":true}');
|
||||
assert.deepEqual(await result, [{ message: true }]);
|
||||
});
|
||||
|
||||
+42
-42
@@ -1,5 +1,5 @@
|
||||
const assert = require('assert').strict;
|
||||
const events = require('events');
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
|
||||
const link = require("lib/link");
|
||||
const errors = require("lib/errors");
|
||||
@@ -14,13 +14,13 @@ describe("lib/link/link", function() {
|
||||
|
||||
before(function() {
|
||||
testConnector = new mock.MockConnector();
|
||||
testLink = new link.Link('source', 'target', testConnector);
|
||||
testLink.setValidator('simple', schema.compile({
|
||||
testLink = new link.Link("source", "target", testConnector);
|
||||
testLink.setValidator("simple", schema.compile({
|
||||
properties: {
|
||||
"data": {
|
||||
type: 'object',
|
||||
type: "object",
|
||||
properties: {
|
||||
"string": { type: 'string' },
|
||||
"string": { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -28,20 +28,20 @@ describe("lib/link/link", function() {
|
||||
});
|
||||
|
||||
it("should emitt error processing message to connector", async function() {
|
||||
testLink.setHandler('throws', () => { throw new Error("Handler error"); }, () => true);
|
||||
let result = events.once(testConnector, 'message');
|
||||
testConnector.emit('message', { seq: 1, type: 'throws', data: {}});
|
||||
testLink.setHandler("throws", () => { throw new Error("Handler error"); }, () => true);
|
||||
let result = events.once(testConnector, "message");
|
||||
testConnector.emit("message", { seq: 1, type: "throws", data: {}});
|
||||
await assert.rejects(result, new Error("Handler error"));
|
||||
});
|
||||
|
||||
describe(".setValidator()", function() {
|
||||
it("should set the validator", function() {
|
||||
testLink.setValidator('test', () => true);
|
||||
assert(testLink._validators.has('test'), "validator was not added");
|
||||
testLink.setValidator("test", () => true);
|
||||
assert(testLink._validators.has("test"), "validator was not added");
|
||||
});
|
||||
it("should throw on duplicated validator", function() {
|
||||
assert.throws(
|
||||
() => testLink.setValidator('test', () => true),
|
||||
() => testLink.setValidator("test", () => true),
|
||||
new Error("test already has a validator")
|
||||
);
|
||||
});
|
||||
@@ -50,18 +50,18 @@ describe("lib/link/link", function() {
|
||||
describe(".setHandler()", function() {
|
||||
it("should throw if validator is not passed", function() {
|
||||
assert.throws(
|
||||
() => testLink.setHandler('no_validator_test', (message) => {}),
|
||||
() => testLink.setHandler("no_validator_test", (message) => {}),
|
||||
new Error("validator is required")
|
||||
);
|
||||
});
|
||||
it("should set the handler", function() {
|
||||
let handler = (message) => {};
|
||||
testLink.setHandler('handler_test', handler, (message) => true);
|
||||
assert.equal(testLink._handlers.get('handler_test'), handler);
|
||||
testLink.setHandler("handler_test", handler, (message) => true);
|
||||
assert.equal(testLink._handlers.get("handler_test"), handler);
|
||||
});
|
||||
it("should throw on duplicated handler", function() {
|
||||
assert.throws(
|
||||
() => testLink.setHandler('handler_test', (message) => {}),
|
||||
() => testLink.setHandler("handler_test", (message) => {}),
|
||||
new Error("handler_test already has a handler")
|
||||
);
|
||||
});
|
||||
@@ -76,19 +76,19 @@ describe("lib/link/link", function() {
|
||||
});
|
||||
it("should throw on message without validator", function() {
|
||||
assert.throws(
|
||||
() => testLink.processMessage({ seq: 1, type: 'no_validator', data: {} }),
|
||||
() => testLink.processMessage({ seq: 1, type: "no_validator", data: {} }),
|
||||
new errors.InvalidMessage("No validator for no_validator on source-target")
|
||||
);
|
||||
});
|
||||
it("should throw on message failing validation", function() {
|
||||
assert.throws(
|
||||
() => testLink.processMessage({ seq: 1, type: 'simple', data: { string: 1 }}),
|
||||
() => testLink.processMessage({ seq: 1, type: "simple", data: { string: 1 }}),
|
||||
{ message: "Validation failed for simple" }
|
||||
);
|
||||
});
|
||||
it("should throw on unhandled message", function() {
|
||||
assert.throws(
|
||||
() => testLink.processMessage({ seq: 1, type: 'simple', data: { string: "a" }}),
|
||||
() => testLink.processMessage({ seq: 1, type: "simple", data: { string: "a" }}),
|
||||
new errors.InvalidMessage("Unhandled message simple")
|
||||
);
|
||||
});
|
||||
@@ -97,16 +97,16 @@ describe("lib/link/link", function() {
|
||||
describe("._processHandler()", function() {
|
||||
it("should call the handler", function() {
|
||||
let handled = [];
|
||||
testLink.setHandler('handled', (message) => handled.push(message), (message) => true)
|
||||
testLink._processHandler({ seq: 1, type: 'handled', data: { test: "foo" } });
|
||||
assert.deepEqual(handled, [{ seq: 1, type: 'handled', data: { test: "foo" } }]);
|
||||
testLink.setHandler("handled", (message) => handled.push(message), (message) => true)
|
||||
testLink._processHandler({ seq: 1, type: "handled", data: { test: "foo" } });
|
||||
assert.deepEqual(handled, [{ seq: 1, type: "handled", data: { test: "foo" } }]);
|
||||
});
|
||||
it("should return true if handled", function() {
|
||||
let result = testLink._processHandler({ seq: 1, type: 'handled', data: {} });
|
||||
let result = testLink._processHandler({ seq: 1, type: "handled", data: {} });
|
||||
assert.equal(result, true);
|
||||
});
|
||||
it("should return false if not handled", function() {
|
||||
let result = testLink._processHandler({ seq: 1, type: 'not_handled', data: {} });
|
||||
let result = testLink._processHandler({ seq: 1, type: "not_handled", data: {} });
|
||||
assert.equal(result, false);
|
||||
});
|
||||
});
|
||||
@@ -114,62 +114,62 @@ describe("lib/link/link", function() {
|
||||
describe("._processWaiters()", function() {
|
||||
it("should call waiters", async function() {
|
||||
let waiter = new Promise(resolve => {
|
||||
testLink._waiters.set('test', [{ resolve, data: {} }]);
|
||||
testLink._waiters.set("test", [{ resolve, data: {} }]);
|
||||
});
|
||||
assert(
|
||||
testLink._processWaiters({ type: 'test', seq: 4, data: {} }),
|
||||
testLink._processWaiters({ type: "test", seq: 4, data: {} }),
|
||||
"Waiter was not processed"
|
||||
);
|
||||
assert.deepEqual(await waiter, { type: 'test', seq: 4, data: {} });
|
||||
assert.deepEqual(await waiter, { type: "test", seq: 4, data: {} });
|
||||
});
|
||||
it("should filter on data", async function() {
|
||||
let waiter = new Promise(resolve => {
|
||||
testLink._waiters.set('test', [{ resolve, data: { a: 1, b: 2 } }]);
|
||||
testLink._waiters.set("test", [{ resolve, data: { a: 1, b: 2 } }]);
|
||||
});
|
||||
assert(
|
||||
!testLink._processWaiters({ type: 'test', seq: 4, data: {} }),
|
||||
!testLink._processWaiters({ type: "test", seq: 4, data: {} }),
|
||||
"Incorrectly matched empty message"
|
||||
);
|
||||
assert(
|
||||
!testLink._processWaiters({ type: 'test', seq: 4, data: { a: 1, b: 0 } }),
|
||||
!testLink._processWaiters({ type: "test", seq: 4, data: { a: 1, b: 0 } }),
|
||||
"Incorrectly matched message with wrong data"
|
||||
);
|
||||
assert(
|
||||
testLink._processWaiters({ type: 'test', seq: 4, data: { a: 1, b: 2, c: 3 } }),
|
||||
testLink._processWaiters({ type: "test", seq: 4, data: { a: 1, b: 2, c: 3 } }),
|
||||
"Did not match correct message"
|
||||
);
|
||||
assert.deepEqual(await waiter, { type: 'test', seq: 4, data: { a: 1, b: 2, c: 3 } });
|
||||
assert.deepEqual(await waiter, { type: "test", seq: 4, data: { a: 1, b: 2, c: 3 } });
|
||||
});
|
||||
});
|
||||
|
||||
describe(".waitFor()", function() {
|
||||
before(function() {
|
||||
testLink.setValidator('waiter', (message) => true);
|
||||
testLink.setValidator("waiter", (message) => true);
|
||||
});
|
||||
|
||||
it("should throw on missing validator", async function() {
|
||||
await assert.rejects(
|
||||
testLink.waitFor('no_validator', {}),
|
||||
testLink.waitFor("no_validator", {}),
|
||||
new Error("No validator for no_validator on source-target")
|
||||
);
|
||||
});
|
||||
it("should wait for a given message", async function() {
|
||||
let result = testLink.waitFor('waiter', {});
|
||||
let result = testLink.waitFor("waiter", {});
|
||||
assert(
|
||||
testLink._processWaiters({ type: 'waiter', seq: 5, data: {} }),
|
||||
testLink._processWaiters({ type: "waiter", seq: 5, data: {} }),
|
||||
"Did not proccess waiter"
|
||||
);
|
||||
assert.deepEqual(await result, { type: 'waiter', seq: 5, data: {} });
|
||||
assert.deepEqual(await result, { type: "waiter", seq: 5, data: {} });
|
||||
});
|
||||
it("should handle multiple waiters", async function() {
|
||||
let result1 = testLink.waitFor('waiter', {});
|
||||
let result2 = testLink.waitFor('waiter', {});
|
||||
let result1 = testLink.waitFor("waiter", {});
|
||||
let result2 = testLink.waitFor("waiter", {});
|
||||
assert(
|
||||
testLink._processWaiters({ type: 'waiter', seq: 5, data: {} }),
|
||||
testLink._processWaiters({ type: "waiter", seq: 5, data: {} }),
|
||||
"Did not proccess waiter"
|
||||
);
|
||||
assert.deepEqual(await result1, { type: 'waiter', seq: 5, data: {} });
|
||||
assert.deepEqual(await result2, { type: 'waiter', seq: 5, data: {} });
|
||||
assert.deepEqual(await result1, { type: "waiter", seq: 5, data: {} });
|
||||
assert.deepEqual(await result2, { type: "waiter", seq: 5, data: {} });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
const assert = require('assert').strict;
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const link = require('lib/link');
|
||||
const errors = require('lib/errors');
|
||||
const mock = require('../../mock');
|
||||
const link = require("lib/link");
|
||||
const errors = require("lib/errors");
|
||||
const mock = require("../../mock");
|
||||
|
||||
|
||||
describe("lib/link/messages", function() {
|
||||
let testSourceLink = new link.Link('source', 'target', new mock.MockConnector());
|
||||
let testTargetLink = new link.Link('target', 'source', new mock.MockConnector());
|
||||
let testSourceLink = new link.Link("source", "target", new mock.MockConnector());
|
||||
let testTargetLink = new link.Link("target", "source", new mock.MockConnector());
|
||||
|
||||
let lastTargetSent;
|
||||
testTargetLink.send = (type, data) => { lastTargetSent = { type, data }; };
|
||||
|
||||
describe("class Request", function() {
|
||||
let testRequest = new link.Request({
|
||||
type: 'test',
|
||||
links: ['source-target'],
|
||||
type: "test",
|
||||
links: ["source-target"],
|
||||
requestProperties: {
|
||||
"test": { type: "string" },
|
||||
},
|
||||
@@ -24,7 +24,7 @@ describe("lib/link/messages", function() {
|
||||
describe("constructor", function() {
|
||||
it("should throw on invalid forwardTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Request({ links: [], forwardTo: 'invalid'}),
|
||||
() => new link.Request({ links: [], forwardTo: "invalid"}),
|
||||
new Error("Invalid forwardTo value invalid")
|
||||
);
|
||||
});
|
||||
@@ -33,7 +33,7 @@ describe("lib/link/messages", function() {
|
||||
describe(".attach()", function() {
|
||||
it("should attach validator to a source link", function() {
|
||||
testRequest.attach(testSourceLink);
|
||||
assert(testSourceLink._validators.has('test_response'), "Validator was not set");
|
||||
assert(testSourceLink._validators.has("test_response"), "Validator was not set");
|
||||
});
|
||||
it("should throw if missing handler on target link", function() {
|
||||
assert.throws(
|
||||
@@ -45,16 +45,16 @@ describe("lib/link/messages", function() {
|
||||
let handlerResult;
|
||||
it("should attach handler to a target link", function() {
|
||||
testRequest.attach(testTargetLink, async (message) => handlerResult );
|
||||
assert(testTargetLink._handlers.has('test_request'), "Handler was not set");
|
||||
assert(testTargetLink._handlers.has("test_request"), "Handler was not set");
|
||||
});
|
||||
it("should send result of calling the handler", async function() {
|
||||
handlerResult = { test: "handler" };
|
||||
testTargetLink._handlers.get('test_request')({ seq: 2 });
|
||||
testTargetLink._handlers.get("test_request")({ seq: 2 });
|
||||
let result = await new Promise(resolve => {
|
||||
testTargetLink.connector.send = (type, data) => resolve({ type, data });
|
||||
});
|
||||
assert.deepEqual(result, {
|
||||
type: 'test_response',
|
||||
type: "test_response",
|
||||
data: {
|
||||
test: "handler",
|
||||
seq: 2,
|
||||
@@ -63,12 +63,12 @@ describe("lib/link/messages", function() {
|
||||
});
|
||||
it("should implicitly send an empty object on empty return", async function() {
|
||||
handlerResult = undefined;
|
||||
testTargetLink._handlers.get('test_request')({ seq: 2 });
|
||||
testTargetLink._handlers.get("test_request")({ seq: 2 });
|
||||
let result = await new Promise(resolve => {
|
||||
testTargetLink.connector.send = (type, data) => resolve({ type, data });
|
||||
});
|
||||
assert.deepEqual(result, {
|
||||
type: 'test_response',
|
||||
type: "test_response",
|
||||
data: {
|
||||
seq: 2,
|
||||
},
|
||||
@@ -87,7 +87,7 @@ describe("lib/link/messages", function() {
|
||||
};
|
||||
assert.deepEqual(
|
||||
await testRequest.send(testSourceLink, { test: "request" }),
|
||||
{ type: 'test_response', request: { type: 'test_request', data: {test: "request" }}}
|
||||
{ type: "test_response", request: { type: "test_request", data: {test: "request" }}}
|
||||
);
|
||||
delete testSourceLink.connector.send;
|
||||
delete testSourceLink.waitFor;
|
||||
@@ -107,8 +107,8 @@ describe("lib/link/messages", function() {
|
||||
|
||||
describe("class Event", function() {
|
||||
let testEvent = new link.Event({
|
||||
type: 'test',
|
||||
links: ['source-target'],
|
||||
type: "test",
|
||||
links: ["source-target"],
|
||||
eventProperties: {
|
||||
"test": { type: "string" },
|
||||
},
|
||||
@@ -117,13 +117,13 @@ describe("lib/link/messages", function() {
|
||||
describe("constructor", function() {
|
||||
it("should throw on invalid forwardTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Event({ forwardTo: 'invalid'}),
|
||||
() => new link.Event({ forwardTo: "invalid"}),
|
||||
new Error("Invalid forwardTo value invalid")
|
||||
);
|
||||
});
|
||||
it("should throw on invalid broadcastTo", function() {
|
||||
assert.throws(
|
||||
() => new link.Event({ broadcastTo: 'invalid'}),
|
||||
() => new link.Event({ broadcastTo: "invalid"}),
|
||||
new Error("Invalid broadcastTo value invalid")
|
||||
);
|
||||
});
|
||||
@@ -139,7 +139,7 @@ describe("lib/link/messages", function() {
|
||||
let called = false;
|
||||
it("should attach handler and validator to a target link", function() {
|
||||
testEvent.attach(testTargetLink, async (message) => { called = true; });
|
||||
assert(testTargetLink._validators.has('test_event'), "Validator was not set");
|
||||
assert(testTargetLink._validators.has("test_event"), "Validator was not set");
|
||||
});
|
||||
it("should call the attached event handler", function() {
|
||||
testTargetLink._handlers.get("test_event")();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const assert = require('assert').strict;
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const luaTools = require('lib/luaTools');
|
||||
const luaTools = require("lib/luaTools");
|
||||
|
||||
|
||||
describe("lib/luaTools", function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var assert = require('assert');
|
||||
var objectOps = require('lib/objectOps');
|
||||
var assert = require("assert");
|
||||
var objectOps = require("lib/objectOps");
|
||||
|
||||
describe("objectOps.js", function(){
|
||||
/*describe("objectOps.clone()", function(){
|
||||
|
||||
+21
-21
@@ -1,11 +1,11 @@
|
||||
const assert = require('assert').strict;
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const mock = require('../mock');
|
||||
const link = require('lib/link');
|
||||
const plugin = require('lib/plugin');
|
||||
const errors = require('lib/errors');
|
||||
const mock = require("../mock");
|
||||
const link = require("lib/link");
|
||||
const plugin = require("lib/plugin");
|
||||
const errors = require("lib/errors");
|
||||
|
||||
|
||||
describe("lib/plugin", function() {
|
||||
@@ -43,26 +43,26 @@ describe("lib/plugin", function() {
|
||||
|
||||
describe("loadPluginInfos()", function() {
|
||||
let baseDir = path.join("temp", "test", "plugin");
|
||||
let emptyDir = path.join(baseDir, 'emptyDir');
|
||||
let emptyPlugin = path.join(baseDir, 'emptyPlugin');
|
||||
let testPlugin = path.join(baseDir, 'testPlugin');
|
||||
let brokenPlugin = path.join(baseDir, 'brokenPlugin');
|
||||
let invalidPlugin = path.join(baseDir, 'invalidPlugin');
|
||||
let emptyDir = path.join(baseDir, "emptyDir");
|
||||
let emptyPlugin = path.join(baseDir, "emptyPlugin");
|
||||
let testPlugin = path.join(baseDir, "testPlugin");
|
||||
let brokenPlugin = path.join(baseDir, "brokenPlugin");
|
||||
let invalidPlugin = path.join(baseDir, "invalidPlugin");
|
||||
before(async function() {
|
||||
await fs.ensureDir(emptyDir);
|
||||
await fs.ensureDir(path.join(emptyPlugin, 'empty'));
|
||||
await fs.ensureDir(path.join(emptyPlugin, "empty"));
|
||||
|
||||
async function writePlugin(pluginPath, name, infoName = name) {
|
||||
await fs.outputFile(
|
||||
path.join(pluginPath, name, 'info.js'),
|
||||
path.join(pluginPath, name, "info.js"),
|
||||
`module.exports = { name: "${infoName}" };`
|
||||
);
|
||||
}
|
||||
|
||||
await writePlugin(testPlugin, 'test');
|
||||
await writePlugin(brokenPlugin, 'broken');
|
||||
await fs.outputFile(path.join(brokenPlugin, 'broken', 'info.js'), "Syntax Error");
|
||||
await writePlugin(invalidPlugin, 'invalid', 'wrong');
|
||||
await writePlugin(testPlugin, "test");
|
||||
await writePlugin(brokenPlugin, "broken");
|
||||
await fs.outputFile(path.join(brokenPlugin, "broken", "info.js"), "Syntax Error");
|
||||
await writePlugin(invalidPlugin, "invalid", "wrong");
|
||||
});
|
||||
|
||||
it("should return an empty array for an empty directory", async function() {
|
||||
@@ -74,7 +74,7 @@ describe("lib/plugin", function() {
|
||||
it("should discover test plugin", async function() {
|
||||
assert.deepEqual(
|
||||
await plugin.loadPluginInfos(testPlugin),
|
||||
[{ name: 'test' }]
|
||||
[{ name: "test" }]
|
||||
);
|
||||
});
|
||||
it("should reject on broken plugin", async function() {
|
||||
@@ -91,12 +91,12 @@ describe("lib/plugin", function() {
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await fs.unlink(path.join(brokenPlugin, 'broken', 'info.js'));
|
||||
await fs.unlink(path.join(brokenPlugin, "broken", "info.js"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("attachPluginMessages()", function() {
|
||||
let mockLink = new link.Link('source', 'target', new mock.MockConnector());
|
||||
let mockLink = new link.Link("source", "target", new mock.MockConnector());
|
||||
let mockEvent = new link.Event({ type: "test:test", links: ["target-source"] });
|
||||
it("should accept pluginInfo without messages", function() {
|
||||
plugin.attachPluginMessages(mockLink, {}, null);
|
||||
|
||||
+89
-89
@@ -1,6 +1,6 @@
|
||||
const assert = require('assert').strict;
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const prometheus = require('lib/prometheus');
|
||||
const prometheus = require("lib/prometheus");
|
||||
|
||||
|
||||
describe("lib/prometheus", function() {
|
||||
@@ -105,22 +105,22 @@ describe("lib/prometheus", function() {
|
||||
describe("class Counter", function() {
|
||||
let counter;
|
||||
beforeEach(function() {
|
||||
counter = new prometheus.Counter('test', "Help", { register: false });
|
||||
counter = new prometheus.Counter("test", "Help", { register: false });
|
||||
});
|
||||
|
||||
describe("constructor", function() {
|
||||
it("should be initialized to 0", function() {
|
||||
assert.equal(counter._values.get(''), 0);
|
||||
assert.equal(counter._values.get(""), 0);
|
||||
});
|
||||
});
|
||||
describe(".inc()", function() {
|
||||
it("should increment the counter by 1 by default", function() {
|
||||
counter.inc();
|
||||
assert.equal(counter._values.get(''), 1);
|
||||
assert.equal(counter._values.get(""), 1);
|
||||
});
|
||||
it("should increment the counter by specified value", function() {
|
||||
counter.inc(3.2);
|
||||
assert.equal(counter._values.get(''), 3.2);
|
||||
assert.equal(counter._values.get(""), 3.2);
|
||||
});
|
||||
it("should throw if value is negative", function() {
|
||||
assert.throws(
|
||||
@@ -146,53 +146,53 @@ describe("lib/prometheus", function() {
|
||||
describe("class Gauge", function() {
|
||||
let gauge;
|
||||
beforeEach(function() {
|
||||
gauge = new prometheus.Gauge('test', "Help", { register: false });
|
||||
gauge = new prometheus.Gauge("test", "Help", { register: false });
|
||||
});
|
||||
|
||||
describe("constructor", function() {
|
||||
it("should be initialized to 0", function() {
|
||||
assert.equal(gauge._values.get(''), 0);
|
||||
assert.equal(gauge._values.get(""), 0);
|
||||
});
|
||||
});
|
||||
describe(".inc()", function() {
|
||||
it("should increment the gauge by 1 by default", function() {
|
||||
gauge.inc();
|
||||
assert.equal(gauge._values.get(''), 1);
|
||||
assert.equal(gauge._values.get(""), 1);
|
||||
});
|
||||
it("should increment the gauge by specified value", function() {
|
||||
gauge.inc(3.2);
|
||||
assert.equal(gauge._values.get(''), 3.2);
|
||||
assert.equal(gauge._values.get(""), 3.2);
|
||||
});
|
||||
it("should decrement on negative value", function() {
|
||||
gauge.inc(-2);
|
||||
assert.equal(gauge._values.get(''), -2);
|
||||
assert.equal(gauge._values.get(""), -2);
|
||||
});
|
||||
});
|
||||
describe(".dec()", function() {
|
||||
it("should decrement the gauge by 1 by default", function() {
|
||||
gauge.dec();
|
||||
assert.equal(gauge._values.get(''), -1);
|
||||
assert.equal(gauge._values.get(""), -1);
|
||||
});
|
||||
it("should decrement the gauge by specified value", function() {
|
||||
gauge.dec(3.2);
|
||||
assert.equal(gauge._values.get(''), -3.2);
|
||||
assert.equal(gauge._values.get(""), -3.2);
|
||||
});
|
||||
it("should increment on negative value", function() {
|
||||
gauge.dec(-2);
|
||||
assert.equal(gauge._values.get(''), 2);
|
||||
assert.equal(gauge._values.get(""), 2);
|
||||
});
|
||||
});
|
||||
describe(".set()", function() {
|
||||
it("should set the gauge to the specified value", function() {
|
||||
gauge.set(7);
|
||||
assert.equal(gauge._values.get(''), 7);
|
||||
assert.equal(gauge._values.get(""), 7);
|
||||
});
|
||||
});
|
||||
describe(".setToCurrentTime()", function() {
|
||||
it("should set the gauge to current unix time in seconds", function() {
|
||||
gauge.setToCurrentTime();
|
||||
assert(
|
||||
Math.abs(gauge._values.get('') - Date.now() / 1000) < 1,
|
||||
Math.abs(gauge._values.get("") - Date.now() / 1000) < 1,
|
||||
"value set is not close to the current unix time"
|
||||
);
|
||||
});
|
||||
@@ -215,7 +215,7 @@ describe("lib/prometheus", function() {
|
||||
for (let name of ["", " ", "0a", "$a", "a:"]) {
|
||||
assert.throws(
|
||||
() => new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: [name] }
|
||||
"test", "Help", { register: false, labels: [name] }
|
||||
),
|
||||
new Error(`Invalid label '${name}'`)
|
||||
)
|
||||
@@ -243,7 +243,7 @@ describe("lib/prometheus", function() {
|
||||
|
||||
describe(".get()", function() {
|
||||
it("should return the current value", function() {
|
||||
let gauge = new prometheus.Gauge('test', "Help", { register: false });
|
||||
let gauge = new prometheus.Gauge("test", "Help", { register: false });
|
||||
gauge.set(11);
|
||||
assert.equal(gauge.get(), 11);
|
||||
});
|
||||
@@ -253,7 +253,7 @@ describe("lib/prometheus", function() {
|
||||
let gauge;
|
||||
beforeEach(function() {
|
||||
gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b'] }
|
||||
"test", "Help", { register: false, labels: ["a", "b"] }
|
||||
);
|
||||
});
|
||||
it("should require all labels set at creation", function() {
|
||||
@@ -266,15 +266,15 @@ describe("lib/prometheus", function() {
|
||||
new Error("Missing label 'a'")
|
||||
);
|
||||
assert.throws(
|
||||
() => gauge.labels({a: '1', b: '2', c: '3'}),
|
||||
() => gauge.labels({a: "1", b: "2", c: "3"}),
|
||||
new Error("Extra label 'c'")
|
||||
);
|
||||
assert.throws(
|
||||
() => gauge.labels('1'),
|
||||
() => gauge.labels("1"),
|
||||
new Error("Missing label 'b'")
|
||||
);
|
||||
assert.throws(
|
||||
() => gauge.labels('1', '2', '3'),
|
||||
() => gauge.labels("1", "2", "3"),
|
||||
new Error("Extra positional label")
|
||||
);
|
||||
});
|
||||
@@ -289,39 +289,39 @@ describe("lib/prometheus", function() {
|
||||
);
|
||||
});
|
||||
it("should initialize a value for the label set", function() {
|
||||
gauge.labels({ a: '1', b: '2'});
|
||||
gauge.labels({ a: "1", b: "2"});
|
||||
assert(gauge._values.has('a="1",b="2"'), "value was not set");
|
||||
gauge.labels('4', '5');
|
||||
gauge.labels("4", "5");
|
||||
assert(gauge._values.has('a="4",b="5"'), "value was not set");
|
||||
});
|
||||
it("should return a child supporting the usual methods", function() {
|
||||
let child = gauge.labels({ a: '1', b: '2'});
|
||||
let child = gauge.labels({ a: "1", b: "2"});
|
||||
child.get();
|
||||
child.inc();
|
||||
child.dec();
|
||||
child.setToCurrentTime();
|
||||
child = gauge.labels('7', '8');
|
||||
child = gauge.labels("7", "8");
|
||||
child.get();
|
||||
child.inc();
|
||||
child.dec();
|
||||
child.setToCurrentTime();
|
||||
});
|
||||
it("should return the same child for the same labels", function() {
|
||||
let child = gauge.labels('1', '2');
|
||||
assert.equal(gauge.labels('1', '2'), child);
|
||||
let child = gauge.labels("1", "2");
|
||||
assert.equal(gauge.labels("1", "2"), child);
|
||||
});
|
||||
});
|
||||
describe(".remove()", function() {
|
||||
it("should remove a label set created with .labels()", function() {
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b'] }
|
||||
"test", "Help", { register: false, labels: ["a", "b"] }
|
||||
);
|
||||
gauge.labels({ a: '1', b: '2'});
|
||||
gauge.remove({ a: '1', b: '2'});
|
||||
gauge.labels({ a: "1", b: "2"});
|
||||
gauge.remove({ a: "1", b: "2"});
|
||||
assert(!gauge._values.has('a="1",b="2"'), "value was not removed");
|
||||
});
|
||||
it("should throw when removing the empty label set", function() {
|
||||
let gauge = new prometheus.Gauge('test', "Help", { register: false });
|
||||
let gauge = new prometheus.Gauge("test", "Help", { register: false });
|
||||
assert.throws(
|
||||
() => gauge.remove({}), new Error("labels cannot be empty")
|
||||
);
|
||||
@@ -330,12 +330,12 @@ describe("lib/prometheus", function() {
|
||||
describe(".removeAll()", function() {
|
||||
it("should remove a label set created with .labels()", function() {
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b'] }
|
||||
"test", "Help", { register: false, labels: ["a", "b"] }
|
||||
);
|
||||
gauge.labels('1', '2');
|
||||
gauge.labels('1', '3');
|
||||
gauge.labels('4', '6');
|
||||
gauge.removeAll({a: '1'});
|
||||
gauge.labels("1", "2");
|
||||
gauge.labels("1", "3");
|
||||
gauge.labels("4", "6");
|
||||
gauge.removeAll({a: "1"});
|
||||
assert(gauge._values.size <= 1, "Matching labels remained")
|
||||
assert(
|
||||
gauge._values.has('a="4",b="6"'),
|
||||
@@ -343,16 +343,16 @@ describe("lib/prometheus", function() {
|
||||
);
|
||||
});
|
||||
it("should throw when removing the empty label set", function() {
|
||||
let gauge = new prometheus.Gauge('test', "Help", { register: false });
|
||||
let gauge = new prometheus.Gauge("test", "Help", { register: false });
|
||||
assert.throws(
|
||||
() => gauge.removeAll({}), new Error("labels cannot be empty")
|
||||
);
|
||||
});
|
||||
it("should handle special characters", function() {
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b'] }
|
||||
"test", "Help", { register: false, labels: ["a", "b"] }
|
||||
)
|
||||
gauge.labels('x\\\\\n\"\"\n\\', '2');
|
||||
gauge.labels('x\\\\\n\"\"\n\\', "2");
|
||||
gauge.removeAll({a: 'x\\\\\n\"\"\n\\'});
|
||||
assert(gauge._values.size === 0, "Matching labels remained")
|
||||
});
|
||||
@@ -360,16 +360,16 @@ describe("lib/prometheus", function() {
|
||||
describe(".clear()", function() {
|
||||
it("should remove all label sets created with .labels()", function() {
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b'] }
|
||||
"test", "Help", { register: false, labels: ["a", "b"] }
|
||||
);
|
||||
gauge.labels({ a: '1', b: '2'});
|
||||
gauge.labels({ a: '3', b: '4'});
|
||||
gauge.labels({ a: '5', b: '6'});
|
||||
gauge.labels({ a: "1", b: "2"});
|
||||
gauge.labels({ a: "3", b: "4"});
|
||||
gauge.labels({ a: "5", b: "6"});
|
||||
gauge.clear();
|
||||
assert(gauge._values.size == 0, "values was not cleared");
|
||||
});
|
||||
it("should throw when used on an unlabled metric", function() {
|
||||
let gauge = new prometheus.Gauge('test', "Help", { register: false });
|
||||
let gauge = new prometheus.Gauge("test", "Help", { register: false });
|
||||
assert.throws(
|
||||
() => gauge.clear(), new Error("Cannot clear unlabeled metric")
|
||||
);
|
||||
@@ -393,7 +393,7 @@ describe("lib/prometheus", function() {
|
||||
);
|
||||
|
||||
assert(
|
||||
Math.abs(results[0].samples.get('') - Date.now() / 1000) < 1,
|
||||
Math.abs(results[0].samples.get("") - Date.now() / 1000) < 1,
|
||||
"value set is not close to the current unix time"
|
||||
);
|
||||
});
|
||||
@@ -412,7 +412,7 @@ describe("lib/prometheus", function() {
|
||||
"collector did not give exactly one result"
|
||||
);
|
||||
|
||||
let value = results[0].samples.get('')
|
||||
let value = results[0].samples.get("")
|
||||
assert(
|
||||
value < 5 && value > 0,
|
||||
`process time is not between 0 and 5 seconds (${value})`
|
||||
@@ -433,7 +433,7 @@ describe("lib/prometheus", function() {
|
||||
"collector did not give exactly one result"
|
||||
);
|
||||
|
||||
let value = results[0].samples.get('')
|
||||
let value = results[0].samples.get("")
|
||||
assert(
|
||||
value < 200e6 && value > 0,
|
||||
`resident memory is not between 0 and 200 MB (${value})`
|
||||
@@ -454,7 +454,7 @@ describe("lib/prometheus", function() {
|
||||
"collector did not give exactly one result"
|
||||
);
|
||||
|
||||
let value = results[0].samples.get('')
|
||||
let value = results[0].samples.get("")
|
||||
assert(
|
||||
value < 200e6 && value > 0,
|
||||
`heap is not between 0 and 200 MB (${value})`
|
||||
@@ -466,35 +466,35 @@ describe("lib/prometheus", function() {
|
||||
describe("exposition()", function() {
|
||||
it("should format simple metrics", async function() {
|
||||
let registry = new prometheus.CollectorRegistry();
|
||||
let counter = new prometheus.Counter('a', "Help", { register: false });
|
||||
let counter = new prometheus.Counter("a", "Help", { register: false });
|
||||
registry.register(counter);
|
||||
let gauge = new prometheus.Gauge('b', "Help", { register: false });
|
||||
let gauge = new prometheus.Gauge("b", "Help", { register: false });
|
||||
registry.register(gauge);
|
||||
let exposition = await prometheus.exposition(registry.collect());
|
||||
assert.equal(
|
||||
exposition,
|
||||
'# HELP a Help\n' +
|
||||
'# TYPE a counter\n' +
|
||||
'a 0\n' +
|
||||
'\n' +
|
||||
'# HELP b Help\n' +
|
||||
'# TYPE b gauge\n' +
|
||||
'b 0\n'
|
||||
"# HELP a Help\n" +
|
||||
"# TYPE a counter\n" +
|
||||
"a 0\n" +
|
||||
"\n" +
|
||||
"# HELP b Help\n" +
|
||||
"# TYPE b gauge\n" +
|
||||
"b 0\n"
|
||||
);
|
||||
});
|
||||
it("should format labeled metrics", async function() {
|
||||
let registry = new prometheus.CollectorRegistry();
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['a', 'b']}
|
||||
"test", "Help", { register: false, labels: ["a", "b"]}
|
||||
);
|
||||
gauge.labels({a: '1', b: '2'});
|
||||
gauge.labels({b: 'y', a: 'x'});
|
||||
gauge.labels({a: "1", b: "2"});
|
||||
gauge.labels({b: "y", a: "x"});
|
||||
registry.register(gauge);
|
||||
let exposition = await prometheus.exposition(registry.collect());
|
||||
assert.equal(
|
||||
exposition,
|
||||
'# HELP test Help\n' +
|
||||
'# TYPE test gauge\n' +
|
||||
"# HELP test Help\n" +
|
||||
"# TYPE test gauge\n" +
|
||||
'test{a="1",b="2"} 0\n' +
|
||||
'test{a="x",b="y"} 0\n'
|
||||
);
|
||||
@@ -502,17 +502,17 @@ describe("lib/prometheus", function() {
|
||||
it("should format Infinity and NaN", async function() {
|
||||
let registry = new prometheus.CollectorRegistry();
|
||||
let gauge = new prometheus.Gauge(
|
||||
'test', "Help", { register: false, labels: ['n']}
|
||||
"test", "Help", { register: false, labels: ["n"]}
|
||||
);
|
||||
gauge.labels({n: '1'}).set(Infinity);
|
||||
gauge.labels({n: '2'}).set(-Infinity);
|
||||
gauge.labels({n: '3'}).set(NaN);
|
||||
gauge.labels({n: "1"}).set(Infinity);
|
||||
gauge.labels({n: "2"}).set(-Infinity);
|
||||
gauge.labels({n: "3"}).set(NaN);
|
||||
registry.register(gauge);
|
||||
let exposition = await prometheus.exposition(registry.collect());
|
||||
assert.equal(
|
||||
exposition,
|
||||
'# HELP test Help\n' +
|
||||
'# TYPE test gauge\n' +
|
||||
"# HELP test Help\n" +
|
||||
"# TYPE test gauge\n" +
|
||||
'test{n="1"} +Inf\n' +
|
||||
'test{n="2"} -Inf\n' +
|
||||
'test{n="3"} NaN\n'
|
||||
@@ -521,11 +521,11 @@ describe("lib/prometheus", function() {
|
||||
});
|
||||
|
||||
let serializedResult = {
|
||||
metric: { type: 'type', name: 'name', help: "Help", labels: ['a', 'b'] },
|
||||
metric: { type: "type", name: "name", help: "Help", labels: ["a", "b"] },
|
||||
samples: [ ['a="1",b="2"', 1], ['a="3",b="4"', 5], ]
|
||||
};
|
||||
let deserializedResult = {
|
||||
metric: new prometheus.Metric('type', 'name', "Help", ['a', 'b']),
|
||||
metric: new prometheus.Metric("type", "name", "Help", ["a", "b"]),
|
||||
samples: new Map([['a="1",b="2"', 1], ['a="3",b="4"', 5]]),
|
||||
};
|
||||
describe("serializeResult()", function() {
|
||||
@@ -538,21 +538,21 @@ describe("lib/prometheus", function() {
|
||||
it("should support adding labels", function() {
|
||||
assert.deepEqual(
|
||||
prometheus.serializeResult({
|
||||
metric: new prometheus.Metric('type', 'name', "Help"),
|
||||
samples: new Map([['', 2]]),
|
||||
}, { addLabels: { c: '8' }}),
|
||||
metric: new prometheus.Metric("type", "name", "Help"),
|
||||
samples: new Map([["", 2]]),
|
||||
}, { addLabels: { c: "8" }}),
|
||||
{
|
||||
metric: {type: 'type', name: 'name', help: "Help", labels: ['c']},
|
||||
metric: {type: "type", name: "name", help: "Help", labels: ["c"]},
|
||||
samples: [['c="8"', 2]],
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
prometheus.serializeResult({
|
||||
metric: new prometheus.Metric('type', 'name', "Help", ['a']),
|
||||
metric: new prometheus.Metric("type", "name", "Help", ["a"]),
|
||||
samples: new Map([['a="4"', 3]]),
|
||||
}, { addLabels: { c: '8' }}),
|
||||
}, { addLabels: { c: "8" }}),
|
||||
{
|
||||
metric: {type: 'type', name: 'name', help: "Help", labels: ['a', 'c']},
|
||||
metric: {type: "type", name: "name", help: "Help", labels: ["a", "c"]},
|
||||
samples: [['a="4",c="8"', 3]],
|
||||
}
|
||||
);
|
||||
@@ -560,30 +560,30 @@ describe("lib/prometheus", function() {
|
||||
it("should support redefining name and help", function() {
|
||||
assert.deepEqual(
|
||||
prometheus.serializeResult({
|
||||
metric: new prometheus.Metric('type', 'name', "Help"),
|
||||
samples: new Map([['', 2]]),
|
||||
}, { metricName: 'new', }),
|
||||
metric: new prometheus.Metric("type", "name", "Help"),
|
||||
samples: new Map([["", 2]]),
|
||||
}, { metricName: "new", }),
|
||||
{
|
||||
metric: {type: 'type', name: 'new', help: "Help", labels: []},
|
||||
samples: [['', 2]],
|
||||
metric: {type: "type", name: "new", help: "Help", labels: []},
|
||||
samples: [["", 2]],
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
prometheus.serializeResult({
|
||||
metric: new prometheus.Metric('type', 'name', "Help"),
|
||||
samples: new Map([['', 2]]),
|
||||
metric: new prometheus.Metric("type", "name", "Help"),
|
||||
samples: new Map([["", 2]]),
|
||||
}, { metricHelp: "old", }),
|
||||
{
|
||||
metric: {type: 'type', name: 'name', help: "old", labels: []},
|
||||
samples: [['', 2]],
|
||||
metric: {type: "type", name: "name", help: "old", labels: []},
|
||||
samples: [["", 2]],
|
||||
}
|
||||
);
|
||||
});
|
||||
it("should throw on unrecoginzed option", function() {
|
||||
assert.throws(
|
||||
() => new prometheus.serializeResult({
|
||||
metric: new prometheus.Metric('type', 'name', "Help"),
|
||||
samples: new Map([['', 3]]),
|
||||
metric: new prometheus.Metric("type", "name", "Help"),
|
||||
samples: new Map([["", 3]]),
|
||||
}, { invalid: true }),
|
||||
new Error("Unrecognized option 'invalid'")
|
||||
);
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
const assert = require('assert').strict;
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const mock = require('./mock');
|
||||
const master = require('../master');
|
||||
const mock = require("./mock");
|
||||
const master = require("../master");
|
||||
|
||||
|
||||
describe('Master testing', function() {
|
||||
describe("Master testing", function() {
|
||||
});
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// These are libraries that does not have any units test, they are
|
||||
// required here in order to track coverage for them.
|
||||
|
||||
require('lib/manager/modManager');
|
||||
require('lib/npmPostinstall.js');
|
||||
require("lib/manager/modManager");
|
||||
require("lib/npmPostinstall.js");
|
||||
+4
-4
@@ -42,7 +42,7 @@ class MockConnector extends events.EventEmitter {
|
||||
send(type, data) {
|
||||
let message = { seq: this._seq, type, data };
|
||||
this.sentMessages.push(message);
|
||||
setImmediate(() => this.emit('send', message));
|
||||
setImmediate(() => this.emit("send", message));
|
||||
return this._seq++;
|
||||
}
|
||||
}
|
||||
@@ -55,13 +55,13 @@ class MockServer {
|
||||
|
||||
async sendRcon(command) {
|
||||
this.rconCommands.push(command);
|
||||
return this.rconCommandResults.get(command) || '';
|
||||
return this.rconCommandResults.get(command) || "";
|
||||
}
|
||||
}
|
||||
|
||||
class MockInstance extends link.Link {
|
||||
constructor() {
|
||||
super('instance', 'slave', new MockConnector());
|
||||
super("instance", "slave", new MockConnector());
|
||||
this.server = new MockServer();
|
||||
this.name = "test";
|
||||
this.config = {
|
||||
@@ -75,7 +75,7 @@ class MockInstance extends link.Link {
|
||||
|
||||
class MockSlave extends link.Link {
|
||||
constructor() {
|
||||
super('slave', 'master', new MockConnector());
|
||||
super("slave", "master", new MockConnector());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
const assert = require('assert').strict;
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
const fs = require("fs-extra");
|
||||
|
||||
const link = require("lib/link");
|
||||
const config = require("lib/config");
|
||||
@@ -65,19 +65,19 @@ describe("Slave testing", function() {
|
||||
});
|
||||
|
||||
it("should throw on CON, PRN, AUX, NUL, COM1, LPT1", function() {
|
||||
for (let bad of ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'LPT1']) {
|
||||
for (let bad of ["CON", "PRN", "AUX", "NUL", "COM1", "LPT1"]) {
|
||||
check(
|
||||
bad, 'cannot be named any of . ..'
|
||||
+' CON PRN AUX NUL COM1-9 and LPT1-9'
|
||||
bad, "cannot be named any of . .."
|
||||
+" CON PRN AUX NUL COM1-9 and LPT1-9"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw on . and ..", function() {
|
||||
for (let bad of ['.', '..']) {
|
||||
for (let bad of [".", ".."]) {
|
||||
check(
|
||||
bad, 'cannot be named any of . ..'
|
||||
+' CON PRN AUX NUL COM1-9 and LPT1-9'
|
||||
bad, "cannot be named any of . .."
|
||||
+" CON PRN AUX NUL COM1-9 and LPT1-9"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user