mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Merge pull request #726 from orbitdb/feat/offline-mode
Add offline mode
This commit is contained in:
78
test/offline-mode.js
Normal file
78
test/offline-mode.js
Normal file
@@ -0,0 +1,78 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const assert = require('assert')
|
||||
const mapSeries = require('p-map-series')
|
||||
const rmrf = require('rimraf')
|
||||
const IPFS = require('ipfs')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const Identities = require('orbit-db-identity-provider')
|
||||
const Keystore = require('orbit-db-keystore')
|
||||
const leveldown = require('leveldown')
|
||||
const storage = require('orbit-db-storage-adapter')(leveldown)
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/offline/db1'
|
||||
const dbPath2 = './orbitdb/tests/offline/db2'
|
||||
const ipfsPath = './orbitdb/tests/offline/ipfs'
|
||||
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Offline mode (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2, orbitdb, db, keystore
|
||||
let identity1, identity2
|
||||
let localDataPath
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = path.join(ipfsPath, '/1')
|
||||
config.daemon2.repo = path.join(ipfsPath, '/2')
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(config.daemon2.repo)
|
||||
rmrf.sync(path.join(ipfsPath, '/2'))
|
||||
rmrf.sync('./orbitdb/tests/offline')
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if(orbitdb)
|
||||
await orbitdb.stop()
|
||||
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
if (ipfsd2)
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
it('starts in offline mode', async () => {
|
||||
orbitdb = await OrbitDB.createInstance(ipfs1, { offline: true, directory: dbPath1 })
|
||||
assert.equal(orbitdb._pubsub, null)
|
||||
await orbitdb.stop()
|
||||
})
|
||||
|
||||
it('does not start in offline mode', async () => {
|
||||
orbitdb = await OrbitDB.createInstance(ipfs1, { offline: false, directory: dbPath1 })
|
||||
assert.notEqual(orbitdb._pubsub, null)
|
||||
await orbitdb.stop()
|
||||
})
|
||||
|
||||
it('does not start in offline mode - default', async () => {
|
||||
orbitdb = await OrbitDB.createInstance(ipfs1, { directory: dbPath1 })
|
||||
assert.notEqual(orbitdb._pubsub, null)
|
||||
await orbitdb.stop()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user