2018-07-21 19:56:40 +00:00
|
|
|
package mbigtable
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"cloud.google.com/go/bigtable"
|
|
|
|
"github.com/mediocregopher/mediocre-go-lib/mrand"
|
2019-02-03 02:57:11 +00:00
|
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest"
|
2018-07-21 19:56:40 +00:00
|
|
|
"github.com/mediocregopher/mediocre-go-lib/mtest/massert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasic(t *T) {
|
2019-02-09 19:08:30 +00:00
|
|
|
ctx := mtest.Context()
|
|
|
|
ctx = mtest.WithEnv(ctx, "BIGTABLE_GCE_PROJECT", "testProject")
|
|
|
|
ctx, bt := WithBigTable(ctx, nil, "testInstance")
|
2019-02-03 02:57:11 +00:00
|
|
|
|
|
|
|
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]
|
2019-03-10 23:23:37 +00:00
|
|
|
massert.Require(t,
|
|
|
|
massert.Length(readColFam, 1),
|
2019-02-03 02:57:11 +00:00
|
|
|
massert.Equal(colFam+":col", readColFam[0].Column),
|
|
|
|
massert.Equal([]byte("bar"), readColFam[0].Value),
|
2019-03-10 23:23:37 +00:00
|
|
|
)
|
2019-02-03 02:57:11 +00:00
|
|
|
})
|
2018-07-21 19:56:40 +00:00
|
|
|
}
|