mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-27 16:32:30 +00:00
Make tests use ipfs-daemon instead of test-apis
This commit is contained in:
parent
e67c4cee35
commit
026740faa9
@ -7,43 +7,71 @@ const assert = require('assert')
|
|||||||
const async = require('asyncawait/async')
|
const async = require('asyncawait/async')
|
||||||
const await = require('asyncawait/await')
|
const await = require('asyncawait/await')
|
||||||
const Promise = require('bluebird')
|
const Promise = require('bluebird')
|
||||||
const IpfsApis = require('ipfs-test-apis')
|
// const IpfsApis = require('ipfs-test-apis')
|
||||||
const OrbitDB = require('../src/OrbitDB')
|
const OrbitDB = require('../src/OrbitDB')
|
||||||
|
const rmrf = require('rimraf')
|
||||||
|
const IpfsNodeDaemon = require('ipfs-daemon/src/ipfs-node-daemon')
|
||||||
|
const IpfsNativeDaemon = require('ipfs-daemon/src/ipfs-native-daemon')
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined')
|
||||||
|
window.LOG = 'ERROR'
|
||||||
|
|
||||||
|
// Data directories
|
||||||
|
const defaultIpfsDirectory = './ipfs'
|
||||||
|
const defaultOrbitDBDirectory = './orbit-db'
|
||||||
|
|
||||||
// Orbit
|
// Orbit
|
||||||
const username = 'testrunner'
|
const username = 'testrunner'
|
||||||
|
|
||||||
let ipfs
|
const hasIpfsApiWithPubsub = (ipfs) => {
|
||||||
|
return ipfs.object.get !== undefined
|
||||||
|
&& ipfs.object.put !== undefined
|
||||||
|
&& ipfs.pubsub.publish !== undefined
|
||||||
|
&& ipfs.pubsub.subscribe !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
IpfsApis.forEach(function(ipfsApi) {
|
[IpfsNativeDaemon, IpfsNodeDaemon].forEach((IpfsDaemon) => {
|
||||||
|
// IpfsApis.forEach(function(ipfsApi) {
|
||||||
|
|
||||||
describe('orbit-db client with ' + ipfsApi.name, function() {
|
describe('orbit-db client', function() {
|
||||||
this.timeout(40000)
|
this.timeout(40000)
|
||||||
|
|
||||||
let client, client2, db
|
let ipfs, client, client2, db
|
||||||
let channel = 'abcdefghijklmn'
|
let channel = 'abcdefghijklmn'
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
ipfsApi.start({ IpfsDataDir: '/tmp/orbit-db-tests' })
|
rmrf.sync(defaultIpfsDirectory)
|
||||||
.then((res) => {
|
rmrf.sync(defaultOrbitDBDirectory)
|
||||||
ipfs = res
|
ipfs = new IpfsDaemon()
|
||||||
client = new OrbitDB(ipfs, username)
|
ipfs.on('error', done)
|
||||||
client2 = new OrbitDB(ipfs, username + '2')
|
ipfs.on('ready', () => {
|
||||||
done()
|
assert.equal(hasIpfsApiWithPubsub(ipfs), true)
|
||||||
})
|
client = new OrbitDB(ipfs, username)
|
||||||
.catch(done)
|
client2 = new OrbitDB(ipfs, username + '2')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
// ipfsApi.start({ IpfsDataDir: '/tmp/orbit-db-tests' })
|
||||||
|
// .then((res) => {
|
||||||
|
// ipfs = res
|
||||||
|
// client = new OrbitDB(ipfs, username)
|
||||||
|
// client2 = new OrbitDB(ipfs, username + '2')
|
||||||
|
// done()
|
||||||
|
// })
|
||||||
|
// .catch(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
if(db) db.delete()
|
if(db) db.delete()
|
||||||
if(client) client.disconnect()
|
if(client) client.disconnect()
|
||||||
if(client2) client2.disconnect()
|
if(client2) client2.disconnect()
|
||||||
ipfsApi.stop()
|
ipfs.stop()
|
||||||
|
rmrf.sync(defaultOrbitDBDirectory)
|
||||||
|
rmrf.sync(defaultIpfsDirectory)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Add events', function() {
|
describe('Add events', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
db = client.eventlog(channel, { subscribe: false })
|
db = client.eventlog(channel, { subscribe: false, maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -69,15 +97,12 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
it('adds five items', async(() => {
|
it('adds five items', async(() => {
|
||||||
for(let i = 1; i <= 5; i ++)
|
for(let i = 1; i <= 5; i ++)
|
||||||
await(db.add('hello' + i));
|
await(db.add('hello' + i))
|
||||||
// const items = [1, 2, 3, 4, 5]
|
|
||||||
// return Promise.map(items, (i) => db.add('hello' + i), { concurrency: 1 })
|
const items = db.iterator({ limit: -1 }).collect()
|
||||||
// .then((res) => {
|
assert.equal(items.length, 5)
|
||||||
const items = db.iterator({ limit: -1 }).collect()
|
assert.equal(_.first(items.map((f) => f.payload.value)), 'hello1')
|
||||||
assert.equal(items.length, 5)
|
assert.equal(_.last(items.map((f) => f.payload.value)), 'hello5')
|
||||||
assert.equal(_.first(items.map((f) => f.payload.value)), 'hello1')
|
|
||||||
assert.equal(_.last(items.map((f) => f.payload.value)), 'hello5')
|
|
||||||
// })
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
it('adds an item that is > 256 bytes', () => {
|
it('adds an item that is > 256 bytes', () => {
|
||||||
@ -94,7 +119,7 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
describe('Delete events (Feed)', function() {
|
describe('Delete events (Feed)', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
db = client.feed(channel, { subscribe: false })
|
db = client.feed(channel, { subscribe: false, maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -134,7 +159,7 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
items = []
|
items = []
|
||||||
db = client.eventlog(channel, { subscribe: false })
|
db = client.eventlog(channel, { subscribe: false, maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 0; i < itemCount; i ++) {
|
||||||
const hash = await(db.add('hello' + i))
|
const hash = await(db.add('hello' + i))
|
||||||
@ -437,7 +462,7 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
describe('Key-Value Store', function() {
|
describe('Key-Value Store', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
db = client.kvstore(channel, { subscribe: false })
|
db = client.kvstore(channel, { subscribe: false, maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -527,7 +552,7 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
describe('Document Store - default index \'_id\'', function() {
|
describe('Document Store - default index \'_id\'', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
db = client.docstore(channel, { subscribe: false })
|
db = client.docstore(channel, { subscribe: false, maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -589,7 +614,7 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
|
|
||||||
describe('Document Store - specified index', function() {
|
describe('Document Store - specified index', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
db = client.docstore(channel, { subscribe: false, indexBy: 'doc' })
|
db = client.docstore(channel, { subscribe: false, indexBy: 'doc', maxHistory: 0 })
|
||||||
db.delete()
|
db.delete()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user