aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assert.go12
-rw-r--r--bolt.go16
-rw-r--r--cursor.go8
-rw-r--r--db_test.go7
-rw-r--r--quick_test.go1
-rw-r--r--warn.go14
6 files changed, 26 insertions, 32 deletions
diff --git a/assert.go b/assert.go
deleted file mode 100644
index c22b2b0..0000000
--- a/assert.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package bolt
-
-import "fmt"
-
-// TODO(benbjohnson): Remove assertions before release.
-
-// _assert will panic with a given formatted message if the given condition is false.
-func _assert(condition bool, msg string, v ...interface{}) {
- if !condition {
- panic(fmt.Sprintf("assertion failed: "+msg, v...))
- }
-}
diff --git a/bolt.go b/bolt.go
index bb5a2de..f258731 100644
--- a/bolt.go
+++ b/bolt.go
@@ -1,6 +1,7 @@
package bolt
import (
+ "fmt"
"os"
)
@@ -13,3 +14,18 @@ func Open(path string, mode os.FileMode) (*DB, error) {
}
return db, nil
}
+
+// _assert will panic with a given formatted message if the given condition is false.
+func _assert(condition bool, msg string, v ...interface{}) {
+ if !condition {
+ panic(fmt.Sprintf("assertion failed: "+msg, v...))
+ }
+}
+
+func warn(v ...interface{}) {
+ fmt.Fprintln(os.Stderr, v...)
+}
+
+func warnf(msg string, v ...interface{}) {
+ fmt.Fprintf(os.Stderr, msg+"\n", v...)
+}
diff --git a/cursor.go b/cursor.go
index 9a527af..cb0d9a5 100644
--- a/cursor.go
+++ b/cursor.go
@@ -16,9 +16,7 @@ type Cursor struct {
// First moves the cursor to the first item in the bucket and returns its key and value.
// If the bucket is empty then a nil key and value are returned.
func (c *Cursor) First() (key []byte, value []byte) {
- if len(c.stack) > 0 {
- c.stack = c.stack[:0]
- }
+ c.stack = c.stack[:0]
p := c.transaction.page(c.root)
c.stack = append(c.stack, pageElementRef{page: p, index: 0})
c.first()
@@ -28,9 +26,7 @@ func (c *Cursor) First() (key []byte, value []byte) {
// Last moves the cursor to the last item in the bucket and returns its key and value.
// If the bucket is empty then a nil key and value are returned.
func (c *Cursor) Last() (key []byte, value []byte) {
- if len(c.stack) > 0 {
- c.stack = c.stack[:0]
- }
+ c.stack = c.stack[:0]
p := c.transaction.page(c.root)
c.stack = append(c.stack, pageElementRef{page: p, index: p.count - 1})
c.last()
diff --git a/db_test.go b/db_test.go
index 59f8748..2b7975c 100644
--- a/db_test.go
+++ b/db_test.go
@@ -334,6 +334,13 @@ func TestDBMmapSize(t *testing.T) {
assert.Equal(t, db.mmapSize(1<<30), 1<<31)
}
+// Ensure that a database can return a string representation of itself.
+func TestDBString(t *testing.T) {
+ db := &DB{path: "/tmp/foo"}
+ assert.Equal(t, db.String(), `DB<"/tmp/foo">`)
+ assert.Equal(t, db.GoString(), `bolt.DB{path:"/tmp/foo"}`)
+}
+
// withDB executes a function with a database reference.
func withDB(fn func(*DB, string)) {
f, _ := ioutil.TempFile("", "bolt-")
diff --git a/quick_test.go b/quick_test.go
index cda7b30..b083250 100644
--- a/quick_test.go
+++ b/quick_test.go
@@ -29,6 +29,7 @@ func init() {
flag.IntVar(&qmaxvsize, "quick.maxvsize", 1024, "")
flag.Parse()
warn("seed:", qseed)
+ warnf("quick settings: count=%v, items=%v, ksize=%v, vsize=%v", qcount, qmaxitems, qmaxksize, qmaxvsize)
}
func qconfig() *quick.Config {
diff --git a/warn.go b/warn.go
deleted file mode 100644
index eadf664..0000000
--- a/warn.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package bolt
-
-import (
- "fmt"
- "os"
-)
-
-func warn(v ...interface{}) {
- fmt.Fprintln(os.Stderr, v...)
-}
-
-func warnf(msg string, v ...interface{}) {
- fmt.Fprintf(os.Stderr, msg+"\n", v...)
-}