-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
glc_test.go
60 lines (55 loc) · 1.13 KB
/
glc_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
package glc
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestGLC(t *testing.T) {
files := []string{"glc.localhost.xuri.log.WARNING.20180312-144710.3877", "glc.localhost.xuri.log.WARNING.20180312-144710"}
path, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
t.Error(err)
return
}
path += `/`
go func() {
glc := NewGLC(InitOption{
Path: path,
Prefix: `glc`,
Interval: time.Duration(time.Second),
Reserve: time.Duration(time.Second * 3),
})
glc.exists(files[0])
}()
for _, file := range files {
fp, err := os.OpenFile(path+file, os.O_CREATE|os.O_RDWR, 0700)
if err != nil {
fp.Close()
t.Error(err)
continue
}
_, err = fp.WriteAt([]byte{0}, 10)
if err != nil {
fp.Close()
t.Error(err)
continue
}
fp.Close()
time.Sleep(time.Second * 5)
}
}
func TestBadPath(t *testing.T) {
path := []string{"", "/usr/bin/nohup"}
for _, p := range path {
go func(p string) {
NewGLC(InitOption{
Path: p,
Prefix: `glc`,
Interval: time.Duration(time.Second),
Reserve: time.Duration(time.Second * 3),
})
}(p)
}
time.Sleep(time.Second * 5)
}