forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple_test.go
51 lines (41 loc) · 979 Bytes
/
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
// +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 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)
}
}