aboutsummaryrefslogtreecommitdiff
path: root/cmd/bolt/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/bolt/main_test.go')
-rw-r--r--cmd/bolt/main_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd/bolt/main_test.go b/cmd/bolt/main_test.go
index 5c70c97..95b4df5 100644
--- a/cmd/bolt/main_test.go
+++ b/cmd/bolt/main_test.go
@@ -53,6 +53,38 @@ func TestGetKeyNotFound(t *testing.T) {
})
}
+// Ensure that a list of keys can be retrieved for a given bucket.
+func TestKeys(t *testing.T) {
+ SetTestMode(true)
+ open(func(db *bolt.DB) {
+ db.Do(func(tx *bolt.Tx) error {
+ tx.CreateBucket("widgets")
+ tx.Bucket("widgets").Put([]byte("0002"), []byte(""))
+ tx.Bucket("widgets").Put([]byte("0001"), []byte(""))
+ tx.Bucket("widgets").Put([]byte("0003"), []byte(""))
+ return nil
+ })
+ output := run("keys", db.Path(), "widgets")
+ assert.Equal(t, "0001\n0002\n0003", output)
+ })
+}
+
+// Ensure that an error is reported if the database is not found.
+func TestKeysDBNotFound(t *testing.T) {
+ SetTestMode(true)
+ output := run("keys", "no/such/db", "widgets")
+ assert.Equal(t, "stat no/such/db: no such file or directory", output)
+}
+
+// Ensure that an error is reported if the bucket is not found.
+func TestKeysBucketNotFound(t *testing.T) {
+ SetTestMode(true)
+ open(func(db *bolt.DB) {
+ output := run("keys", db.Path(), "widgets")
+ assert.Equal(t, "bucket not found: widgets", output)
+ })
+}
+
// open creates and opens a Bolt database in the temp directory.
func open(fn func(*bolt.DB)) {
f, _ := ioutil.TempFile("", "bolt-")