mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13: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
+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")();
|
||||
|
||||
Reference in new issue
Block a user