mirror of https://github.com/hak5/bolt.git
*: fix test print format
parent
25b28102db
commit
42ab7c097f
112
bucket_test.go
112
bucket_test.go
|
@ -456,10 +456,10 @@ func TestBucket_Nested(t *testing.T) {
|
|||
if err := db.View(func(tx *bolt.Tx) error {
|
||||
var b = tx.Bucket([]byte("widgets"))
|
||||
if v := b.Bucket([]byte("foo")).Get([]byte("baz")); !bytes.Equal(v, []byte("yyyy")) {
|
||||
t.Fatalf("unexpected value: %v")
|
||||
t.Fatalf("unexpected value: %v", v)
|
||||
}
|
||||
if !bytes.Equal(b.Get([]byte("bar")), []byte("xxxx")) {
|
||||
t.Fatalf("unexpected value: %v")
|
||||
if v := b.Get([]byte("bar")); !bytes.Equal(v, []byte("xxxx")) {
|
||||
t.Fatalf("unexpected value: %v", v)
|
||||
}
|
||||
for i := 0; i < 10000; i++ {
|
||||
if v := b.Get([]byte(strconv.Itoa(i))); !bytes.Equal(v, []byte(strconv.Itoa(i))) {
|
||||
|
@ -1118,18 +1118,18 @@ func TestBucket_Stats(t *testing.T) {
|
|||
// Only check allocations for 4KB pages.
|
||||
if os.Getpagesize() == 4096 {
|
||||
if stats.BranchAlloc != 4096 {
|
||||
t.Fatalf("unexpected BranchAlloc:", stats.BranchAlloc)
|
||||
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
|
||||
} else if stats.LeafAlloc != 36864 {
|
||||
t.Fatalf("unexpected LeafAlloc:", stats.LeafAlloc)
|
||||
t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc)
|
||||
}
|
||||
}
|
||||
|
||||
if stats.BucketN != 1 {
|
||||
t.Fatalf("unexpected BucketN:", stats.BucketN)
|
||||
t.Fatalf("unexpected BucketN: %d", stats.BucketN)
|
||||
} else if stats.InlineBucketN != 0 {
|
||||
t.Fatalf("unexpected InlineBucketN:", stats.InlineBucketN)
|
||||
t.Fatalf("unexpected InlineBucketN: %d", stats.InlineBucketN)
|
||||
} else if stats.InlineBucketInuse != 0 {
|
||||
t.Fatalf("unexpected InlineBucketInuse:", stats.InlineBucketInuse)
|
||||
t.Fatalf("unexpected InlineBucketInuse: %d", stats.InlineBucketInuse)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1178,27 +1178,27 @@ func TestBucket_Stats_RandomFill(t *testing.T) {
|
|||
if err := db.View(func(tx *bolt.Tx) error {
|
||||
stats := tx.Bucket([]byte("woojits")).Stats()
|
||||
if stats.KeyN != 100000 {
|
||||
t.Fatalf("unexpected KeyN", stats.KeyN)
|
||||
t.Fatalf("unexpected KeyN: %d", stats.KeyN)
|
||||
}
|
||||
|
||||
if stats.BranchPageN != 98 {
|
||||
t.Fatalf("unexpected BranchPageN", stats.BranchPageN)
|
||||
t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN)
|
||||
} else if stats.BranchOverflowN != 0 {
|
||||
t.Fatalf("unexpected BranchOverflowN", stats.BranchOverflowN)
|
||||
t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN)
|
||||
} else if stats.BranchInuse != 130984 {
|
||||
t.Fatalf("unexpected BranchInuse", stats.BranchInuse)
|
||||
t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse)
|
||||
} else if stats.BranchAlloc != 401408 {
|
||||
t.Fatalf("unexpected BranchAlloc", stats.BranchAlloc)
|
||||
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
|
||||
}
|
||||
|
||||
if stats.LeafPageN != 3412 {
|
||||
t.Fatalf("unexpected LeafPageN", stats.LeafPageN)
|
||||
t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN)
|
||||
} else if stats.LeafOverflowN != 0 {
|
||||
t.Fatalf("unexpected LeafOverflowN", stats.LeafOverflowN)
|
||||
t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN)
|
||||
} else if stats.LeafInuse != 4742482 {
|
||||
t.Fatalf("unexpected LeafInuse", stats.LeafInuse)
|
||||
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
|
||||
} else if stats.LeafAlloc != 13975552 {
|
||||
t.Fatalf("unexpected LeafAlloc", stats.LeafAlloc)
|
||||
t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
@ -1232,37 +1232,37 @@ func TestBucket_Stats_Small(t *testing.T) {
|
|||
b := tx.Bucket([]byte("whozawhats"))
|
||||
stats := b.Stats()
|
||||
if stats.BranchPageN != 0 {
|
||||
t.Fatalf("unexpected BranchPageN: ", stats.BranchPageN)
|
||||
t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN)
|
||||
} else if stats.BranchOverflowN != 0 {
|
||||
t.Fatalf("unexpected BranchOverflowN: ", stats.BranchOverflowN)
|
||||
t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN)
|
||||
} else if stats.LeafPageN != 0 {
|
||||
t.Fatalf("unexpected LeafPageN: ", stats.LeafPageN)
|
||||
t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN)
|
||||
} else if stats.LeafOverflowN != 0 {
|
||||
t.Fatalf("unexpected LeafOverflowN: ", stats.LeafOverflowN)
|
||||
t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN)
|
||||
} else if stats.KeyN != 1 {
|
||||
t.Fatalf("unexpected KeyN: ", stats.KeyN)
|
||||
t.Fatalf("unexpected KeyN: %d", stats.KeyN)
|
||||
} else if stats.Depth != 1 {
|
||||
t.Fatalf("unexpected Depth: ", stats.Depth)
|
||||
t.Fatalf("unexpected Depth: %d", stats.Depth)
|
||||
} else if stats.BranchInuse != 0 {
|
||||
t.Fatalf("unexpected BranchInuse: ", stats.BranchInuse)
|
||||
t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse)
|
||||
} else if stats.LeafInuse != 0 {
|
||||
t.Fatalf("unexpected LeafInuse: ", stats.LeafInuse)
|
||||
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
|
||||
}
|
||||
|
||||
if os.Getpagesize() == 4096 {
|
||||
if stats.BranchAlloc != 0 {
|
||||
t.Fatalf("unexpected BranchAlloc: ", stats.BranchAlloc)
|
||||
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
|
||||
} else if stats.LeafAlloc != 0 {
|
||||
t.Fatalf("unexpected LeafAlloc: ", stats.LeafAlloc)
|
||||
t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc)
|
||||
}
|
||||
}
|
||||
|
||||
if stats.BucketN != 1 {
|
||||
t.Fatalf("unexpected BucketN: ", stats.BucketN)
|
||||
t.Fatalf("unexpected BucketN: %d", stats.BucketN)
|
||||
} else if stats.InlineBucketN != 1 {
|
||||
t.Fatalf("unexpected InlineBucketN: ", stats.InlineBucketN)
|
||||
t.Fatalf("unexpected InlineBucketN: %d", stats.InlineBucketN)
|
||||
} else if stats.InlineBucketInuse != 16+16+6 {
|
||||
t.Fatalf("unexpected InlineBucketInuse: ", stats.InlineBucketInuse)
|
||||
t.Fatalf("unexpected InlineBucketInuse: %d", stats.InlineBucketInuse)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1291,37 +1291,37 @@ func TestBucket_Stats_EmptyBucket(t *testing.T) {
|
|||
b := tx.Bucket([]byte("whozawhats"))
|
||||
stats := b.Stats()
|
||||
if stats.BranchPageN != 0 {
|
||||
t.Fatalf("unexpected BranchPageN: ", stats.BranchPageN)
|
||||
t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN)
|
||||
} else if stats.BranchOverflowN != 0 {
|
||||
t.Fatalf("unexpected BranchOverflowN: ", stats.BranchOverflowN)
|
||||
t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN)
|
||||
} else if stats.LeafPageN != 0 {
|
||||
t.Fatalf("unexpected LeafPageN: ", stats.LeafPageN)
|
||||
t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN)
|
||||
} else if stats.LeafOverflowN != 0 {
|
||||
t.Fatalf("unexpected LeafOverflowN: ", stats.LeafOverflowN)
|
||||
t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN)
|
||||
} else if stats.KeyN != 0 {
|
||||
t.Fatalf("unexpected KeyN: ", stats.KeyN)
|
||||
t.Fatalf("unexpected KeyN: %d", stats.KeyN)
|
||||
} else if stats.Depth != 1 {
|
||||
t.Fatalf("unexpected Depth: ", stats.Depth)
|
||||
t.Fatalf("unexpected Depth: %d", stats.Depth)
|
||||
} else if stats.BranchInuse != 0 {
|
||||
t.Fatalf("unexpected BranchInuse: ", stats.BranchInuse)
|
||||
t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse)
|
||||
} else if stats.LeafInuse != 0 {
|
||||
t.Fatalf("unexpected LeafInuse: ", stats.LeafInuse)
|
||||
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
|
||||
}
|
||||
|
||||
if os.Getpagesize() == 4096 {
|
||||
if stats.BranchAlloc != 0 {
|
||||
t.Fatalf("unexpected BranchAlloc: ", stats.BranchAlloc)
|
||||
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
|
||||
} else if stats.LeafAlloc != 0 {
|
||||
t.Fatalf("unexpected LeafAlloc: ", stats.LeafAlloc)
|
||||
t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc)
|
||||
}
|
||||
}
|
||||
|
||||
if stats.BucketN != 1 {
|
||||
t.Fatalf("unexpected BucketN: ", stats.BucketN)
|
||||
t.Fatalf("unexpected BucketN: %d", stats.BucketN)
|
||||
} else if stats.InlineBucketN != 1 {
|
||||
t.Fatalf("unexpected InlineBucketN: ", stats.InlineBucketN)
|
||||
t.Fatalf("unexpected InlineBucketN: %d", stats.InlineBucketN)
|
||||
} else if stats.InlineBucketInuse != 16 {
|
||||
t.Fatalf("unexpected InlineBucketInuse: ", stats.InlineBucketInuse)
|
||||
t.Fatalf("unexpected InlineBucketInuse: %d", stats.InlineBucketInuse)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1377,19 +1377,19 @@ func TestBucket_Stats_Nested(t *testing.T) {
|
|||
b := tx.Bucket([]byte("foo"))
|
||||
stats := b.Stats()
|
||||
if stats.BranchPageN != 0 {
|
||||
t.Fatalf("unexpected BranchPageN: ", stats.BranchPageN)
|
||||
t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN)
|
||||
} else if stats.BranchOverflowN != 0 {
|
||||
t.Fatalf("unexpected BranchOverflowN: ", stats.BranchOverflowN)
|
||||
t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN)
|
||||
} else if stats.LeafPageN != 2 {
|
||||
t.Fatalf("unexpected LeafPageN: ", stats.LeafPageN)
|
||||
t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN)
|
||||
} else if stats.LeafOverflowN != 0 {
|
||||
t.Fatalf("unexpected LeafOverflowN: ", stats.LeafOverflowN)
|
||||
t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN)
|
||||
} else if stats.KeyN != 122 {
|
||||
t.Fatalf("unexpected KeyN: ", stats.KeyN)
|
||||
t.Fatalf("unexpected KeyN: %d", stats.KeyN)
|
||||
} else if stats.Depth != 3 {
|
||||
t.Fatalf("unexpected Depth: ", stats.Depth)
|
||||
t.Fatalf("unexpected Depth: %d", stats.Depth)
|
||||
} else if stats.BranchInuse != 0 {
|
||||
t.Fatalf("unexpected BranchInuse: ", stats.BranchInuse)
|
||||
t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse)
|
||||
}
|
||||
|
||||
foo := 16 // foo (pghdr)
|
||||
|
@ -1407,23 +1407,23 @@ func TestBucket_Stats_Nested(t *testing.T) {
|
|||
baz += 10 + 10 // baz leaf key/values
|
||||
|
||||
if stats.LeafInuse != foo+bar+baz {
|
||||
t.Fatalf("unexpected LeafInuse: ", stats.LeafInuse)
|
||||
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
|
||||
}
|
||||
|
||||
if os.Getpagesize() == 4096 {
|
||||
if stats.BranchAlloc != 0 {
|
||||
t.Fatalf("unexpected BranchAlloc: ", stats.BranchAlloc)
|
||||
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
|
||||
} else if stats.LeafAlloc != 8192 {
|
||||
t.Fatalf("unexpected LeafAlloc: ", stats.LeafAlloc)
|
||||
t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc)
|
||||
}
|
||||
}
|
||||
|
||||
if stats.BucketN != 3 {
|
||||
t.Fatalf("unexpected BucketN: ", stats.BucketN)
|
||||
t.Fatalf("unexpected BucketN: %d", stats.BucketN)
|
||||
} else if stats.InlineBucketN != 1 {
|
||||
t.Fatalf("unexpected InlineBucketN: ", stats.InlineBucketN)
|
||||
t.Fatalf("unexpected InlineBucketN: %d", stats.InlineBucketN)
|
||||
} else if stats.InlineBucketInuse != baz {
|
||||
t.Fatalf("unexpected InlineBucketInuse: ", stats.InlineBucketInuse)
|
||||
t.Fatalf("unexpected InlineBucketInuse: %d", stats.InlineBucketInuse)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -904,11 +904,11 @@ func TestDB_Stats(t *testing.T) {
|
|||
|
||||
stats := db.Stats()
|
||||
if stats.TxStats.PageCount != 2 {
|
||||
t.Fatalf("unexpected TxStats.PageCount", stats.TxStats.PageCount)
|
||||
t.Fatalf("unexpected TxStats.PageCount: %d", stats.TxStats.PageCount)
|
||||
} else if stats.FreePageN != 0 {
|
||||
t.Fatalf("unexpected FreePageN != 0", stats.FreePageN)
|
||||
t.Fatalf("unexpected FreePageN != 0: %d", stats.FreePageN)
|
||||
} else if stats.PendingPageN != 2 {
|
||||
t.Fatalf("unexpected PendingPageN != 2", stats.PendingPageN)
|
||||
t.Fatalf("unexpected PendingPageN != 2: %d", stats.PendingPageN)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -571,7 +571,7 @@ func TestTx_CopyFile_Error_Meta(t *testing.T) {
|
|||
if err := db.View(func(tx *bolt.Tx) error {
|
||||
return tx.Copy(&failWriter{})
|
||||
}); err == nil || err.Error() != "meta copy: error injected for tests" {
|
||||
t.Fatal("unexpected error: %s", err)
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,7 @@ func TestTx_CopyFile_Error_Normal(t *testing.T) {
|
|||
if err := db.View(func(tx *bolt.Tx) error {
|
||||
return tx.Copy(&failWriter{3 * db.Info().PageSize})
|
||||
}); err == nil || err.Error() != "error injected for tests" {
|
||||
t.Fatal("unexpected error: %s", err)
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue