mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use test context in tests and new loop system in benchmarks (#33648)
Replace all contexts in tests with go1.24 t.Context() --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -118,7 +117,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
@@ -185,7 +184,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
@@ -211,7 +210,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
@@ -280,7 +279,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
||||
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||
|
||||
select {
|
||||
case gotBody := <-cases[typ].gotBody:
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
@@ -236,7 +235,7 @@ func TestDingTalkJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newDingtalkRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newDingtalkRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -303,7 +302,7 @@ func TestDiscordJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newDiscordRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newDiscordRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -177,7 +176,7 @@ func TestFeishuJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newFeishuRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newFeishuRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -211,7 +210,7 @@ func TestMatrixJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newMatrixRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newMatrixRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -439,7 +438,7 @@ func TestMSTeamsJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newMSTeamsRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newMSTeamsRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -164,7 +163,7 @@ func TestPackagistJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
@@ -199,7 +198,7 @@ func TestPackagistEmptyPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -178,7 +177,7 @@ func TestSlackJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newSlackRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newSlackRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
@@ -195,7 +194,7 @@ func TestTelegramJSONPayload(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
req, reqBody, err := newTelegramRequest(context.Background(), hook, task)
|
||||
req, reqBody, err := newTelegramRequest(t.Context(), hook, task)
|
||||
require.NotNil(t, req)
|
||||
require.NotNil(t, reqBody)
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user