-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrows_test.go
73 lines (60 loc) · 3.08 KB
/
rows_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
package fireboltgosdk
import (
"database/sql/driver"
"encoding/json"
"io"
"reflect"
"testing"
)
func assert(val bool, t *testing.T, err string) {
if !val {
t.Errorf(err)
}
}
func mockRows() driver.Rows {
resultJson := "{\"query\":{\"query_id\":\"16FF2A0300ECA753\"},\"meta\":[{\"name\":\"int_col\",\"type\":\"Int32\"},{\"name\":\"bigint_col\",\"type\":\"Int64\"},{\"name\":\"float_col\",\"type\":\"Float32\"},{\"name\":\"double_col\",\"type\":\"Float64\"},{\"name\":\"text_col\",\"type\":\"String\"},{\"name\":\"date_col\",\"type\":\"Date\"},{\"name\":\"timestamp_col\",\"type\":\"DateTime\"},{\"name\":\"bool_col\",\"type\":\"UInt8\"},{\"name\":\"array_col\",\"type\":\"Array(Int32)\"},{\"name\":\"nested_array_col\",\"type\":\"Array(Array(String))\"}],\"data\":[[2,1,0.312321,123213.321321,\"text\",\"1970-01-01\",\"1970-01-01 00:00:00\",1,[1,2,3],[[]]],[2,1,0.312321,123213.321321,\"text\",\"1970-01-01\",\"1970-01-01 00:00:00\",1,[1,2,3],[[]]],[3,5,0.312321,123213.321321,\"text\",\"1970-01-01\",\"1970-01-01 00:00:00\",1,[5,2,3,2],[[\"TEST\",\"TEST1\"],[\"TEST3\"]]]],\"rows\":3,\"statistics\":{\"elapsed\":0.001797702,\"rows_read\":3,\"bytes_read\":293,\"time_before_execution\":0.001251613,\"time_to_execute\":0.000544098,\"scanned_bytes_cache\":2003,\"scanned_bytes_storage\":0}}"
var response QueryResponse
err := json.Unmarshal([]byte(resultJson), &response)
if err != nil {
panic("Error in test code")
}
return &fireboltRows{response, 0}
}
func TestRowsColumns(t *testing.T) {
rows := mockRows()
columnNames := []string{"int_col", "bigint_col", "float_col", "double_col", "text_col", "date_col", "timestamp_col", "bool_col", "array_col", "nested_array_col"}
if !reflect.DeepEqual(rows.Columns(), columnNames) {
t.Errorf("column lists are not equal")
}
}
func TestRowsClose(t *testing.T) {
rows := mockRows()
if rows.Close() != nil {
t.Errorf("Closing rows was not successful")
}
var dest []driver.Value
if rows.Next(dest) != io.EOF {
t.Errorf("Next of closed rows didn't return EOF")
}
}
func TestRowsNext(t *testing.T) {
rows := mockRows()
var dest = make([]driver.Value, 10)
err := rows.Next(dest)
assert(err == nil, t, "Next shouldn't return an error")
assert(dest[0] == int32(2), t, "results not equal for int32")
assert(dest[1] == int64(1), t, "results not equal for int64")
assert(dest[2] == float32(0.312321), t, "results not equal for float32")
assert(dest[3] == float64(123213.321321), t, "results not equal for float64")
assert(dest[4] == "text", t, "results not equal for string")
err = rows.Next(dest)
assert(err == nil, t, "Next shouldn't return an error")
err = rows.Next(dest)
assert(err == nil, t, "Next shouldn't return an error")
assert(dest[0] == int32(3), t, "results not equal for int32")
assert(dest[1] == int64(5), t, "results not equal for int64")
assert(dest[2] == float32(0.312321), t, "results not equal for float32")
assert(dest[3] == float64(123213.321321), t, "results not equal for float64")
assert(dest[4] == "text", t, "results not equal for string")
assert(io.EOF == rows.Next(dest), t, "Next should return io.EOF if no data available anymore")
}