bbolt/cmd/bolt/main_test.go
Ben Johnson e6b5fdc30e Add import/export to CLI.
This commit adds two new commands:

    bolt import --input INPUT PATH
    bolt export PATH

This exports the database in a simple, nested, key/value JSON document.
Each node in the document has a "key", a "value", and an optional "type".
The key and value fields are both base64 encoded.
2014-04-11 14:05:58 -06:00

38 lines
749 B
Go

package main_test
import (
"io/ioutil"
"os"
"strings"
"github.com/boltdb/bolt"
. "github.com/boltdb/bolt/cmd/bolt"
)
// open creates and opens a Bolt database in the temp directory.
func open(fn func(*bolt.DB, string)) {
path := tempfile()
defer os.RemoveAll(path)
db, err := bolt.Open(path, 0600)
if err != nil {
panic("db open error: " + err.Error())
}
fn(db, path)
}
// run executes a command against the CLI and returns the output.
func run(args ...string) string {
args = append([]string{"bolt"}, args...)
NewApp().Run(args)
return strings.TrimSpace(LogBuffer())
}
// tempfile returns a temporary file path.
func tempfile() string {
f, _ := ioutil.TempFile("", "bolt-")
f.Close()
os.Remove(f.Name())
return f.Name()
}