Repository navigation
Expand file tree
/
Copy pathsqlstream_test.go
More file actions
122 lines (112 loc) · 2.99 KB
/
Copy pathsqlstream_test.go
File metadata and controls
122 lines (112 loc) · 2.99 KB
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
package sqlstream_test
import (
"io"
"testing"
"github.com/stackql/stackql/internal/stackql/sqlstream"
)
func TestNewStaticMapStream(t *testing.T) {
payload := []map[string]interface{}{
{"id": 1, "name": "test"},
}
stream := sqlstream.NewStaticMapStream(payload)
if stream == nil {
t.Fatal("NewStaticMapStream returned nil")
}
}
func TestStaticMapStream_Write(t *testing.T) {
payload := []map[string]interface{}{}
stream := sqlstream.NewStaticMapStream(payload)
err := stream.Write(nil)
if err != nil {
t.Errorf("Write(nil) error = %v, want nil", err)
}
}
func TestStaticMapStream_Write_WithData(t *testing.T) {
payload := []map[string]interface{}{}
stream := sqlstream.NewStaticMapStream(payload)
err := stream.Write([]map[string]interface{}{
{"key": "value"},
})
if err != nil {
t.Errorf("Write() error = %v, want nil", err)
}
}
func TestStaticMapStream_Read_ReturnsPayload(t *testing.T) {
payload := []map[string]interface{}{
{"id": 1, "name": "alice"},
{"id": 2, "name": "bob"},
}
stream := sqlstream.NewStaticMapStream(payload)
got, err := stream.Read()
if err != io.EOF {
t.Errorf("Read() error = %v, want io.EOF", err)
}
if len(got) != 2 {
t.Errorf("Read() returned %d rows, want 2", len(got))
}
if got[0]["id"] != 1 {
t.Errorf("Read()[0][id] = %v, want 1", got[0]["id"])
}
if got[1]["name"] != "bob" {
t.Errorf("Read()[1][name] = %v, want 'bob'", got[1]["name"])
}
}
func TestStaticMapStream_Read_EmptyPayload(t *testing.T) {
payload := []map[string]interface{}{}
stream := sqlstream.NewStaticMapStream(payload)
got, err := stream.Read()
if err != io.EOF {
t.Errorf("Read() error = %v, want io.EOF", err)
}
if len(got) != 0 {
t.Errorf("Read() returned %d rows, want 0", len(got))
}
}
func TestStaticMapStream_Read_NilPayload(t *testing.T) {
stream := sqlstream.NewStaticMapStream(nil)
got, err := stream.Read()
if err != io.EOF {
t.Errorf("Read() error = %v, want io.EOF", err)
}
if got != nil {
t.Errorf("Read() returned %v, want nil for nil payload", got)
}
}
func TestStaticMapStream_Read_MultipleRows(t *testing.T) {
payload := []map[string]interface{}{
{"a": 1, "b": 2, "c": 3},
{"a": 4, "b": 5, "c": 6},
{"a": 7, "b": 8, "c": 9},
}
stream := sqlstream.NewStaticMapStream(payload)
got, err := stream.Read()
if err != io.EOF {
t.Errorf("Read() error = %v, want io.EOF", err)
}
if len(got) != 3 {
t.Errorf("Read() returned %d rows, want 3", len(got))
}
}
func TestStaticMapStream_Read_NestedMaps(t *testing.T) {
payload := []map[string]interface{}{
{
"user": map[string]interface{}{
"name": "test",
"age": 30,
},
"active": true,
},
}
stream := sqlstream.NewStaticMapStream(payload)
got, err := stream.Read()
if err != io.EOF {
t.Errorf("Read() error = %v, want io.EOF", err)
}
nested, ok := got[0]["user"].(map[string]interface{})
if !ok {
t.Fatalf("Read()[0][user] is not a map, got %T", got[0]["user"])
}
if nested["name"] != "test" {
t.Errorf("Read()[0][user][name] = %v, want 'test'", nested["name"])
}
}