-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathpins-test.js
79 lines (67 loc) · 2.16 KB
/
pins-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'
const { Buffer } = require('buffer')
const { expect } = require('./utils/chai')
const range = require('just-range')
const Key = require('interface-datastore').Key
module.exports = (repo) => {
describe('pins', () => {
const dataList = range(100).map((i) => Buffer.from(`hello-${i}-${Math.random()}`))
const data = Buffer.from('hello world')
const b = new Key('hello')
it('exists', () => {
expect(repo).to.have.property('pins')
})
it('implements interface-datastore', () => {
const pins = repo.pins
expect(pins.batch).to.exist()
expect(pins.query).to.exist()
})
describe('.put', () => {
it('simple', async () => {
await repo.pins.put(b, data)
})
it('multi write (locks)', async () => {
await Promise.all([repo.pins.put(b, data), repo.pins.put(b, data)])
})
it('massive multiwrite', async function () {
this.timeout(15000) // add time for ci
await Promise.all(range(100).map((i) => {
return repo.pins.put(new Key('hello' + i), dataList[i])
}))
})
})
describe('.get', () => {
it('simple', async () => {
const val = await repo.pins.get(b)
expect(val).to.be.eql(data)
})
it('massive read', async function () {
this.timeout(15000) // add time for ci
await Promise.all(range(20 * 100).map(async (i) => {
const j = i % dataList.length
const val = await repo.pins.get(new Key('hello' + j))
expect(val).to.be.eql(dataList[j])
}))
}).timeout(10 * 1000)
})
describe('.has', () => {
it('existing pin', async () => {
const exists = await repo.pins.has(b)
expect(exists).to.eql(true)
})
it('non existent pin', async () => {
const exists = await repo.pins.has(new Key('world'))
expect(exists).to.eql(false)
})
})
describe('.delete', () => {
it('simple', async () => {
await repo.pins.delete(b)
const exists = await repo.pins.has(b)
expect(exists).to.equal(false)
})
})
})
}