-
Notifications
You must be signed in to change notification settings - Fork 17
/
ext_reader_test.go
53 lines (45 loc) · 1012 Bytes
/
ext_reader_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ctlstore_test
import (
"context"
"database/sql"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/segmentio/ctlstore"
)
func TestGetRowByKeyExternalPackage(t *testing.T) {
type testKVStruct struct {
Key string `ctlstore:"key"`
Val string `ctlstore:"value"`
}
const initSQL = `
CREATE TABLE family1___table1 (
key VARCHAR PRIMARY KEY,
value VARCHAR
);
INSERT INTO family1___table1 VALUES('foo', 'bar');
`
ctx := context.Background()
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatalf("Unexpected error %+v", err)
}
_, err = db.Exec(initSQL)
if err != nil {
t.Fatalf("Unexpected error +%v", err)
}
reader := ctlstore.NewLDBReaderFromDB(db)
gotOut := testKVStruct{}
_, gotErr := reader.GetRowByKey(
ctx,
&gotOut,
"family1",
"table1",
"foo",
)
if gotErr != nil {
t.Errorf("Unexpected error %+v", gotErr)
}
if diff := cmp.Diff(gotOut, testKVStruct{"foo", "bar"}); diff != "" {
t.Errorf("GetRowByKey out param mismatch\n%s", diff)
}
}