-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexecutor_test.go
87 lines (72 loc) · 1.56 KB
/
executor_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
package main
import (
"bytes"
"regexp"
"strings"
"testing"
"time"
"github.com/ujiro99/logcatf/logcat"
)
func Test_IfMatch(t *testing.T) {
line := "aaa"
e := executor{
Stdout: new(bytes.Buffer),
trigger: regexp.MustCompile("a"),
}
res := e.IfMatch(line)
if &e != res {
t.Errorf("trigger should mathes line.")
}
}
func Test_IfMatch_not_match(t *testing.T) {
line := "bbb"
e := executor{
Stdout: new(bytes.Buffer),
trigger: regexp.MustCompile("a"),
}
res := e.IfMatch(line)
if &e == res {
t.Errorf("IfMatch should returns emptyExecutor.")
}
}
func Test_Exec(t *testing.T) {
expect := "test"
command := "echo $message"
item := logcat.Entry{"message": expect}
out := new(bytes.Buffer)
e := executor{
Stdout: out,
command: &command,
}
e.Exec(item)
<-time.After(time.Second / 100)
if !strings.Contains(out.String(), expect) {
t.Errorf("expect %s to eq \"%s\"", out.String(), expect)
}
}
func Test_Exec_useFlag(t *testing.T) {
expect := "test"
command := "echo %m"
item := logcat.Entry{"message": expect}
out := new(bytes.Buffer)
e := executor{
Stdout: out,
command: &command,
}
e.Exec(item)
<-time.After(time.Second / 100)
if !strings.Contains(out.String(), expect) {
t.Errorf("expect %s to eq \"%s\"", out.String(), expect)
}
}
func Test_Exec_empty(t *testing.T) {
expect := "test"
item := logcat.Entry{"message": expect}
out := new(bytes.Buffer)
e := emptyExecutor{}
e.Exec(item)
<-time.After(time.Second / 100)
if strings.Contains(out.String(), expect) {
t.Errorf("emptyExecutor should not execute command")
}
}