This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rows_test.go
88 lines (79 loc) · 2.13 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cql
import (
"database/sql/driver"
"io"
"testing"
)
func TestRowsColumns(t *testing.T) {
conn, stmt, rows := testGetRowsHostValid(t, "select cql_version from system.local")
if rows == nil {
t.Fatal("rows is nil")
}
columns := rows.Columns()
if len(columns) != 1 {
t.Fatalf("Columns len - received: %v - expected: %v ", len(columns), 1)
}
if columns[0] != "cql_version" {
t.Fatalf("Columns[0] - received: %v - expected: %v ", columns[0], "cql_version")
}
err := rows.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
err = stmt.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
err = conn.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
}
func TestRowsNext(t *testing.T) {
conn, stmt, rows := testGetRowsHostValid(t, "select cql_version from system.local")
if rows == nil {
t.Fatal("rows is nil")
}
dest := make([]driver.Value, 1)
err := rows.Next(dest)
if err != nil {
t.Fatalf("Next error - received: %v - expected: %v ", err, nil)
}
if len(dest) != 1 {
t.Fatalf("Next len - received: %v - expected: %v ", len(dest), 1)
}
data, ok := dest[0].(string)
if !ok {
t.Fatal("Next type not string")
}
if len(data) < 3 {
t.Fatalf("Next string len too small - received: %v ", len(data))
}
dest = make([]driver.Value, 0)
err = rows.Next(dest)
if err == nil || err != io.EOF {
t.Fatalf("Next error - received: %v - expected: %v ", err, io.EOF)
}
if len(dest) != 0 {
t.Fatalf("Next len - received: %v - expected: %v ", len(dest), 1)
}
err = rows.Next(dest)
if err == nil || err != io.EOF {
t.Fatalf("Next error - received: %v - expected: %v ", err, io.EOF)
}
if len(dest) != 0 {
t.Fatalf("Next len - received: %v - expected: %v ", len(dest), 1)
}
err = rows.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
err = stmt.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
err = conn.Close()
if err != nil {
t.Fatalf("Close error - received: %v - expected: %v ", err, nil)
}
}