Skip to content

Commit

Permalink
feat: redis migrations + redis tests (#26)
Browse files Browse the repository at this point in the history
* feat: redis migrations + redis tests

* fix: lint settings
  • Loading branch information
pajgo authored Mar 10, 2020
1 parent 206ddd6 commit 8ce85b8
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "makeomatic",
"rules": {
"semi": ["error", "never"],
"quotes": ["error", "single", { "allowTemplateLiterals": true }]
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 0 }]
}
}
15 changes: 15 additions & 0 deletions migrations/redis/01-create-constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
async function createConstantKeys(service) {
const { redis } = service
const pipeline = redis.pipeline()
pipeline.set('some.key')
pipeline.sadd('some.set', 'value')
pipeline.sadd('some.set', 'other value')

await pipeline.exec()
}

module.exports = {
min: 0,
final: 1,
script: createConstantKeys,
}
5 changes: 5 additions & 0 deletions migrations/redis/02-lua-migration/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
min: 1,
final: 2,
script: `${__dirname}/update-data.lua`,
}
3 changes: 3 additions & 0 deletions migrations/redis/02-lua-migration/update-data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
redis.call('del', '{demo-app}some.key')
redis.call('srem', '{demo-app}some.set', 'value')
redis.call('sadd', '{demo-app}some.set', 'new value')
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@microfleet/transport-amqp": "^15.0.0",
"@microfleet/validation": "^8.1.2",
"common-errors": "^1.0.5",
"ioredis": "^4.14.1",
"ms-conf": "^5.0.2",
"uuid": "^3.3.3"
},
Expand Down
6 changes: 6 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
'http',
'router',
'amqp',
'redisCluster',
],
app: {
someSecret: {
Expand All @@ -46,6 +47,11 @@ module.exports = {
directory: path.resolve(`${__dirname}/../migrations/knex`),
},
},
redis: {
options: {
keyPrefix: '{demo-app}',
},
},
amqp: {
transport: {
connection: {
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class DemoApp extends Microfleet {
this.addConnector(ConnectorsTypes.migration, async () => {
await this.migrate('knex')
}, 'knex-migration')

this.addConnector(ConnectorsTypes.migration, async () => {
await this.migrate('redis', path.resolve(`${__dirname}/../migrations/redis`))
}, 'redis-migration')
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = {
},
},
},
redis: {
hosts: Array.from({ length: 5 }).map((_, i) => ({
host: 'redis',
port: 7000 + i,
})),
},
knex: {
debug: false,
client: 'pg',
Expand Down
2 changes: 2 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
image: rabbitmq:3.8-alpine
expose:
- "5672"
redis:
image: grokzen/redis-cluster
tester:
expose:
- "3000"
Expand Down
1 change: 0 additions & 1 deletion test/suites/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const rp = require('request-promise')
const DemoApp = require('../../src')

describe('#amqp action test', () => {
// eslint-disable-next-line no-unused-vars
const query = rp.defaults({
baseUrl: 'http://0.0.0.0:3000/amqp',
method: 'POST',
Expand Down
25 changes: 25 additions & 0 deletions test/suites/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const assert = require('assert')
const DemoApp = require('../../src')

describe('#amqp action test', () => {
before(async () => {
this.demoapp = new DemoApp()
await this.demoapp.connect()
})

after(async () => {
await this.demoapp.close()
})

it('connects to redis server', async () => {
const { redis } = this.demoapp
assert.ok(redis, 'should have AMQP plugin')
})

it('should able to call redis commands', async () => {
const { redis } = this.demoapp
await redis.set('sample-key', 'some-value')
const keyContents = await redis.get('sample-key')
assert.strictEqual(keyContents, 'some-value')
})
})
57 changes: 57 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,11 @@ cliui@^5.0.0:
strip-ansi "^5.2.0"
wrap-ansi "^5.1.0"

cluster-key-slot@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz#30474b2a981fb12172695833052bc0d01336d10d"
integrity sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==

code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
Expand Down Expand Up @@ -1014,6 +1019,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

denque@^1.1.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf"
integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==

detect-file@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7"
Expand Down Expand Up @@ -1979,6 +1989,21 @@ invert-kv@^1.0.0:
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"
integrity sha1-EEqOSqym09jNFXqO+L+rLXo//bY=

ioredis@^4.14.1:
version "4.14.1"
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.14.1.tgz#b73ded95fcf220f106d33125a92ef6213aa31318"
integrity sha512-94W+X//GHM+1GJvDk6JPc+8qlM7Dul+9K+lg3/aHixPN7ZGkW6qlvX0DG6At9hWtH2v3B32myfZqWoANUJYGJA==
dependencies:
cluster-key-slot "^1.1.0"
debug "^4.1.1"
denque "^1.1.0"
lodash.defaults "^4.2.0"
lodash.flatten "^4.4.0"
redis-commands "1.5.0"
redis-errors "^1.2.0"
redis-parser "^3.0.0"
standard-as-callback "^2.0.1"

is-absolute@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-absolute/-/is-absolute-1.0.0.tgz#395e1ae84b11f26ad1795e73c17378e48a301576"
Expand Down Expand Up @@ -2378,11 +2403,21 @@ lodash.camelcase@^4.3.0:
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY=

lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=

lodash.defaultsdeep@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6"
integrity sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==

lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
integrity sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
Expand Down Expand Up @@ -3264,6 +3299,23 @@ rechoir@^0.6.2:
dependencies:
resolve "^1.1.6"

[email protected]:
version "1.5.0"
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.5.0.tgz#80d2e20698fe688f227127ff9e5164a7dd17e785"
integrity sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg==

redis-errors@^1.0.0, redis-errors@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad"
integrity sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=

redis-parser@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-3.0.0.tgz#b66d828cdcafe6b4b8a428a7def4c6bcac31c8b4"
integrity sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=
dependencies:
redis-errors "^1.0.0"

regex-not@^1.0.0, regex-not@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
Expand Down Expand Up @@ -3681,6 +3733,11 @@ sshpk@^1.7.0:
safer-buffer "^2.0.2"
tweetnacl "~0.14.0"

standard-as-callback@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/standard-as-callback/-/standard-as-callback-2.0.1.tgz#ed8bb25648e15831759b6023bdb87e6b60b38126"
integrity sha512-NQOxSeB8gOI5WjSaxjBgog2QFw55FV8TkS6Y07BiB3VJ8xNTvUYm0wl0s8ObgQ5NhdpnNfigMIKjgPESzgr4tg==

static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
Expand Down

0 comments on commit 8ce85b8

Please sign in to comment.