-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparse_test.go
122 lines (109 loc) · 2.45 KB
/
parse_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package dreck
import (
"io/ioutil"
"testing"
)
func TestParseComment(t *testing.T) {
f := "testdata/issue_comment.json"
event := "issue_comment"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
if l := req.Comment.User.Login; l != "miekg" {
t.Errorf("expected login to be %s, got %s", "miekg", l)
}
}
func TestParseIssueOpen(t *testing.T) {
f := "testdata/issues-open.json"
event := "issues"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
if l := req.Comment.User.Login; l != "miekg" {
t.Errorf("expected login to be %s, got %s", "miekg", l)
}
}
func TestParsePullRequest(t *testing.T) {
f := "testdata/pull_request.json"
event := "pull_request"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
if l := req.Comment.User.Login; l != "miekg" {
t.Errorf("expected login to be %s, got %s", "miekg", l)
}
if l := req.Comment.Body; l != "/label moo" {
t.Errorf("expected body to be %s, got %s", "/label moo", l)
}
}
func TestParsePullRequesNumbert(t *testing.T) {
f := "testdata/pull_request.json"
event := "pull_request"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
if l := req.PullRequest.Number; l != 128 {
t.Errorf("expected number to be %d, got %d", 128, l)
}
}
func TestParseMultipleCommands(t *testing.T) {
f := "testdata/issue_comment-multiple.json"
event := "issue_comment"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
conf := &DreckConfig{}
c := parse(req.Comment.Body, conf)
if len(c) != 2 {
t.Errorf("expected 2 commands, got %d", len(c))
}
for i := range c {
if c[i].Type == "lgtm" {
if c[i].Value != "" {
t.Errorf("expected not value, got %s", c[i].Value)
}
}
}
}
func TestParseDulicate(t *testing.T) {
f := "testdata/issue_comment-duplicate.json"
event := "issue_comment"
body, err := ioutil.ReadFile(f)
if err != nil {
t.Error(err)
}
req, err := parseEvent(event, body)
if err != nil {
t.Error(err)
}
conf := &DreckConfig{}
c := parse(req.Comment.Body, conf)
if c[0].Type != "duplicate" {
t.Errorf("expected not duplicate, got %s", c[0].Type)
}
}