-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store pins in datastore (#221)
- Loading branch information
1 parent
8660e4f
commit 467c430
Showing
9 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
webpack: { | ||
node: { | ||
// this is needed until level stops using node buffers in browser code | ||
Buffer: true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* 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') | ||
}) | ||
|
||
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) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters