forked from stathat/rotate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate_test.go
70 lines (63 loc) · 1.15 KB
/
rotate_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
package rotate
import (
"io/ioutil"
"os"
"testing"
)
func TestCreate(t *testing.T) {
root, err := ioutil.TempDir("", "multitest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
x, err := New(root, "mt")
if err != nil {
t.Fatal(err)
}
if _, err := x.Write([]byte("hello\n")); err != nil {
t.Fatal(err)
}
d, err := os.Open(root)
if err != nil {
t.Fatal(err)
}
names, err := d.Readdirnames(1024)
if err != nil {
t.Fatal(err)
}
if len(names) != 1 {
t.Errorf("number files in root: %d, expected 1", len(names))
}
}
func TestRotate(t *testing.T) {
root, err := ioutil.TempDir("", "multitest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
x, err := New(root, "mt")
if err != nil {
t.Fatal(err)
}
x.SetMax(5)
for i := 0; i < 20; i++ {
if _, err := x.Write([]byte("hello\n")); err != nil {
t.Fatal(err)
}
}
d, err := os.Open(root)
if err != nil {
t.Fatal(err)
}
defer d.Close()
names, err := d.Readdirnames(1024)
if err != nil {
t.Fatal(err)
}
if len(names) != 11 {
t.Errorf("number files in root: %d, expected 11", len(names))
for i, n := range names {
t.Logf("%d: %q", i, n)
}
}
}