test: consolidate Go tests (#39962)

Consolidate all Go tests. Coverage is identical to before. Go tests are
around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
silverwind authored and GitHub committed 2026-10-24 13:48:19 +00:00
1 parent ce7364e215
commit 8abda62312
388 files changed
+18410 -29561

No files matched your search

+26 -33
View File
@@ -12,21 +12,33 @@ import (
"github.com/stretchr/testify/require"
)
func TestPullRequestPayloadSynchronizeBeforeAfter(t *testing.T) {
payload := &PullRequestPayload{
Action: HookIssueSynchronized,
Before: "1111111111111111111111111111111111111111",
After: "2222222222222222222222222222222222222222",
Index: 12,
}
data, err := json.Marshal(payload)
require.NoError(t, err)
assert.JSONEq(t, `{
func TestPullRequestPayload(t *testing.T) {
for _, tt := range []struct {
payload PullRequestPayload
want string
}{
{
payload: PullRequestPayload{
Action: HookIssueSynchronized,
Before: "1111111111111111111111111111111111111111",
After: "2222222222222222222222222222222222222222",
Index: 12,
},
want: `
"action": "synchronized",
"before": "1111111111111111111111111111111111111111",
"after": "2222222222222222222222222222222222222222",
"after": "2222222222222222222222222222222222222222",`,
},
{
payload: PullRequestPayload{Action: HookIssueOpened, Index: 12},
want: `
"action": "opened",`,
},
} {
t.Run(string(tt.payload.Action), func(t *testing.T) {
data, err := json.Marshal(&tt.payload)
require.NoError(t, err)
assert.JSONEq(t, `{`+tt.want+`
"number": 12,
"commit_id": "",
"pull_request": null,
@@ -35,25 +47,6 @@ func TestPullRequestPayloadSynchronizeBeforeAfter(t *testing.T) {
"review": null,
"sender": null
}`, string(data))
}
func TestPullRequestPayloadNonSynchronizeOmitsBeforeAfter(t *testing.T) {
payload := &PullRequestPayload{
Action: HookIssueOpened,
Index: 12,
})
}
data, err := json.Marshal(payload)
require.NoError(t, err)
assert.JSONEq(t, `{
"action": "opened",
"number": 12,
"commit_id": "",
"pull_request": null,
"repository": null,
"requested_reviewer": null,
"review": null,
"sender": null
}`, string(data))
}
+9 -23
View File
@@ -46,39 +46,22 @@ func TestIssueTemplateStringSlice_UnmarshalYAML(t *testing.T) {
tests := []struct {
name string
content string
tmpl *IssueTemplate
want *IssueTemplate
labels []string
wantErr string
}{
{
name: "array",
content: `labels: ["a", "b", "c"]`,
tmpl: &IssueTemplate{
Labels: []string{"should_be_overwrote"},
},
want: &IssueTemplate{
Labels: []string{"a", "b", "c"},
},
labels: []string{"a", "b", "c"},
},
{
name: "string",
content: `labels: "a,b,c"`,
tmpl: &IssueTemplate{
Labels: []string{"should_be_overwrote"},
},
want: &IssueTemplate{
Labels: []string{"a", "b", "c"},
},
labels: []string{"a", "b", "c"},
},
{
name: "empty",
content: `labels:`,
tmpl: &IssueTemplate{
Labels: []string{"should_be_overwrote"},
},
want: &IssueTemplate{
Labels: nil,
},
},
{
name: "error",
@@ -87,18 +70,21 @@ labels:
a: aa
b: bb
`,
tmpl: &IssueTemplate{},
wantErr: "yaml: construct errors: line 3: cannot unmarshal !!map into IssueTemplateStringSlice",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := yaml.Unmarshal([]byte(tt.content), tt.tmpl)
tmpl := &IssueTemplate{}
if tt.wantErr == "" {
tmpl.Labels = []string{"should_be_overwrote"}
}
err := yaml.Unmarshal([]byte(tt.content), tmpl)
if tt.wantErr != "" {
assert.EqualError(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.want, tt.tmpl)
assert.Equal(t, &IssueTemplate{Labels: tt.labels}, tmpl)
}
})
}