forked from omc/dendrite
/
tail_group_test.go
60 lines (54 loc) · 1.18 KB
/
tail_group_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 dendrite
import (
"os"
"path/filepath"
"testing"
"time"
)
var config *SourceConfig = nil
var group *TailGroup = nil
var _tg_init = func() {
config = new(SourceConfig)
config.Glob = filepath.Join(".", "testdata", "solr*txt")
_ = os.RemoveAll(filepath.Join("testdata", "solrN.txt"))
config.Pattern = "(?P<line>.+)\n"
config.OffsetDir = "tmp"
_ = os.RemoveAll(config.OffsetDir)
os.Mkdir(config.OffsetDir, 0777)
output = make(chan Record, 100000)
matches, _ := filepath.Glob(config.Glob)
for _, m := range matches {
os.Chtimes(m, time.Now(), time.Now())
}
group = NewTailGroup(*config, output)
}
func TestGroupHasTails(t *testing.T) {
_tg_init()
n := len(group.Tails)
if n != 2 {
t.Errorf("group has %d tails", n)
}
}
func TestRefreshPicksUpFiles(t *testing.T) {
_tg_init()
solrN := filepath.Join("testdata", "solrN.txt")
n := len(group.Tails)
if n != 2 {
t.Errorf("group has %d tails", n)
}
if tmp, err := os.Create(solrN); err != nil {
t.Error(err)
} else {
tmp.Close()
defer os.RemoveAll(solrN)
}
group.Refresh()
n = len(group.Tails)
if n != 3 {
t.Errorf("group has %d tails", n)
}
}
func TestGroupCanPoll(t *testing.T) {
_tg_init()
group.Poll()
}