mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
don't dump stuff to stdout for tests
We have some tests that cover stuff like the DumpDot functionality, but we don't need them to actually write to stdout during ordinary testing. Dump to buffers which we politely ignore. Yes, we could have used a dummy writer, but this way it's super easy to display the contents if we find ourselves suddenly caring.
This commit is contained in:
parent
3ced081271
commit
7dd7557e21
2 changed files with 32 additions and 24 deletions
|
|
@ -2,6 +2,7 @@
|
|||
package rbf_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
|
|
@ -852,8 +853,10 @@ func TestDumpDot(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rbf.Dumpdot(tx, 0, " ", os.Stdout)
|
||||
var b bytes.Buffer
|
||||
rbf.Dumpdot(tx, 0, " ", &b)
|
||||
}
|
||||
|
||||
func TestCursor_UpdateBranchCells(t *testing.T) {
|
||||
db := MustOpenDB(t)
|
||||
defer MustCloseDB(t, db)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
package rbf_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
|
@ -742,7 +743,11 @@ func TestTx_DeleteBitmapsWithPrefix(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
checkInfos := func() {
|
||||
var b bytes.Buffer
|
||||
pBuf := func(msg string, args ...interface{}) (int, error) {
|
||||
return fmt.Fprintf(&b, msg, args...)
|
||||
}
|
||||
checkInfos := func(pf func(string, ...interface{}) (int, error)) {
|
||||
tx := MustBegin(t, db, false)
|
||||
defer tx.Rollback()
|
||||
infos, err := tx.PageInfos()
|
||||
|
|
@ -750,34 +755,34 @@ func TestTx_DeleteBitmapsWithPrefix(t *testing.T) {
|
|||
for pgno, info := range infos {
|
||||
switch info := info.(type) {
|
||||
case *rbf.MetaPageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "meta")
|
||||
fmt.Printf("pageN=%d,walid=%d,rootrec=%d,freelist=%d\n", info.PageN, info.WALID, info.RootRecordPageNo, info.FreelistPageNo)
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "meta")
|
||||
pf("pageN=%d,walid=%d,rootrec=%d,freelist=%d\n", info.PageN, info.WALID, info.RootRecordPageNo, info.FreelistPageNo)
|
||||
|
||||
case *rbf.RootRecordPageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "rootrec")
|
||||
fmt.Printf("next=%d\n", info.Next)
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "rootrec")
|
||||
pf("next=%d\n", info.Next)
|
||||
|
||||
case *rbf.LeafPageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "leaf")
|
||||
fmt.Printf("flags=x%x,celln=%d\n", info.Flags, info.CellN)
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "leaf")
|
||||
pf("flags=x%x,celln=%d\n", info.Flags, info.CellN)
|
||||
|
||||
case *rbf.BranchPageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "branch")
|
||||
fmt.Printf("flags=x%x,celln=%d\n", info.Flags, info.CellN)
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "branch")
|
||||
pf("flags=x%x,celln=%d\n", info.Flags, info.CellN)
|
||||
|
||||
case *rbf.BitmapPageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "bitmap")
|
||||
fmt.Printf("-\n")
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "bitmap")
|
||||
pf("-\n")
|
||||
|
||||
case *rbf.FreePageInfo:
|
||||
fmt.Printf("%-8d ", pgno)
|
||||
fmt.Printf("%-10s ", "free")
|
||||
fmt.Printf("-\n")
|
||||
pf("%-8d ", pgno)
|
||||
pf("%-10s ", "free")
|
||||
pf("-\n")
|
||||
|
||||
default:
|
||||
t.Fatal(fmt.Sprintf("unexpected page info type %T", info))
|
||||
|
|
@ -806,19 +811,19 @@ func TestTx_DeleteBitmapsWithPrefix(t *testing.T) {
|
|||
ifError(tx.Commit())
|
||||
}
|
||||
|
||||
checkInfos()
|
||||
checkInfos(pBuf)
|
||||
populate()
|
||||
checkInfos()
|
||||
checkInfos(pBuf)
|
||||
ifError(db.Check())
|
||||
|
||||
tx := MustBegin(t, db, true)
|
||||
tx.DeleteBitmapsWithPrefix(prefix)
|
||||
ifError(tx.Commit())
|
||||
ifError(db.Check())
|
||||
checkInfos()
|
||||
checkInfos(pBuf)
|
||||
populate()
|
||||
ifError(db.Check())
|
||||
checkInfos()
|
||||
checkInfos(pBuf)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue