-
Notifications
You must be signed in to change notification settings - Fork 1
/
clickhouse_json_test.go
59 lines (50 loc) · 1.17 KB
/
clickhouse_json_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
package clickhouseJSONEachRow
import (
"bytes"
"io"
"testing"
)
var (
wantJson = []byte(`[{"SearchPhrase":"дизайн штор","count()":"1064"}
,{"SearchPhrase":"баку","count()":"1000"}
,{"SearchPhrase":"","count":"8267016"}
]`)
fromJson = []byte(`{"SearchPhrase":"дизайн штор","count()":"1064"}
{"SearchPhrase":"баку","count()":"1000"}
{"SearchPhrase":"","count":"8267016"}
`)
)
func TestCopy(t *testing.T) {
for i := 2; i < 30; i++ {
buf1 := bytes.NewBuffer(make([]byte, 0, 145))
buf2 := bytes.NewBuffer(fromJson)
count, err := Copy(buf1, buf2, i)
if err != nil && err != io.EOF {
t.Fatal(err)
return
}
if count != 145 {
t.Fatal("wrong copy count elements")
}
if bytes.Compare(buf1.Bytes(), wantJson) != 0 {
t.Fatal("not same")
}
}
}
func BenchmarkCopyTest(b *testing.B) {
for i := 0; i < b.N; i++ {
buf1 := bytes.NewBuffer(make([]byte, 0, 145))
buf2 := bytes.NewBuffer(fromJson)
count, err := Copy(buf1, buf2, 4)
if err != nil && err != io.EOF {
b.Fatal(err)
return
}
if count != 145 {
b.Fatal("wrong copy count elements")
}
if bytes.Compare(buf1.Bytes(), wantJson) != 0 {
b.Fatal("not same")
}
}
}