-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtechlog_test.go
107 lines (96 loc) · 1.64 KB
/
techlog_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
package techlog
import (
"encoding/json"
"github.com/k0kubun/pp"
"testing"
)
func TestWatch(t *testing.T) {
type args struct {
dir string
opts []Options
}
tests := []struct {
name string
args args
}{
{
"small chunk",
args{
dir: "./log",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
logs, _ := watch(tt.args.dir, tt.args.opts...)
for log := range logs {
pp.Println(log)
}
})
}
}
func TestStreamEvents(t *testing.T) {
type args struct {
file string
maxEvents int64
}
tests := []struct {
name string
args args
wantErr bool
}{
{
"simple",
args{
file: "./log/18100509.log",
maxEvents: 10,
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stream, err := StreamRead(tt.args.file, tt.args.maxEvents)
if (err != nil) != tt.wantErr {
t.Errorf("StreamRead() error = %v, wantErr %v", err, tt.wantErr)
return
}
count := 0
for _ = range stream {
count++
}
pp.Println("events", count)
})
}
}
func TestRead(t *testing.T) {
type args struct {
file string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
"simple",
args{
file: "./log/21051221.log",
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Read(tt.args.file)
if (err != nil) != tt.wantErr {
t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
return
}
d, _ := json.Marshal(got)
pp.Println("events count", len(got))
//pp.Println("events json", got)
pp.Println("events json", len(d))
})
}
}