-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_test.go
115 lines (108 loc) · 2.16 KB
/
test_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
103
104
105
106
107
108
109
110
111
112
113
114
115
package zdb_test
import (
"context"
"testing"
"zgo.at/zdb"
)
func TestDump(t *testing.T) {
zdb.RunTest(t, func(t *testing.T, ctx context.Context) {
err := zdb.Exec(ctx, `create table tbl (
v text not null,
i int not null,
t timestamp not null,
n text null
);`)
if err != nil {
t.Fatal(err)
}
err = zdb.Exec(ctx, `insert into tbl values
('hello', 42, '2006-01-02 15:04:05', 'v'),
('<zxc>,"', 0, '2020-01-01 12:00:00', null);
`)
if err != nil {
t.Fatal(err)
}
return
{
got := zdb.DumpString(ctx, `select * from tbl`)
want := `
v i t n
hello 42 2006-01-02 15:04:05 v
<zxc>," 0 2020-01-01 12:00:00 NULL`
if d := zdb.Diff(got, want); d != "" {
t.Error(d)
}
}
{
got := zdb.DumpString(ctx, `select * from tbl`, zdb.DumpVertical)
want := `
v hello
i 42
t 2006-01-02 15:04:05
n v
v <zxc>,"
i 0
t 2020-01-01 12:00:00
n NULL`
if d := zdb.Diff(got, want); d != "" {
t.Error(d)
}
}
{
got := zdb.DumpString(ctx, `select * from tbl`, zdb.DumpCSV)
want := `
v,i,t,n
hello,42,2006-01-02 15:04:05,v
"<zxc>,""",0,2020-01-01 12:00:00,NULL`
if d := zdb.Diff(got, want); d != "" {
t.Error(d)
}
}
{
got := zdb.DumpString(ctx, `select * from tbl`, zdb.DumpJSON)
want := `[
{
"i": 42,
"n": "v",
"t": "2006-01-02T15:04:05Z",
"v": "hello"
},
{
"i": 0,
"n": null,
"t": "2020-01-01T12:00:00Z",
"v": "\u003czxc\u003e,\""
}
]`
if d := zdb.Diff(got, want); d != "" {
t.Error(d)
}
}
{
got := zdb.DumpString(ctx, `select * from tbl`, zdb.DumpHTML)
want := `
<table><thead><tr>
<th>v</th>
<th>i</th>
<th>t</th>
<th>n</th>
</tr></thead><tbody>
<tr>
<td>hello</td>
<td>42</td>
<td>2006-01-02 15:04:05</td>
<td>v</td>
</tr>
<tr>
<td><zxc>,"</td>
<td>0</td>
<td>2020-01-01 12:00:00</td>
<td>NULL</td>
</tr>
</tbody></table>`
if d := zdb.Diff(got, want); d != "" {
t.Error(d)
}
}
})
}