Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing path as input opt #13

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ piet.publish({type: 'test', content: "a test message"}, (err, msg) => {

Outputs:
```
{
{
key: '%FQ2auS8kVY9qPgpTWNY3le/JG5+IlO6JHDjBIQcSPSc=.sha256',
value: {
value: {
previous: null,
sequence: 1,
author: '@UreG2i/rf4mz7QAVOtg0OML5SRRB42Cwwl3D1ct0mbU=.ed25519',
timestamp: 1517190039755,
hash: 'sha256',
content: { type: 'test', content: 'a test message' },
signature: '0AxMJ7cKjHQ6vJDPkVNWcGND4gUwv2Z8barND5eha7ZXH/s5T0trFqcratIqzmhE3YJU2FY61Rf1S/Za2foLCA==.sig.ed25519'
signature: '0AxMJ7cKjHQ6vJDPkVNWcGND4gUwv2Z8barND5eha7ZXH/s5T0trFqcratIqzmhE3YJU2FY61Rf1S/Za2foLCA==.sig.ed25519'
},
timestamp: 1517190039758
timestamp: 1517190039758
}
```

Expand All @@ -47,7 +47,8 @@ By default, CreateTestSbot deletes an existing database of the same `name` befor

Valid `opts` keys include:
- `name` *String* (optional) (default: `ssb-test + Number(new Date)`)
- `myTestName`: Sets the database in /tmp/myTestName
- `path` *String* (optional) (default: `/tmp/${name}`, where `name` is the above)
- `~/.ssb-test`: Sets the database in `~/.ssb-test`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the working location for the identity - log databases, secret, conn.json etc

Wonder if there's an easy word for that.
Anyway not a big deal

- `keys` *String* (optional) (default: scuttle-testbot generates a new set of random keys)
- you can create your own keys with `ssbKeys.generate()`
- `startUnclean` (default: `false`)
Expand Down
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ function createTestBot (opts = {}) {
if (!opts.name) {
opts.name = `ssb-test-${Date.now()}-${Math.floor(Math.random() * 1000)}`
}
const folderPath = join('/tmp', opts.name)
if (!opts.startUnclean) { rimraf.sync(folderPath) }
if (!opts.path) {
opts.path = join(os.tmpdir(), opts.name)
}
if (!opts.startUnclean) { rimraf.sync(opts.path) }
if (!opts.keys) { opts.keys = ssbKeys.generate() }

const caps = {
Expand All @@ -28,10 +30,7 @@ function createTestBot (opts = {}) {
plugins.forEach(plugin => createSbot.use(plugin))
plugins = []

return createSbot({
...opts,
path: join(os.tmpdir(), opts.name)
})
return createSbot(opts)
}

createTestBot.use = function use (plugin) {
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var test = require('tape')
var fs = require('fs')
var CreateTestSbot = require('../')

test('creates an sbot', function (t) {
Expand Down Expand Up @@ -59,3 +60,16 @@ test('persist database across instances', (t) => {
})
})
})

test('allows specifying the path to the db', (t) => {
const a = CreateTestSbot({ path: '/tmp/overhere/scuttle-testbot' })

a.publish({ type: 'test' }, (err, val) => {
t.error(err, 'no error on publish')
a.close((err) => {
t.error(err, 'no error on close')
t.true(fs.existsSync('/tmp/overhere/scuttle-testbot/conn.json'))
t.end()
})
})
})