Skip to content

Commit

Permalink
feat: add stub for failover
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 31, 2022
1 parent e69903e commit 0c69daf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 50%](https://img.shields.io/badge/redis-50%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 51%](https://img.shields.io/badge/redis-51%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

This library emulates [ioredis](https://github.com/luin/ioredis) by performing
all operations in-memory. The best way to do integration testing against redis
Expand Down
4 changes: 2 additions & 2 deletions compat.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Supported commands ![Commands Coverage: 50%](https://img.shields.io/badge/coverage-50%25-red.svg)
## Supported commands ![Commands Coverage: 51%](https://img.shields.io/badge/coverage-51%25-red.svg)

| redis | ioredis | ioredis-mock |
| ---------------------- | :----------------: | :----------------: |
Expand Down Expand Up @@ -35,7 +35,7 @@
| [exists] | :white_check_mark: | :white_check_mark: |
| [expire] | :white_check_mark: | :white_check_mark: |
| [expireat] | :white_check_mark: | :white_check_mark: |
| [failover] | :white_check_mark: | :x: |
| [failover] | :white_check_mark: | :white_check_mark: |
| [flushall] | :white_check_mark: | :white_check_mark: |
| [flushdb] | :white_check_mark: | :white_check_mark: |
| [geoadd] | :white_check_mark: | :x: |
Expand Down
8 changes: 8 additions & 0 deletions src/commands/failover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function failover() {
throw new Error('ERR FAILOVER requires connected replicas.')
}

export function failoverBuffer(...args) {
const val = failover.apply(this, args)
return val ? Buffer.from(val) : val
}
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './evalsha'
export * from './exists'
export * from './expire'
export * from './expireat'
export * from './failover'
export * from './flushall'
export * from './flushdb'
export * from './get'
Expand Down
21 changes: 21 additions & 0 deletions test/integration/commands/failover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Redis from 'ioredis'

// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

runTwinSuite('failover', command => {
describe(command, () => {
it('should throw an error when no replicas are connected', async () => {
const redis = new Redis()
expect.hasAssertions()

try {
await redis[command]()
} catch (err) {
expect(err.message).toBe('ERR FAILOVER requires connected replicas.')
}

redis.disconnect()
})
})
})

0 comments on commit 0c69daf

Please sign in to comment.