-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrows_test.go
81 lines (77 loc) · 1.66 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
package polypheny
import (
"database/sql/driver"
io "io"
"sync/atomic"
testing "testing"
)
func TestColumns(t *testing.T) {
columns := []string{"id"}
result := [][]any{{int32(1)}, {int32(2)}, {int32(3)}}
rows := PolyphenyRows{
columns: columns,
result: result,
readIndex: atomic.Int32{},
}
rows.readIndex.Store(0)
for i, v := range columns {
if v != rows.Columns()[i] {
t.Errorf("Column mismatches: expecting %s but got %s", v, rows.Columns()[i])
}
}
}
func TestRowsClose(t *testing.T) {
columns := []string{"id"}
result := [][]any{{int32(1)}, {int32(2)}, {int32(3)}}
rows := PolyphenyRows{
columns: columns,
result: result,
readIndex: atomic.Int32{},
}
rows.readIndex.Store(0)
rows.Close()
if rows.readIndex.Load() != -1 {
t.Error("Error closing result")
}
}
func TestNext(t *testing.T) {
columns := []string{"id"}
result := [][]any{{int32(1)}, {int32(2)}, {int32(3)}}
rows := PolyphenyRows{
columns: columns,
result: result,
readIndex: atomic.Int32{},
}
rows.readIndex.Store(0)
dest := make([]driver.Value, 1)
err := rows.Next(dest)
if err != nil {
t.Error(err)
}
if len(dest) != 1 || dest[0] != int32(1) {
t.Error("Error Next")
}
err = rows.Next(dest)
if err != nil {
t.Error(err)
}
if len(dest) != 1 || dest[0] != int32(2) {
t.Error("Error Next")
}
err = rows.Next(dest)
if err != nil {
t.Error(err)
}
if len(dest) != 1 || dest[0] != int32(3) {
t.Error("Error Next")
}
err = rows.Next(dest)
if err != io.EOF {
t.Error(err)
}
rows.Close()
err = rows.Next(dest)
if err.Error() != "The Rows iterator has been closed" {
t.Error("Expecting an error indicting the rows has been closed")
}
}