Skip to content
This repository has been archived by the owner on Jul 14, 2019. It is now read-only.

Commit

Permalink
fix(test): Tests and docs for new optional API additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Jul 29, 2017
1 parent cf0fa0d commit c37e97e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ class Store {
}
```

There are also optional APIs. These are not required as they may not be
possible on top of certain storage but *may* be required by certain users
of an implementation.

```javascript
class Store {
set (value, ...args, cb) {
// Optional args are sent to the hashing function..
}
hash (value, ...args, cb) {
// Optional args are sent to the hashing function.
}
}
```

## In-Memory Implementation

```javascript
Expand Down
15 changes: 15 additions & 0 deletions tests/test-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ test('fs(implementation): slow hasher', t => {
stream.end()
})

test('fs(implementation): hasher args', t => {
t.plan(4)
const argHasher = (one, two, three, cb) => {
t.same([one, two, three], [1, 2, 3])
return through(() => setTimeout(() => cb(null, 'asdf'), 100))
}
let store = fsStore(testdir, argHasher)
store.set(Buffer.from('asdf'), 1, 2, 3, (err, hash) => {
t.error(err)
})
store.hash(Buffer.from('asdf'), 1, 2, 3, (err, hash) => {
t.error(err)
})
})

let rimraf = require('rimraf')

process.on('beforeExit', () => {
Expand Down
15 changes: 15 additions & 0 deletions tests/test-inmemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ test('inmemory: (implementation) hash error in set()', t => {
t.type(err, 'Error')
})
})

test('inmemory(implementation): hasher args', t => {
t.plan(4)
const argHasher = (one, two, three, cb) => {
t.same([one, two, three], [1, 2, 3])
return through(() => setTimeout(() => cb(null, 'asdf'), 100))
}
let store = inmemory(argHasher)
store.set(Buffer.from('asdf'), 1, 2, 3, (err, hash) => {
t.error(err)
})
store.hash(Buffer.from('asdf'), 1, 2, 3, (err, hash) => {
t.error(err)
})
})

0 comments on commit c37e97e

Please sign in to comment.