1 package enforcereleaselabel
2
3 import (
4 "context"
5 "reflect"
6 "testing"
7
8 "edge-infra.dev/pkg/lib/logging"
9
10 "github.com/google/go-github/v47/github"
11
12 "edge-infra.dev/pkg/f8n/devinfra/jack/constants"
13 "edge-infra.dev/pkg/f8n/devinfra/jack/plugin"
14 )
15
16 var c = &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{}}
17 var hp = &plugin.HandlerParams{
18 Ctx: context.Background(),
19 Client: c,
20 Org: "some-org",
21 Repo: "some-repo",
22 Log: *logging.NewLogger(),
23 }
24
25 func TestOpening(t *testing.T) {
26 c.GithubIssues = &plugin.MockIssueService{
27 Labels: []string{},
28 }
29
30 pre := &github.PullRequestEvent{
31 Action: github.String("opened"),
32 PullRequest: &github.PullRequest{
33 Labels: []*github.Label{},
34 },
35 }
36 handlePR(*hp, *pre)
37
38 ct := &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{Labels: []string{constants.TriageReleaseLabel, constants.DoNotMergeNeedsRelease}}}
39
40 if !reflect.DeepEqual(ct.GithubIssues, c.GithubIssues) {
41 t.Error("Failed: TestOpening")
42 }
43 }
44
45 func TestLabeling(t *testing.T) {
46
47 c.GithubIssues = &plugin.MockIssueService{
48 Labels: []string{constants.TriageReleaseLabel},
49 }
50
51 pre := &github.PullRequestEvent{
52 Action: github.String("labeled"),
53 PullRequest: &github.PullRequest{
54 Labels: []*github.Label{
55 {
56 Name: github.String(constants.TriageReleaseLabel),
57 },
58 },
59 },
60 }
61 handlePR(*hp, *pre)
62
63 ct := &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{Labels: []string{constants.TriageReleaseLabel}}}
64
65 if !reflect.DeepEqual(ct.GithubIssues, c.GithubIssues) {
66 t.Error("Failed: TestLabeling")
67 }
68
69
70 c.GithubIssues = &plugin.MockIssueService{
71 Labels: []string{"release-kind/bug"},
72 }
73
74 pre = &github.PullRequestEvent{
75 Action: github.String("labeled"),
76 PullRequest: &github.PullRequest{
77 Labels: []*github.Label{
78 {
79 Name: github.String("release-kind/bug"),
80 },
81 },
82 },
83 }
84 handlePR(*hp, *pre)
85
86 ct = &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{Labels: []string{"release-kind/bug"}}}
87
88 if !reflect.DeepEqual(ct.GithubIssues, c.GithubIssues) {
89 t.Error("Failed: TestLabeling")
90 }
91 }
92
93 func TestUnlabeling(t *testing.T) {
94
95 c.GithubIssues = &plugin.MockIssueService{
96 Labels: []string{constants.TriageReleaseLabel},
97 }
98
99 pre := &github.PullRequestEvent{
100 Action: github.String("unlabeled"),
101 PullRequest: &github.PullRequest{
102 Labels: []*github.Label{
103 {
104 Name: github.String(constants.TriageReleaseLabel),
105 },
106 },
107 },
108 }
109 handlePR(*hp, *pre)
110
111 ct := &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{Labels: []string{constants.TriageReleaseLabel}}}
112 if !reflect.DeepEqual(ct.GithubIssues, c.GithubIssues) {
113 t.Error("Failed: TestUnlabeling")
114 }
115
116
117 c.GithubIssues = &plugin.MockIssueService{
118 Labels: []string{
119 constants.TriageReleaseLabel,
120 },
121 }
122
123 pre = &github.PullRequestEvent{
124 Action: github.String("unlabeled"),
125 PullRequest: &github.PullRequest{
126 Labels: []*github.Label{
127 {
128 Name: github.String("release-kind/bug"),
129 },
130 },
131 },
132 }
133 handlePR(*hp, *pre)
134
135 ct = &plugin.MockGithubClient{GithubIssues: &plugin.MockIssueService{Labels: []string{constants.TriageReleaseLabel}}}
136 if !reflect.DeepEqual(ct.GithubIssues, c.GithubIssues) {
137 t.Error("Failed: TestUnlabeling")
138 }
139 }
140
View as plain text