Repository navigation
Expand file tree
/
Copy pathcommit_test.go
More file actions
70 lines (60 loc) · 2.19 KB
/
Copy pathcommit_test.go
File metadata and controls
70 lines (60 loc) · 2.19 KB
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
package main //nolint:testpackage // Tests unexported release helpers.
import (
"testing"
)
func TestFindBreakingCommits(t *testing.T) {
t.Parallel()
// Metadata for PRs that were labeled release/breaking. #10 is
// keyed by merge-commit SHA (direct merge), #20 only by PR
// number (cherry-picked, so the SHA on the release branch
// differs from the merge commit on main). #99 is labeled but
// deliberately absent from the commit list, simulating a
// breaking PR that shipped in an earlier release on the branch.
prMeta := &prMetadataMaps{
bySHA: map[string]prMetadata{
"aaa": {Labels: []string{"release/breaking"}},
},
byNumber: map[int]prMetadata{
10: {Labels: []string{"release/breaking"}},
20: {Labels: []string{"release/breaking"}},
99: {Labels: []string{"release/breaking"}},
},
}
commits := []commitEntry{
{SHA: "aaa", FullSHA: "aaa", Title: "feat: labeled via sha (#10)", PRCount: 10},
{SHA: "bbb", FullSHA: "bbb", Title: "fix: labeled via pr number (#20)", PRCount: 20},
{SHA: "ccc", FullSHA: "ccc", Title: "feat(cli)!: bang title (#30)", PRCount: 30},
{SHA: "ddd", FullSHA: "ddd", Title: "fix: ordinary change (#40)", PRCount: 40},
{SHA: "eee", FullSHA: "eee", Title: "chore: no pr number"},
}
got := findBreakingCommits(commits, prMeta)
want := []string{"aaa", "bbb", "ccc"}
if len(got) != len(want) {
t.Fatalf("got %d breaking commits, want %d: %+v", len(got), len(want), got)
}
for i, c := range got {
if c.SHA != want[i] {
t.Fatalf("breaking[%d] = %s, want %s", i, c.SHA, want[i])
}
}
}
func TestFindBreakingCommitsWithoutMetadata(t *testing.T) {
t.Parallel()
// With no PR metadata (gh unavailable), only "!" titles are
// detected.
prMeta := &prMetadataMaps{
bySHA: map[string]prMetadata{},
byNumber: map[int]prMetadata{},
}
commits := []commitEntry{
{SHA: "aaa", FullSHA: "aaa", Title: "feat!: bang (#1)", PRCount: 1},
{SHA: "bbb", FullSHA: "bbb", Title: "feat: plain (#2)", PRCount: 2},
}
got := findBreakingCommits(commits, prMeta)
if len(got) != 1 || got[0].SHA != "aaa" {
t.Fatalf("got %+v, want only aaa", got)
}
if got := findBreakingCommits(nil, prMeta); got != nil {
t.Fatalf("got %+v for no commits, want nil", got)
}
}