From fde750a7744561d145de16a31ab8a187a4da82f0 Mon Sep 17 00:00:00 2001 From: Joey Guerra Date: Sun, 23 Jul 2023 11:19:24 -0500 Subject: [PATCH] fix: Fails to connect to Redis --- .github/workflows/e2e.yml | 34 +++++++ package-lock.json | 204 ++++++++------------------------------ package.json | 4 +- src/redis-brain.js | 12 ++- test/e2e/connect.js | 39 ++++++++ 5 files changed, 126 insertions(+), 167 deletions(-) create mode 100644 .github/workflows/e2e.yml create mode 100644 test/e2e/connect.js diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..1d0e70e --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,34 @@ +name: End to end tests +on: [push] + +permissions: + contents: read +jobs: + e2e-tests: + name: E2E Tests + runs-on: ubuntu-latest + services: + redis: + image: redis + ports: + - 6379:6379 + permissions: + contents: write + issues: write + pull-requests: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "lts/*" + - name: Install Dependencies + run: npm ci + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + - name: Run Tests + run: npm run e2e \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 37ae483..4cc5293 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1738,24 +1738,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/ansicolors": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", @@ -1969,9 +1951,9 @@ } }, "node_modules/async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw==", + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==", "dev": true }, "node_modules/atob": { @@ -2476,22 +2458,6 @@ "node": ">=4" } }, - "node_modules/chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A==", - "dev": true, - "dependencies": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -2686,16 +2652,16 @@ } }, "node_modules/coffeescript": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.6.3.tgz", - "integrity": "sha512-0yrF6eG4bzTMkTNEQDMyM3Vx7n1q/SPTJEgnkubfxNQezhJ+NkF8ouuh92x7Swd4zmE4F/QHpV0iUCBB4LuRIg==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.7.0.tgz", + "integrity": "sha512-hzWp6TUE2d/jCcN67LrW1eh5b/rSDKQK6oD6VMLlggYVUUFexgTH9z3dNYihzX4RMhze5FTUsUmOXViJKFQR/A==", "dev": true, "bin": { "cake": "bin/cake", "coffee": "bin/coffee" }, "engines": { - "node": ">=0.8.0" + "node": ">=6" } }, "node_modules/collection-visit": { @@ -4306,9 +4272,9 @@ } }, "node_modules/express-basic-auth": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.1.7.tgz", - "integrity": "sha512-gofejPlyXxuRQfbc2pfCBEjFgKUPwICLoEJuC6i2KqBPBszBU7bIKvpEKrsU0oCCFDo2L1YuK/KSG5gVyess+A==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.2.1.tgz", + "integrity": "sha512-L6YQ1wQ/mNjVLAmK3AG1RK6VkokA1BIY6wmiH304Xtt/cLTps40EusZsU1Uop+v9lTDPxdtzbFmdXfFO3KEnwA==", "dev": true, "dependencies": { "basic-auth": "^2.0.1" @@ -5347,18 +5313,6 @@ "node": ">= 0.4.0" } }, - "node_modules/has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg==", - "dev": true, - "dependencies": { - "ansi-regex": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -5627,20 +5581,19 @@ "dev": true }, "node_modules/hubot": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/hubot/-/hubot-3.4.0.tgz", - "integrity": "sha512-3Q3nhJifAcH3oPp2aNg03+0KUzQLKp856fvXWX4UpTu6jpseAD+lUIm/200CzDb9VMgC9sH5tDXq89m74zHjlA==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/hubot/-/hubot-3.5.0.tgz", + "integrity": "sha512-7hAo59yit3MnyYB6Px2z4toMYcePH6TB1ZwcV5wsiCMQNe7ruHN5JiRITDZiLlTvHyiM709+tzxtc/MWWaBIGw==", "dev": true, "dependencies": { - "async": ">=0.1.0 <1.0.0", - "chalk": "^1.0.0", + "async": "^3.2.4", "cline": "^0.8.2", - "coffeescript": "1.6.3", - "connect-multiparty": "^2.1.1", - "express": "^4.16.3", - "express-basic-auth": "1.1.7", + "coffeescript": "^2.7.0", + "connect-multiparty": "^2.2.0", + "express": "^4.18.2", + "express-basic-auth": "^1.2.1", "log": "1.4.0", - "optparse": "1.0.4" + "optparse": "^1.0.5" }, "bin": { "hubot": "bin/hubot" @@ -11015,9 +10968,9 @@ } }, "node_modules/optparse": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/optparse/-/optparse-1.0.4.tgz", - "integrity": "sha512-kPnGNF9pL0Tytj29uIEo4qt9J4XqnZKFZQoQjd1APo3lF9lODP1nvSXcdqK3SnEdNnN3d8HnradcytHfgowX7g==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/optparse/-/optparse-1.0.5.tgz", + "integrity": "sha512-WfnNWLS3vr8omCm8nKYKaRbapuy6pEbx1O0B+eP5sUf/a++sT9/h8PflqBoHsY9N+YdzUT12T8snXigq13QpJg==", "dev": true }, "node_modules/p-each-series": { @@ -13482,18 +13435,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", - "dev": true, - "dependencies": { - "ansi-regex": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/strip-bom": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", @@ -13538,15 +13479,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/supports-hyperlinks": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz", @@ -15666,18 +15598,6 @@ } } }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", - "dev": true - }, - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA==", - "dev": true - }, "ansicolors": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", @@ -15840,9 +15760,9 @@ "dev": true }, "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw==", + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==", "dev": true }, "atob": { @@ -16220,19 +16140,6 @@ "type-detect": "^4.0.5" } }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A==", - "dev": true, - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -16378,9 +16285,9 @@ "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==" }, "coffeescript": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.6.3.tgz", - "integrity": "sha512-0yrF6eG4bzTMkTNEQDMyM3Vx7n1q/SPTJEgnkubfxNQezhJ+NkF8ouuh92x7Swd4zmE4F/QHpV0iUCBB4LuRIg==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.7.0.tgz", + "integrity": "sha512-hzWp6TUE2d/jCcN67LrW1eh5b/rSDKQK6oD6VMLlggYVUUFexgTH9z3dNYihzX4RMhze5FTUsUmOXViJKFQR/A==", "dev": true }, "collection-visit": { @@ -17641,9 +17548,9 @@ } }, "express-basic-auth": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.1.7.tgz", - "integrity": "sha512-gofejPlyXxuRQfbc2pfCBEjFgKUPwICLoEJuC6i2KqBPBszBU7bIKvpEKrsU0oCCFDo2L1YuK/KSG5gVyess+A==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.2.1.tgz", + "integrity": "sha512-L6YQ1wQ/mNjVLAmK3AG1RK6VkokA1BIY6wmiH304Xtt/cLTps40EusZsU1Uop+v9lTDPxdtzbFmdXfFO3KEnwA==", "dev": true, "requires": { "basic-auth": "^2.0.1" @@ -18380,15 +18287,6 @@ "function-bind": "^1.1.1" } }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg==", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, "has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -18580,20 +18478,19 @@ } }, "hubot": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/hubot/-/hubot-3.4.0.tgz", - "integrity": "sha512-3Q3nhJifAcH3oPp2aNg03+0KUzQLKp856fvXWX4UpTu6jpseAD+lUIm/200CzDb9VMgC9sH5tDXq89m74zHjlA==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/hubot/-/hubot-3.5.0.tgz", + "integrity": "sha512-7hAo59yit3MnyYB6Px2z4toMYcePH6TB1ZwcV5wsiCMQNe7ruHN5JiRITDZiLlTvHyiM709+tzxtc/MWWaBIGw==", "dev": true, "requires": { - "async": ">=0.1.0 <1.0.0", - "chalk": "^1.0.0", + "async": "^3.2.4", "cline": "^0.8.2", - "coffeescript": "1.6.3", - "connect-multiparty": "^2.1.1", - "express": "^4.16.3", - "express-basic-auth": "1.1.7", + "coffeescript": "^2.7.0", + "connect-multiparty": "^2.2.0", + "express": "^4.18.2", + "express-basic-auth": "^1.2.1", "log": "1.4.0", - "optparse": "1.0.4" + "optparse": "^1.0.5" } }, "human-signals": { @@ -22421,9 +22318,9 @@ } }, "optparse": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/optparse/-/optparse-1.0.4.tgz", - "integrity": "sha512-kPnGNF9pL0Tytj29uIEo4qt9J4XqnZKFZQoQjd1APo3lF9lODP1nvSXcdqK3SnEdNnN3d8HnradcytHfgowX7g==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/optparse/-/optparse-1.0.5.tgz", + "integrity": "sha512-WfnNWLS3vr8omCm8nKYKaRbapuy6pEbx1O0B+eP5sUf/a++sT9/h8PflqBoHsY9N+YdzUT12T8snXigq13QpJg==", "dev": true }, "p-each-series": { @@ -24249,15 +24146,6 @@ "es-abstract": "^1.20.4" } }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, "strip-bom": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", @@ -24284,12 +24172,6 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==", - "dev": true - }, "supports-hyperlinks": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz", diff --git a/package.json b/package.json index 18369bf..3d6a641 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "main": "index.js", "scripts": { "pretest": "standard", - "test": "nyc --reporter=html --reporter=text mocha --exit" + "test": "nyc --reporter=html --reporter=text mocha --exit", + "e2e": "mocha --exit test/e2e", + "standard": "standard" }, "dependencies": { "redis": "^4.6.6", diff --git a/src/redis-brain.js b/src/redis-brain.js index e001a95..3099b66 100644 --- a/src/redis-brain.js +++ b/src/redis-brain.js @@ -44,11 +44,9 @@ module.exports = function (robot) { robot.brain.setAutoSave(false) - const getData = () => - client.get(`${prefix}:storage`, function (err, reply) { - if (err) { - throw err - } else if (reply) { + const getData = () => { + client.get(`${prefix}:storage`).then((reply) => { + if (reply) { robot.logger.info(`hubot-redis-brain: Data for ${prefix} brain retrieved from Redis`) robot.brain.mergeData(JSON.parse(reply.toString())) robot.brain.emit('connected') @@ -59,7 +57,10 @@ module.exports = function (robot) { } robot.brain.setAutoSave(true) + }).catch(err => { + robot.logger.error(`hubot-redis-brain: Unable to get data from Redis: ${err}`) }) + } if (info.auth) { client.auth(info.auth.split(':')[1], function (err) { @@ -91,6 +92,7 @@ module.exports = function (robot) { }) robot.brain.on('close', () => client.quit()) + client.connect().then(() => {}).catch(robot.logger.error) } function getRedisEnv () { diff --git a/test/e2e/connect.js b/test/e2e/connect.js new file mode 100644 index 0000000..76a6816 --- /dev/null +++ b/test/e2e/connect.js @@ -0,0 +1,39 @@ +'use strict' + +/* global describe, it */ +/* eslint-disable no-unused-expressions */ +const shell = require('hubot/src/adapters/shell') +const Adapter = require('hubot/src/adapter') + +const path = require('path') + +const chai = require('chai') +const sinon = require('sinon') +const Hubot = require('hubot') + +const expect = chai.expect +const Robot = Hubot.Robot + +chai.use(require('sinon-chai')) + +describe('e2e', () => { + it('connects to redis', done => { + shell.use = robot => { + return new Adapter() + } + + const robot = new Robot(null, 'shell', false, 'hubot') + sinon.spy(robot.logger, 'debug') + robot.brain.on('loaded', actual => { + const expected = { users: {}, _private: {} } + expect(actual).to.deep.equal(expected) + }) + robot.brain.on('connected', () => { + expect(robot.logger.debug).to.have.been.calledWith('hubot-redis-brain: Successfully connected to Redis') + robot.shutdown() + done() + }) + robot.loadFile(path.resolve('src/'), 'redis-brain.js') + robot.run() + }) +})