-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbisect_test.go
151 lines (147 loc) · 3.07 KB
/
bisect_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"golang.org/x/oscar/internal/bisect"
"golang.org/x/oscar/internal/github"
)
func TestParseBisectTrigger(t *testing.T) {
for _, tc := range []struct {
name string
e *github.WebhookIssueCommentEvent
want *bisect.Request
err bool
}{
{
name: "no bisect directive",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: "body1",
},
},
want: nil,
err: false,
},
{
name: "missing bisect command",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: "@gabyhelp",
},
},
want: nil,
err: false,
},
{
name: "bisect directive not first",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: strings.Join([]string{
"some line",
"@gabyhelp bisect",
}, "\n"),
},
},
want: nil,
err: false,
},
{
name: "wrong number of directive args",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: "@gabyhelp bisect go1.22.0 go1.22.1 go1.22.2",
},
},
want: nil,
err: true,
},
{
name: "insufficient number of directive args",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: "@gabyhelp bisect go1.22.0",
},
},
want: nil,
err: true,
},
{
name: "no regression body",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: "@gabyhelp bisect",
},
},
want: nil,
err: true,
},
{
name: "correct with no directive args",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: strings.Join([]string{
"@gabyhelp bisect",
"```",
"some code",
"```",
}, "\n"),
},
},
want: &bisect.Request{
Fail: "master",
Pass: "go1.22.0",
Repo: "https://go.googlesource.com/go",
Body: "some code",
},
err: false,
},
{
name: "correct with directive args",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: strings.Join([]string{
"@gabyhelp bisect go1.22.1 go1.22.2",
"```",
"some code",
"```",
}, "\n"),
},
},
want: &bisect.Request{
Fail: "go1.22.1",
Pass: "go1.22.2",
Repo: "https://go.googlesource.com/go",
Body: "some code",
},
err: false,
},
{
name: "wrong order for directive and regression body",
e: &github.WebhookIssueCommentEvent{
Comment: github.Comment{
Body: strings.Join([]string{
"```",
"some code",
"```",
"@gabyhelp bisect go1.22.1 go1.22.2",
}, "\n"),
},
},
want: nil,
err: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
got, err := parseBisectTrigger(tc.e)
if tc.err && err == nil {
t.Error("got no error; want some")
} else if diff := cmp.Diff(got, tc.want); diff != "" {
t.Errorf("request mismatch (-got +want):\n%s", diff)
}
})
}
}