4b446a0efc
This change required refactoring nearly every package in this project, but it does a lot to simplify mctx and make other code using it easier to think about. Other code, such as mlog and mcfg, had to be slightly modified for this change to work as well.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package mbigtable
|
|
|
|
import (
|
|
. "testing"
|
|
"time"
|
|
|
|
"cloud.google.com/go/bigtable"
|
|
"github.com/mediocregopher/mediocre-go-lib/mrand"
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest"
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest/massert"
|
|
)
|
|
|
|
func TestBasic(t *T) {
|
|
ctx := mtest.NewCtx()
|
|
ctx = mtest.SetEnv(ctx, "GCE_PROJECT", "testProject")
|
|
ctx, bt := MNew(ctx, nil, "testInstance")
|
|
|
|
mtest.Run(ctx, t, func() {
|
|
tableName := "test-" + mrand.Hex(8)
|
|
colFam := "colFam-" + mrand.Hex(8)
|
|
if err := bt.EnsureTable(ctx, tableName, colFam); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
table := bt.Table(tableName)
|
|
row := "row-" + mrand.Hex(8)
|
|
mut := bigtable.NewMutation()
|
|
mut.Set(colFam, "col", bigtable.Time(time.Now()), []byte("bar"))
|
|
if err := table.Apply(ctx, row, mut); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
readRow, err := table.ReadRow(ctx, row)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
readColFam := readRow[colFam]
|
|
massert.Fatal(t, massert.All(
|
|
massert.Len(readColFam, 1),
|
|
massert.Equal(colFam+":col", readColFam[0].Column),
|
|
massert.Equal([]byte("bar"), readColFam[0].Value),
|
|
))
|
|
})
|
|
}
|