-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathintegration_test.go
141 lines (114 loc) · 2.72 KB
/
integration_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// +build integration
package hivething
import (
"reflect"
"testing"
)
/*
Used with local testing: expects hiveserver2 running on 127.0.0.1:10000,
with a single table defined, "foo".
*/
func TestShowTables(t *testing.T) {
var (
ct int = 0
tableName string
)
conn, err := Connect("127.0.0.1:10000", DefaultOptions)
if err != nil {
t.Fatalf("Connect error %v", err)
}
rows, err := conn.Query("SHOW TABLES")
if err != nil {
t.Fatalf("Connection.Query error: %v", err)
}
status, err := rows.Wait()
if err != nil {
t.Fatalf("Connection.Wait error: %v", err)
}
if !status.IsSuccess() {
t.Fatalf("Unsuccessful query execution: %v", status)
}
for rows.Next() {
if ct > 0 {
t.Fatal("Rows.Next should terminate after 1 fetch")
}
rows.Scan(&tableName)
ct++
}
if tableName != "foo" {
t.Errorf("Expected table 'foo' but found %s", tableName)
}
}
func TestQuery(t *testing.T) {
var (
ct int = 0
id int
value string
)
db, err := Connect("127.0.0.1:10000", DefaultOptions)
rows, err := db.Query("select * from foo")
if err != nil {
t.Fatalf("Connect error: %v", err)
}
status, err := rows.Wait()
if !status.IsSuccess() {
t.Fatalf("Unsuccessful query execution: %v", status)
}
col := rows.Columns()
if !reflect.DeepEqual(col, []string{"foo.id", "foo.val"}) {
t.Fatalf("Expected 'id' and 'value' columns, but got %v", col)
}
vals := make([]string, 0)
for rows.Next() {
ct++
rows.Scan(&id, &value)
if id != ct {
t.Errorf("Expected row id to be %d but was %d", ct, id)
}
vals = append(vals, value)
}
if !reflect.DeepEqual(vals, []string{"foo", "bar", "baz"}) {
t.Errorf("Expected 3 row values to be [foo, bar, baz] but was %v", vals)
}
}
func TestReattach(t *testing.T) {
var (
ct int = 0
id int
value string
)
db, err := Connect("127.0.0.1:10000", DefaultOptions)
oldRows, err := db.Query("select * from foo")
if err != nil {
t.Fatalf("Connect error: %v", err)
}
handle, err := oldRows.Handle()
if err != nil {
t.Fatalf("Can't read handle: %v", err)
}
// Reattach.
rows, err := Reattach(db, handle)
if err != nil {
t.Fatalf("Can't reattach: %v", err)
}
status, err := rows.Wait()
if !status.IsSuccess() {
t.Fatalf("Unsuccessful query execution: %v", status)
}
col := rows.Columns()
if !reflect.DeepEqual(col, []string{"foo.id", "foo.val"}) {
t.Fatalf("Expected 'id' and 'value' columns, but got %v", col)
}
vals := make([]string, 0)
for rows.Next() {
ct++
rows.Scan(&id, &value)
if id != ct {
t.Errorf("Expected row id to be %d but was %d", ct, id)
}
vals = append(vals, value)
}
if !reflect.DeepEqual(vals, []string{"foo", "bar", "baz"}) {
t.Errorf("Expected 3 row values to be [foo, bar, baz] but was %v", vals)
}
}