forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple_test.go
79 lines (63 loc) · 1.57 KB
/
tuple_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// +build all integration
package gocql
import "testing"
func TestTupleSimple(t *testing.T) {
if *flagProto < protoVersion3 {
t.Skip("tuple types are only available of proto>=3")
}
session := createSession(t)
defer session.Close()
err := createTable(session, `CREATE TABLE gocql_test.tuple_test(
id int,
coord frozen<tuple<int, int>>,
primary key(id))`)
if err != nil {
t.Fatal(err)
}
err = session.Query("INSERT INTO tuple_test(id, coord) VALUES(?, (?, ?))", 1, 100, -100).Exec()
if err != nil {
t.Fatal(err)
}
var (
id int
coord struct {
x int
y int
}
)
iter := session.Query("SELECT id, coord FROM tuple_test WHERE id=?", 1)
if err := iter.Scan(&id, &coord.x, &coord.y); err != nil {
t.Fatal(err)
}
if id != 1 {
t.Errorf("expected to get id=1 got: %v", id)
}
if coord.x != 100 {
t.Errorf("expected to get coord.x=100 got: %v", coord.x)
}
if coord.y != -100 {
t.Errorf("expected to get coord.y=-100 got: %v", coord.y)
}
}
func TestTupleMapScan(t *testing.T) {
if *flagProto < protoVersion3 {
t.Skip("tuple types are only available of proto>=3")
}
session := createSession(t)
defer session.Close()
err := createTable(session, `CREATE TABLE gocql_test.tuple_map_scan(
id int,
val frozen<tuple<int, int>>,
primary key(id))`)
if err != nil {
t.Fatal(err)
}
if err := session.Query(`INSERT INTO tuple_map_scan (id, val) VALUES (1, (1, 2));`).Exec(); err != nil {
t.Fatal(err)
}
m := make(map[string]interface{})
err = session.Query(`SELECT * FROM tuple_map_scan`).MapScan(m)
if err != nil {
t.Fatal(err)
}
}