Skip to content

Commit

Permalink
chore: fix open handles
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Apr 11, 2023
1 parent ebd16a0 commit 9a0024c
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 204 deletions.
54 changes: 31 additions & 23 deletions test/integration/commands/ltrim.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,39 @@ runTwinSuite('ltrim', (command, equals) => {
}
)

it('should return empty array if out-of-range', () => {
const redis = new Redis({
data: {
foo: ['1', '2', '3', '4', '5'],
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should return empty array if out-of-range',
() => {
const redis = new Redis({
data: {
foo: ['1', '2', '3', '4', '5'],
},
})

return Promise.all([
redis[command]('foo', 10, 100).then(res =>
expect(equals(res, 'OK')).toBe(true)
),
redis.lrange('foo', 0, -1).then(res => expect(res).toEqual([])),
])
})
return Promise.all([
redis[command]('foo', 10, 100).then(res =>
expect(equals(res, 'OK')).toBe(true)
),
redis.lrange('foo', 0, -1).then(res => expect(res).toEqual([])),
])
}
)

it('should throw an exception if the key contains something other than a list', () => {
const redis = new Redis({
data: {
foo: 'not a list',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the key contains something other than a list',
() => {
const redis = new Redis({
data: {
foo: 'not a list',
},
})

return redis[command]('foo', 0, 2).catch(err =>
expect(err.message).toBe('Key foo does not contain a list')
)
})
return redis[command]('foo', 0, 2).catch(err =>
expect(err.message).toBe('Key foo does not contain a list')
)
}
)
})
})
89 changes: 51 additions & 38 deletions test/integration/commands/rpoplpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runTwinSuite } from '../../../test-utils'

runTwinSuite('rpoplpush', (command, equals) => {
describe(command, () => {
const redis = new Redis()
afterAll(() => {
redis.disconnect()
})

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should remove one item from the tail of the source list',
Expand Down Expand Up @@ -39,26 +44,26 @@ runTwinSuite('rpoplpush', (command, equals) => {
)

it('should return null if the source list does not exist', () => {
const redis = new Redis({
data: {},
})

return redis[command]('foo', 'bar').then(item =>
return redis[command]('baz', 'bar').then(item =>
expect(item).toEqual(null)
)
})

it('should return null if the source list is empty', () => {
const redis = new Redis({
data: {
foo: [],
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should return null if the source list is empty',
() => {
const redis = new Redis({
data: {
foo: [],
},
})

return redis[command]('foo', 'bar').then(item =>
expect(item).toEqual(null)
)
})
return redis[command]('foo', 'bar').then(item =>
expect(item).toEqual(null)
)
}
)

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)('should return the item', () => {
Expand Down Expand Up @@ -88,32 +93,40 @@ runTwinSuite('rpoplpush', (command, equals) => {
}
)

it('should throw an exception if the source key contains something other than a list', () => {
const redis = new Redis({
data: {
foo: 'not a list',
bar: [],
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the source key contains something other than a list',
() => {
const redis = new Redis({
data: {
foo: 'not a list',
bar: [],
},
})

return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe(
'WRONGTYPE Operation against a key holding the wrong kind of value'
return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe(
'WRONGTYPE Operation against a key holding the wrong kind of value'
)
)
)
})
}
)

it('should throw an exception if the destination key contains something other than a list', () => {
const redis = new Redis({
data: {
foo: [],
bar: 'not a list',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the destination key contains something other than a list',
() => {
const redis = new Redis({
data: {
foo: [],
bar: 'not a list',
},
})

return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key bar does not contain a list')
)
})
return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key bar does not contain a list')
)
}
)
})
})
57 changes: 34 additions & 23 deletions test/integration/commands/sdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runTwinSuite } from '../../../test-utils'

runTwinSuite('sdiff', command => {
describe(command, () => {
const redis = new Redis()
afterAll(() => {
redis.disconnect()
})

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should return the difference between the first set and all the successive sets',
Expand All @@ -26,34 +31,40 @@ runTwinSuite('sdiff', command => {
}
)

it('should throw an exception if the first key is not of a set', () => {
const redis = new Redis({
data: {
foo: 'not a set',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the first key is not of a set',
() => {
const redis = new Redis({
data: {
foo: 'not a set',
},
})

return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key foo does not contain a set')
)
})
return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key foo does not contain a set')
)
}
)

it('should throw an exception if the destination contains something other than a set', () => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the destination contains something other than a set',
() => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})

return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key bar does not contain a set')
)
})
return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe('Key bar does not contain a set')
)
}
)

it("should return empty array if sources don't exists", () => {
const redis = new Redis()

return redis[command]('foo', 'bar').then(result =>
expect(
command === 'sdiffBuffer' ? result.map(r => r.toString()) : result
Expand Down
16 changes: 6 additions & 10 deletions test/integration/commands/sdiffstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,11 @@ runTwinSuite('sdiffstore', command => {
}
)

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
"should return 0 if sources don't exists",
() => {
return redis[command]('dest', 'foo', 'bar')
.then(count => expect(count).toEqual(0))
.then(() => redis.smembers('dest'))
.then(result => expect(result).toEqual([]))
}
)
it("should return 0 if sources don't exists", () => {
return redis[command]('dest', 'foo', 'bar')
.then(count => expect(count).toEqual(0))
.then(() => redis.smembers('dest'))
.then(result => expect(result).toEqual([]))
})
})
})
30 changes: 16 additions & 14 deletions test/integration/commands/sinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ runTwinSuite('sinter', command => {
}
)

it('should throw an exception if one of the keys is not a set', () => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if one of the keys is not a set',
() => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})

