-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrows_test.go
102 lines (94 loc) · 1.99 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package db
import (
"testing"
)
// TestScanWithValidData tests Scan() function
func TestScanWithValidData(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", 1, true},
},
idx: 1,
}
var str string
var i int
var b bool
err := rows.Scan(&str, &i, &b)
if err != nil {
t.Errorf("Scan() error, expected no error but got: %v", err)
}
}
// TestScanWithInvalidData tests Scan() function
func TestScanWithInvalidData(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", "invalid", true},
},
idx: 1,
}
var str string
var i int
var b bool
err := rows.Scan(&str, &i, &b)
if err == nil {
t.Errorf("Scan() error, expected error but got none")
}
}
// TestNextWithRemainingData tests Next() function
func TestNextWithRemainingData(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", 1, true},
{"test2", 2, false},
},
idx: 1,
}
if !rows.Next() {
t.Errorf("Next() error, expected true but got false")
}
}
// TestNextWithoutRemainingData tests Next() function
func TestNextWithoutRemainingData(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", 1, true},
},
idx: 1,
}
if rows.Next() {
t.Errorf("Next() error, expected false but got true")
}
}
// TestClose tests Close() function
func TestClose(t *testing.T) {
rows := &SurrogateRows{}
err := rows.Close()
if err != nil {
t.Errorf("Close() error, expected no error but got: %v", err)
}
}
// TestDumpWithMultipleRows tests Dump() function
func TestDumpWithMultipleRows(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", 1, true},
{"test2", 2, false},
},
}
dump := rows.Dump()
if dump == "" {
t.Errorf("Dump() error, dump is empty")
}
}
// TestDumpWithSingleRow tests Dump() function
func TestDumpWithSingleRow(t *testing.T) {
rows := &SurrogateRows{
data: []surrogateRowsRow{
{"test", 1, true},
},
}
dump := rows.Dump()
if dump == "" {
t.Errorf("Dump() error, dump is empty")
}
}