mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-29 15:52:02 +00:00
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:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -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))
|
||||
}
|
||||
Reference in new issue
Block a user