From d8cc58a7e47ad2c6875f8da88ec5d49ffd146bb6 Mon Sep 17 00:00:00 2001 From: Dao Lam Date: Mon, 21 May 2018 14:41:00 -0700 Subject: [PATCH] fix: args values need to be string (#26) --- index.js | 6 +++--- test/data/fullConfig.json | 2 +- test/index.test.js | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c44c315..141bec3 100644 --- a/index.js +++ b/index.js @@ -287,7 +287,7 @@ class ExecutorQueue extends Executor { return this.queueBreaker.runCommand('enqueue', this.buildQueue, 'start', [{ buildId, jobId, - blockedBy + blockedBy: blockedBy.toString() }]); } @@ -307,7 +307,7 @@ class ExecutorQueue extends Executor { const numDeleted = await this.queueBreaker.runCommand('del', this.buildQueue, 'start', [{ buildId, jobId, - blockedBy + blockedBy: blockedBy.toString() }]); if (numDeleted !== 0) { @@ -319,7 +319,7 @@ class ExecutorQueue extends Executor { return this.queueBreaker.runCommand('enqueue', this.buildQueue, 'stop', [{ buildId, jobId, - blockedBy + blockedBy: blockedBy.toString() }]); } diff --git a/test/data/fullConfig.json b/test/data/fullConfig.json index 146c536..bd1f25c 100644 --- a/test/data/fullConfig.json +++ b/test/data/fullConfig.json @@ -7,5 +7,5 @@ "container": "node:4", "apiUri": "http://api.com", "token": "asdf", - "blockedBy": [777] + "blockedBy": [777, 888] } diff --git a/test/index.test.js b/test/index.test.js index effbb0b..731cc6f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -16,6 +16,8 @@ const partialTestConfig = { jobId: testConfig.jobId, blockedBy: testConfig.blockedBy }; +const partialTestConfigToString = Object.assign({}, partialTestConfig, { + blockedBy: testConfig.blockedBy.toString() }); const tokenGen = sinon.stub().returns('123456abc'); const testDelayedConfig = { pipeline: testPipeline, @@ -302,7 +304,14 @@ describe('index test', () => { assert.calledOnce(queueMock.connect); assert.calledWith(redisMock.hset, 'buildConfigs', testConfig.buildId, JSON.stringify(testConfig)); - assert.calledWith(queueMock.enqueue, 'builds', 'start', [partialTestConfig]); + assert.calledWith(queueMock.enqueue, 'builds', 'start', [partialTestConfigToString]); + })); + + it('enqueues a build and caches the config', () => executor.start(testConfig).then(() => { + assert.calledOnce(queueMock.connect); + assert.calledWith(redisMock.hset, 'buildConfigs', testConfig.buildId, + JSON.stringify(testConfig)); + assert.calledWith(queueMock.enqueue, 'builds', 'start', [partialTestConfigToString]); })); it('doesn\'t call connect if there\'s already a connection', () => { @@ -310,7 +319,8 @@ describe('index test', () => { return executor.start(testConfig).then(() => { assert.notCalled(queueMock.connect); - assert.calledWith(queueMock.enqueue, 'builds', 'start', [partialTestConfig]); + assert.calledWith(queueMock.enqueue, 'builds', 'start', + [partialTestConfigToString]); }); }); }); @@ -329,7 +339,7 @@ describe('index test', () => { it('removes a start event from the queue and the cached buildconfig', () => executor.stop(partialTestConfig).then(() => { assert.calledOnce(queueMock.connect); - assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfig]); + assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfigToString]); assert.calledWith(redisMock.hdel, 'buildConfigs', 8609); assert.notCalled(queueMock.enqueue); })); @@ -339,8 +349,8 @@ describe('index test', () => { return executor.stop(partialTestConfig).then(() => { assert.calledOnce(queueMock.connect); - assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfig]); - assert.calledWith(queueMock.enqueue, 'builds', 'stop', [partialTestConfig]); + assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfigToString]); + assert.calledWith(queueMock.enqueue, 'builds', 'stop', [partialTestConfigToString]); }); }); @@ -351,7 +361,7 @@ describe('index test', () => { 'beta.screwdriver.cd/executor': 'screwdriver-executor-k8s' } })).then(() => { assert.notCalled(queueMock.connect); - assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfig]); + assert.calledWith(queueMock.del, 'builds', 'start', [partialTestConfigToString]); }); }); });