Updates
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PCrdtMap } = require('../index.js')
|
||||
|
||||
test('crdt-map: set get', async (t) => {
|
||||
const m = new HyperP2PCrdtMap()
|
||||
m.set('k', { v: 1 })
|
||||
t.is(m.get('k').v, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('crdt-map: merge LWW', async (t) => {
|
||||
const a = new HyperP2PCrdtMap()
|
||||
const b = new HyperP2PCrdtMap()
|
||||
a.set('x', 'a')
|
||||
b.merge(a.toJSON())
|
||||
t.is(b.get('x'), 'a')
|
||||
await a.close()
|
||||
await b.close()
|
||||
})
|
||||
test('hyper-p2p-crdt-map: close without leak', async (t) => {
|
||||
const m = new HyperP2PCrdtMap()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
test('hyper-p2p-crdt-map: validation rejects invalid input', async (t) => {
|
||||
const m = new HyperP2PCrdtMap()
|
||||
try {
|
||||
if (typeof m.addNeighbor === 'function') m.addNeighbor(null)
|
||||
else if (typeof m.buildCircuit === 'function') m.buildCircuit([])
|
||||
else if (typeof m.grant === 'function') m.grant(null, -1)
|
||||
else if (typeof m.enqueue === 'function') m.enqueue('bad', null)
|
||||
else if (typeof m.reportSample === 'function') m.reportSample(null, -1, -1)
|
||||
else if (typeof m.fanout === 'function') m.fanout(null, 0)
|
||||
else if (typeof m.probe === 'function') m.probe(null)
|
||||
else if (typeof m.resolve === 'function') m.resolve(null)
|
||||
else if (typeof m.acquire === 'function') m.acquire(null)
|
||||
else throw new Error('no validation hook')
|
||||
t.fail('expected throw')
|
||||
} catch (err) {
|
||||
t.ok(err instanceof Error)
|
||||
}
|
||||
await m.close()
|
||||
})
|
||||
Reference in New Issue
Block a user