Skip to content

Commit d5a697e

Browse files
committed
fix tests
1 parent 336e6e3 commit d5a697e

File tree

4 files changed

+27
-69
lines changed

4 files changed

+27
-69
lines changed

backport/backport.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ func backport(ctx context.Context, log *slog.Logger, client BackportClient, issu
164164
func Backport(ctx context.Context, log *slog.Logger, backportClient BackportClient, commentClient CommentClient, issueClient IssueClient, execClient CommandRunner, opts BackportOpts) (*github.PullRequest, error) {
165165
// Remove any `backport` related labels from the original PR, and mark this PR as a "backport"
166166
labels := []*github.Label{
167-
&github.Label{
168-
Name: github.String("backport"),
169-
},
167+
{Name: github.String("backport")},
170168
}
171169

172170
for _, v := range opts.Labels {

backport/backport_test.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ func TestMostRecentBranch(t *testing.T) {
7878
}
7979

8080
func TestBackportTarget(t *testing.T) {
81-
assertError := func(t *testing.T, label *github.Label, branches []*github.Branch) {
81+
assertError := func(t *testing.T, label string, branches []*github.Branch) {
8282
t.Helper()
8383
b, err := BackportTarget(label, branches)
8484
assert.Error(t, err)
8585
assert.Empty(t, b)
8686
}
8787

88-
assertBranch := func(t *testing.T, label *github.Label, branches []*github.Branch, branch string) {
88+
assertBranch := func(t *testing.T, label string, branches []*github.Branch, branch string) {
8989
t.Helper()
9090
b, err := BackportTarget(label, branches)
9191
assert.NoError(t, err)
@@ -107,36 +107,16 @@ func TestBackportTarget(t *testing.T) {
107107
{Name: github.String("release-12.2.12")},
108108
}
109109

110-
assertError(t, &github.Label{
111-
Name: github.String("backport v3.2.x"),
112-
}, branches)
113-
assertError(t, &github.Label{
114-
Name: github.String("backport v4.0.x"),
115-
}, branches)
116-
assertError(t, &github.Label{
117-
Name: github.String("backport v13.0.x"),
118-
}, branches)
119-
assertError(t, &github.Label{
120-
Name: github.String("backport v10.5.x"),
121-
}, branches)
122-
assertError(t, &github.Label{
123-
Name: github.String("backport v11.8.x"),
124-
}, branches)
125-
assertBranch(t, &github.Label{
126-
Name: github.String("backport v11.0.x"),
127-
}, branches, "release-11.0.1")
128-
assertBranch(t, &github.Label{
129-
Name: github.String("backport v12.1.x"),
130-
}, branches, "release-12.1.15")
131-
assertBranch(t, &github.Label{
132-
Name: github.String("backport v12.0.x"),
133-
}, branches, "release-12.0.15")
134-
assertBranch(t, &github.Label{
135-
Name: github.String("backport v1.2.x"),
136-
}, branches, "release-1.2.3")
137-
assertBranch(t, &github.Label{
138-
Name: github.String("backport v10.2.x"),
139-
}, branches, "release-10.2.4")
110+
assertError(t, "backport v3.2.x", branches)
111+
assertError(t, "backport v4.0.x", branches)
112+
assertError(t, "backport v13.0.x", branches)
113+
assertError(t, "backport v10.5.x", branches)
114+
assertError(t, "backport v11.8.x", branches)
115+
assertBranch(t, "backport v11.0.x", branches, "release-11.0.1")
116+
assertBranch(t, "backport v12.1.x", branches, "release-12.1.15")
117+
assertBranch(t, "backport v12.0.x", branches, "release-12.0.15")
118+
assertBranch(t, "backport v1.2.x", branches, "release-1.2.3")
119+
assertBranch(t, "backport v10.2.x", branches, "release-10.2.4")
140120
}
141121

142122
type TestBackportClient struct {

backport/pr_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func GetBackportPrInfo(ctx context.Context, client *github.Client, ghctx *github
3636
// Try to use event data if present
3737
eventPath := ghctx.EventPath
3838
if eventPath != "" {
39-
return getFromEvent(ctx, client, ghctx)
39+
return getFromEvent(ghctx)
4040
}
4141

4242
return PrInfo{}, fmt.Errorf("no PR info found")
4343
}
4444

45-
func getFromEvent(ctx context.Context, client *github.Client, ghctx *githubactions.GitHubContext) (PrInfo, error) {
45+
func getFromEvent(ghctx *githubactions.GitHubContext) (PrInfo, error) {
4646
payload := &github.PullRequestTargetEvent{}
4747

4848
if err := UnmarshalEventData(ghctx, &payload); err != nil {

backport/release_branches_test.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@ func TestBackportTargets(t *testing.T) {
2525
}
2626

2727
t.Run("with backport labels", func(t *testing.T) {
28-
labels := []*github.Label{
29-
{
30-
Name: github.String("backport v12.2.x"),
31-
},
32-
{
33-
Name: github.String("backport v12.0.x"),
34-
},
35-
{
36-
Name: github.String("backport v11.0.x"),
37-
},
28+
labels := []string{
29+
"backport v12.2.x",
30+
"backport v12.0.x",
31+
"backport v11.0.x",
3832
}
3933

4034
targets, err := BackportTargets(branches, labels)
@@ -47,28 +41,14 @@ func TestBackportTargets(t *testing.T) {
4741
})
4842

4943
t.Run("with non-backport labels", func(t *testing.T) {
50-
labels := []*github.Label{
51-
{
52-
Name: github.String("type/bug"),
53-
},
54-
{
55-
Name: github.String("backport v12.2.x"),
56-
},
57-
{
58-
Name: github.String("release/latest"),
59-
},
60-
{
61-
Name: github.String("backport v12.0.x"),
62-
},
63-
{
64-
Name: github.String("type/ci"),
65-
},
66-
{
67-
Name: github.String("backport v11.0.x"),
68-
},
69-
{
70-
Name: github.String("add-to-changelog"),
71-
},
44+
labels := []string{
45+
"type/bug",
46+
"backport v12.2.x",
47+
"release/latest",
48+
"backport v12.0.x",
49+
"type/ci",
50+
"backport v11.0.x",
51+
"add-to-changelog",
7252
}
7353

7454
targets, err := BackportTargets(branches, labels)

0 commit comments

Comments
 (0)