-
Notifications
You must be signed in to change notification settings - Fork 0
/
offset_test.go
70 lines (52 loc) · 1.62 KB
/
offset_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 filersync
import (
"os"
"io/ioutil"
"testing"
)
func TestOffset(t *testing.T) {
tmpdir, err := ioutil.TempDir("/tmp", "filersync")
if err != nil { t.Fatal(err) }
defer os.RemoveAll(tmpdir)
content := []byte("abcefg")
err = ioutil.WriteFile(tmpdir+"/a.log-1", content, 0666)
if err != nil { t.Fatal(err) }
defer os.Remove(tmpdir + "/a.log-1")
err = ioutil.WriteFile(tmpdir+"/a.log-2", content, 0666)
if err != nil { t.Fatal(err) }
defer os.Remove(tmpdir + "/a.log-2")
stat1, err := getStat(tmpdir+"/a.log-1")
if err != nil { t.Fatal(err) }
stat2, err := getStat(tmpdir + "/a.log-2")
if err != nil { t.Fatal(err) }
o := NewOffset()
_, ok := o.GetStatOffset(stat1)
if ok { t.Fatal("must not be ok") }
o.SetStatOffset(stat1, 1)
s, ok := o.GetStatOffset(stat1)
if ! ok { t.Fatal("must be ok") }
if s != 1 { t.Fatal("s1.offset must be 1") }
finish := o.IsFinish(stat1)
if finish { t.Fatal("must not be finish") }
o.AddStatOffset(stat1, 2)
s, ok = o.GetStatOffset(stat1)
if ! ok { t.Fatal("must be ok") }
if s != 3 { t.Fatal("s1.offset must be 3") }
finish = o.IsFinish(stat1)
if finish { t.Fatal("must not be finish") }
o.SetStatLimit(stat1, 3)
finish = o.IsFinish(stat1)
if ! finish { t.Fatal("must be finish") }
ok = o.Remove(stat1)
if ! ok { t.Fatal("must can remove") }
ok = o.Remove(stat1)
if ok { t.Fatal("must could not remove") }
_, ok = o.GetStatOffset(stat1)
if ok { t.Fatal("must not be ok") }
ok = o.IsFinish(stat1)
if ok { t.Fatal("must not finish") }
o.AddStatOffset(stat2, 3)
s, ok = o.GetStatOffset(stat2)
if ! ok { t.Fatal("must be ok") }
if s != 3 { t.Fatal("must be 3") }
}