return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe(
'WRONGTYPE Operation against a key holding the wrong kind of value'
return redis[command]('foo', 'bar').catch(err =>
expect(err.message).toBe(
'WRONGTYPE Operation against a key holding the wrong kind of value'
)
)
)
})
}
)

it("should return empty array if sources don't exists", () => {
const redis = new Redis()

return redis[command]('foo', 'bar').then(result =>
expect(result).toEqual([])
)
Expand Down
57 changes: 34 additions & 23 deletions test/integration/commands/smove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { runTwinSuite } from '../../../test-utils'

runTwinSuite('smove', command => {
describe(command, () => {
const redis = new Redis()
afterAll(() => {
redis.disconnect()
})

// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should move value from source to destination',
Expand Down Expand Up @@ -41,36 +46,42 @@ runTwinSuite('smove', command => {
)

it('should return 0 if source does not exist', () => {
const redis = new Redis()

return redis[command]('foo', 'bar', 'two').then(status =>
expect(status).toBe(0)
)
})

it('should throw an exception if the source contains something other than a set', () => {
const redis = new Redis({
data: {
foo: 'not a set',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the source contains something other than a set',
() => {
const redis = new Redis({
data: {
foo: 'not a set',
},
})

return redis[command]('foo', 'bar', 'two').catch(err =>
expect(err.message).toBe('Key foo does not contain a set')
)
})
return redis[command]('foo', 'bar', 'two').catch(err =>
expect(err.message).toBe('Key foo does not contain a set')
)
}
)

it('should throw an exception if the destination contains something other than a set', () => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})
// @TODO Rewrite test so it runs on a real Redis instance
;(process.env.IS_E2E ? it.skip : it)(
'should throw an exception if the destination contains something other than a set',
() => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})

return redis[command]('foo', 'bar', 'two').catch(err =>
expect(err.message).toBe('Key bar does not contain a set')
)
})
return redis[command]('foo', 'bar', 'two').catch(err =>
expect(err.message).toBe('Key bar does not contain a set')
)
}
)
})
})
Loading

0 comments on commit 9a0024c

Please sign in to comment.