Skip to content

Commit f0142d0

Browse files
committed
Fix lint and use immediate queue on tests
1 parent 646c76d commit f0142d0

File tree

7 files changed

+17
-28
lines changed

7 files changed

+17
-28
lines changed

services/webhook/general_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ func packageTestPayload() *api.PackagePayload {
319319
AvatarURL: "http://localhost:3000/user1/avatar",
320320
},
321321
Repository: nil,
322-
Organization: &api.User{
323-
UserName: "org1",
322+
Organization: &api.Organization{
323+
Name: "org1",
324324
AvatarURL: "http://localhost:3000/org1/avatar",
325325
},
326326
Package: &api.Package{

services/webhook/webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727
"github.com/gobwas/glob"
2828
)
2929

30-
type WebhookRequester func(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error)
30+
type Requester func(context.Context, *webhook_model.Webhook, *webhook_model.HookTask) (req *http.Request, body []byte, err error)
3131

32-
var webhookRequesters = map[webhook_module.HookType]WebhookRequester{}
32+
var webhookRequesters = map[webhook_module.HookType]Requester{}
3333

34-
func RegisterWebhookRequester(hookType webhook_module.HookType, requester WebhookRequester) {
34+
func RegisterWebhookRequester(hookType webhook_module.HookType, requester Requester) {
3535
webhookRequesters[hookType] = requester
3636
}
3737

tests/integration/repo_webhook_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/url"
1212
"strings"
1313
"testing"
14-
"time"
1514

1615
auth_model "code.gitea.io/gitea/models/auth"
1716
"code.gitea.io/gitea/models/repo"
@@ -132,8 +131,6 @@ func Test_WebhookCreate(t *testing.T) {
132131
// 2. trigger the webhook
133132
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
134133

135-
time.Sleep(1 * time.Second)
136-
137134
// 3. validate the webhook is triggered
138135
assert.EqualValues(t, string(webhook_module.HookEventCreate), triggeredEvent)
139136
assert.EqualValues(t, "repo1", payload.Repo.Name)
@@ -163,8 +160,6 @@ func Test_WebhookDelete(t *testing.T) {
163160
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
164161
testAPIDeleteBranch(t, "master2", http.StatusNoContent)
165162

166-
time.Sleep(1 * time.Second)
167-
168163
// 3. validate the webhook is triggered
169164
assert.EqualValues(t, "delete", triggeredEvent)
170165
assert.EqualValues(t, "repo1", payload.Repo.Name)
@@ -193,8 +188,6 @@ func Test_WebhookFork(t *testing.T) {
193188
// 2. trigger the webhook
194189
testRepoFork(t, session, "user2", "repo1", "user1", "repo1-fork", "master")
195190

196-
time.Sleep(1 * time.Second)
197-
198191
// 3. validate the webhook is triggered
199192
assert.EqualValues(t, "fork", triggeredEvent)
200193
assert.EqualValues(t, "repo1-fork", payload.Repo.Name)
@@ -224,8 +217,6 @@ func Test_WebhookIssueComment(t *testing.T) {
224217
issueURL := testNewIssue(t, session, "user2", "repo1", "Title2", "Description2")
225218
testIssueAddComment(t, session, issueURL, "issue title2 comment1", "")
226219

227-
time.Sleep(1 * time.Second)
228-
229220
// 3. validate the webhook is triggered
230221
assert.EqualValues(t, "issue_comment", triggeredEvent)
231222
assert.EqualValues(t, "created", payload.Action)
@@ -256,8 +247,6 @@ func Test_WebhookRelease(t *testing.T) {
256247
// 2. trigger the webhook
257248
createNewRelease(t, session, "/user2/repo1", "v0.0.99", "v0.0.99", false, false)
258249

259-
time.Sleep(1 * time.Second)
260-
261250
// 3. validate the webhook is triggered
262251
assert.EqualValues(t, "release", triggeredEvent)
263252
assert.EqualValues(t, "repo1", payload.Repository.Name)
@@ -287,8 +276,6 @@ func Test_WebhookPush(t *testing.T) {
287276
// 2. trigger the webhook
288277
testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")
289278

290-
time.Sleep(1 * time.Second)
291-
292279
// 3. validate the webhook is triggered
293280
assert.EqualValues(t, "push", triggeredEvent)
294281
assert.EqualValues(t, "repo1", payload.Repo.Name)
@@ -317,8 +304,6 @@ func Test_WebhookIssue(t *testing.T) {
317304
// 2. trigger the webhook
318305
testNewIssue(t, session, "user2", "repo1", "Title1", "Description1")
319306

320-
time.Sleep(1 * time.Second)
321-
322307
// 3. validate the webhook is triggered
323308
assert.EqualValues(t, "issues", triggeredEvent)
324309
assert.EqualValues(t, "opened", payload.Action)
@@ -350,8 +335,6 @@ func Test_WebhookPullRequest(t *testing.T) {
350335
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
351336
testCreatePullToDefaultBranch(t, session, repo1, repo1, "master2", "first pull request")
352337

353-
time.Sleep(1 * time.Second)
354-
355338
// 3. validate the webhook is triggered
356339
assert.EqualValues(t, "pull_request", triggeredEvent)
357340
assert.EqualValues(t, "repo1", payload.PullRequest.Base.Repository.Name)
@@ -381,8 +364,6 @@ func Test_WebhookWiki(t *testing.T) {
381364
// 2. trigger the webhook
382365
testAPICreateWikiPage(t, session, "user2", "repo1", "Test Wiki Page", http.StatusCreated)
383366

384-
time.Sleep(1 * time.Second)
385-
386367
// 3. validate the webhook is triggered
387368
assert.EqualValues(t, "wiki", triggeredEvent)
388369
assert.EqualValues(t, "created", payload.Action)
@@ -411,8 +392,6 @@ func Test_WebhookRepository(t *testing.T) {
411392
// 2. trigger the webhook
412393
testAPIOrgCreateRepo(t, session, "org3", "repo_new", http.StatusCreated)
413394

414-
time.Sleep(1 * time.Second)
415-
416395
// 3. validate the webhook is triggered
417396
assert.EqualValues(t, "repository", triggeredEvent)
418397
assert.EqualValues(t, "created", payload.Action)
@@ -445,8 +424,6 @@ func Test_WebhookPackage(t *testing.T) {
445424
AddTokenAuth(token)
446425
MakeRequest(t, req, http.StatusCreated)
447426

448-
time.Sleep(1 * time.Second)
449-
450427
// 3. validate the webhook is triggered
451428
assert.EqualValues(t, "package", triggeredEvent)
452429
assert.EqualValues(t, "created", payload.Action)

tests/mssql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ TYPE = immediate
2626
[queue.push_update]
2727
TYPE = immediate
2828

29+
[queue.webhook_sender]
30+
TYPE = immediate
31+
2932
[repository]
3033
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mssql/gitea-repositories
3134

tests/mysql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ TYPE = immediate
2828
[queue.push_update]
2929
TYPE = immediate
3030

31+
[queue.webhook_sender]
32+
TYPE = immediate
33+
3134
[repository]
3235
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mysql/gitea-repositories
3336

tests/pgsql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ TYPE = immediate
2727
[queue.push_update]
2828
TYPE = immediate
2929

30+
[queue.webhook_sender]
31+
TYPE = immediate
32+
3033
[repository]
3134
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-pgsql/gitea-repositories
3235

tests/sqlite.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ TYPE = immediate
2222
[queue.push_update]
2323
TYPE = immediate
2424

25+
[queue.webhook_sender]
26+
TYPE = immediate
27+
2528
[repository]
2629
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/gitea-repositories
2730

0 commit comments

Comments
 (0)