Skip to content

Commit

Permalink
Fix lint and use immediate queue on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 25, 2025
1 parent 646c76d commit f0142d0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions services/webhook/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func packageTestPayload() *api.PackagePayload {
AvatarURL: "http://localhost:3000/user1/avatar",
},
Repository: nil,
Organization: &api.User{
UserName: "org1",
Organization: &api.Organization{
Name: "org1",
AvatarURL: "http://localhost:3000/org1/avatar",
},
Package: &api.Package{
Expand Down
6 changes: 3 additions & 3 deletions services/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/gobwas/glob"
)

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

var webhookRequesters = map[webhook_module.HookType]WebhookRequester{}
var webhookRequesters = map[webhook_module.HookType]Requester{}

func RegisterWebhookRequester(hookType webhook_module.HookType, requester WebhookRequester) {
func RegisterWebhookRequester(hookType webhook_module.HookType, requester Requester) {
webhookRequesters[hookType] = requester
}

Expand Down
23 changes: 0 additions & 23 deletions tests/integration/repo_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/url"
"strings"
"testing"
"time"

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

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, string(webhook_module.HookEventCreate), triggeredEvent)
assert.EqualValues(t, "repo1", payload.Repo.Name)
Expand Down Expand Up @@ -163,8 +160,6 @@ func Test_WebhookDelete(t *testing.T) {
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
testAPIDeleteBranch(t, "master2", http.StatusNoContent)

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "delete", triggeredEvent)
assert.EqualValues(t, "repo1", payload.Repo.Name)
Expand Down Expand Up @@ -193,8 +188,6 @@ func Test_WebhookFork(t *testing.T) {
// 2. trigger the webhook
testRepoFork(t, session, "user2", "repo1", "user1", "repo1-fork", "master")

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "fork", triggeredEvent)
assert.EqualValues(t, "repo1-fork", payload.Repo.Name)
Expand Down Expand Up @@ -224,8 +217,6 @@ func Test_WebhookIssueComment(t *testing.T) {
issueURL := testNewIssue(t, session, "user2", "repo1", "Title2", "Description2")
testIssueAddComment(t, session, issueURL, "issue title2 comment1", "")

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "issue_comment", triggeredEvent)
assert.EqualValues(t, "created", payload.Action)
Expand Down Expand Up @@ -256,8 +247,6 @@ func Test_WebhookRelease(t *testing.T) {
// 2. trigger the webhook
createNewRelease(t, session, "/user2/repo1", "v0.0.99", "v0.0.99", false, false)

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "release", triggeredEvent)
assert.EqualValues(t, "repo1", payload.Repository.Name)
Expand Down Expand Up @@ -287,8 +276,6 @@ func Test_WebhookPush(t *testing.T) {
// 2. trigger the webhook
testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "push", triggeredEvent)
assert.EqualValues(t, "repo1", payload.Repo.Name)
Expand Down Expand Up @@ -317,8 +304,6 @@ func Test_WebhookIssue(t *testing.T) {
// 2. trigger the webhook
testNewIssue(t, session, "user2", "repo1", "Title1", "Description1")

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "issues", triggeredEvent)
assert.EqualValues(t, "opened", payload.Action)
Expand Down Expand Up @@ -350,8 +335,6 @@ func Test_WebhookPullRequest(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
testCreatePullToDefaultBranch(t, session, repo1, repo1, "master2", "first pull request")

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "pull_request", triggeredEvent)
assert.EqualValues(t, "repo1", payload.PullRequest.Base.Repository.Name)
Expand Down Expand Up @@ -381,8 +364,6 @@ func Test_WebhookWiki(t *testing.T) {
// 2. trigger the webhook
testAPICreateWikiPage(t, session, "user2", "repo1", "Test Wiki Page", http.StatusCreated)

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "wiki", triggeredEvent)
assert.EqualValues(t, "created", payload.Action)
Expand Down Expand Up @@ -411,8 +392,6 @@ func Test_WebhookRepository(t *testing.T) {
// 2. trigger the webhook
testAPIOrgCreateRepo(t, session, "org3", "repo_new", http.StatusCreated)

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "repository", triggeredEvent)
assert.EqualValues(t, "created", payload.Action)
Expand Down Expand Up @@ -445,8 +424,6 @@ func Test_WebhookPackage(t *testing.T) {
AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated)

time.Sleep(1 * time.Second)

// 3. validate the webhook is triggered
assert.EqualValues(t, "package", triggeredEvent)
assert.EqualValues(t, "created", payload.Action)
Expand Down
3 changes: 3 additions & 0 deletions tests/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ TYPE = immediate
[queue.push_update]
TYPE = immediate

[queue.webhook_sender]
TYPE = immediate

[repository]
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mssql/gitea-repositories

Expand Down
3 changes: 3 additions & 0 deletions tests/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ TYPE = immediate
[queue.push_update]
TYPE = immediate

[queue.webhook_sender]
TYPE = immediate

[repository]
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mysql/gitea-repositories

Expand Down
3 changes: 3 additions & 0 deletions tests/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ TYPE = immediate
[queue.push_update]
TYPE = immediate

[queue.webhook_sender]
TYPE = immediate

[repository]
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-pgsql/gitea-repositories

Expand Down
3 changes: 3 additions & 0 deletions tests/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ TYPE = immediate
[queue.push_update]
TYPE = immediate

[queue.webhook_sender]
TYPE = immediate

[repository]
ROOT = {{REPO_TEST_DIR}}tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/gitea-repositories

Expand Down

0 comments on commit f0142d0

Please sign in to comment.