mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-26 16:02:29 +00:00
Add tests for dropping databases
This commit is contained in:
parent
e6e72fee9e
commit
e338f4039a
@ -1,60 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import fs from 'fs'
|
||||
// import path from 'path'
|
||||
// import rmrf from 'rimraf'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs,
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const dbPath = './orbitdb/tests/drop'
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// describe(`orbit-db - Drop Database (${API})`, function() {
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// let ipfsd, ipfs, orbitdb, db, address
|
||||
// let localDataPath
|
||||
|
||||
// before(async () => {
|
||||
// rmrf.sync(dbPath)
|
||||
// ipfsd = await startIpfs(API, config.daemon1)
|
||||
// ipfs = ipfsd.api
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if(orbitdb)
|
||||
// await orbitdb.stop()
|
||||
|
||||
// if (ipfsd)
|
||||
// await stopIpfs(ipfsd)
|
||||
|
||||
// rmrf.sync(dbPath)
|
||||
// })
|
||||
|
||||
// describe('Drop', function() {
|
||||
// before(async () => {
|
||||
// db = await orbitdb.create('first', 'feed')
|
||||
// localDataPath = path.join(dbPath)
|
||||
// assert.equal(fs.existsSync(localDataPath), true)
|
||||
// })
|
||||
|
||||
// it('removes local database cache', async () => {
|
||||
// await db.drop()
|
||||
// await db._cache.open()
|
||||
// assert.equal(await db._cache.get(db.localHeadsPath), undefined)
|
||||
// assert.equal(await db._cache.get(db.remoteHeadsPath), undefined)
|
||||
// assert.equal(await db._cache.get(db.snapshotPath), undefined)
|
||||
// assert.equal(await db._cache.get(db.queuePath), undefined)
|
||||
// assert.equal(await db._cache.get(db.manifestPath), undefined)
|
||||
// await db._cache.close()
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
117
test/orbitdb-drop.test.js
Normal file
117
test/orbitdb-drop.test.js
Normal file
@ -0,0 +1,117 @@
|
||||
import { strictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs'
|
||||
import { OrbitDB } from '../src/index.js'
|
||||
import config from './config.js'
|
||||
|
||||
describe('Drop databases', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let ipfs
|
||||
let orbitdb1
|
||||
let db
|
||||
|
||||
before(async () => {
|
||||
ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (ipfs) {
|
||||
await ipfs.stop()
|
||||
}
|
||||
await rmrf('./orbitdb')
|
||||
await rmrf('./ipfs')
|
||||
})
|
||||
|
||||
describe('dropping a database', () => {
|
||||
const amount = 10
|
||||
|
||||
before(async () => {
|
||||
orbitdb1 = await OrbitDB({ ipfs, id: 'user1' })
|
||||
db = await orbitdb1.open('helloworld')
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (db) {
|
||||
await db.close()
|
||||
}
|
||||
if (orbitdb1) {
|
||||
await orbitdb1.stop()
|
||||
}
|
||||
await rmrf('./orbitdb')
|
||||
})
|
||||
|
||||
it('returns no entries in the database after dropping it', async () => {
|
||||
for (let i = 0; i < amount; i++) {
|
||||
await db.add('hello' + i)
|
||||
}
|
||||
|
||||
const before = await db.all()
|
||||
strictEqual(before.length, amount)
|
||||
|
||||
await db.drop()
|
||||
|
||||
const after = await db.all()
|
||||
strictEqual(after.length, 0)
|
||||
})
|
||||
|
||||
it('returns no heads for the database oplog after dropping it', async () => {
|
||||
for (let i = 0; i < amount; i++) {
|
||||
await db.add('hello' + i)
|
||||
}
|
||||
|
||||
const before = await db.log.heads()
|
||||
strictEqual(before.length, 1)
|
||||
|
||||
await db.drop()
|
||||
|
||||
const after = await db.log.heads()
|
||||
strictEqual(after.length, 0)
|
||||
})
|
||||
|
||||
it('returns no entries when a dropped database is opened again after closing', async () => {
|
||||
for (let i = 0; i < amount; i++) {
|
||||
await db.add('hello' + i)
|
||||
}
|
||||
|
||||
const before = await db.all()
|
||||
strictEqual(before.length, amount)
|
||||
|
||||
await db.drop()
|
||||
await db.close()
|
||||
|
||||
db = await orbitdb1.open('helloworld')
|
||||
|
||||
const after = await db.all()
|
||||
strictEqual(after.length, 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('dropping an empty database', () => {
|
||||
before(async () => {
|
||||
orbitdb1 = await OrbitDB({ ipfs, id: 'user1' })
|
||||
db = await orbitdb1.open('helloworld')
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (db) {
|
||||
await db.drop()
|
||||
await db.close()
|
||||
}
|
||||
if (orbitdb1) {
|
||||
await orbitdb1.stop()
|
||||
}
|
||||
await rmrf('./orbitdb1')
|
||||
})
|
||||
|
||||
it('doesn\'t error when dropping an empty database', async () => {
|
||||
let err
|
||||
try {
|
||||
await db.drop()
|
||||
} catch (e) {
|
||||
err = e
|
||||
}
|
||||
strictEqual(err, undefined)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user