mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-06 23:38:48 +02:00
Avoid webhook test fixtures affect other tests (be triggered) Also fixed more testing problems including path init, global config pollution & conflict --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/models/webhook"
|
|
"code.gitea.io/gitea/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTestHook(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
hook := &webhook.Webhook{
|
|
RepoID: 1,
|
|
URL: "https://www.example.com/test_hook",
|
|
ContentType: webhook.ContentTypeJSON,
|
|
Events: `{"push_only":true}`,
|
|
IsActive: true,
|
|
}
|
|
assert.NoError(t, db.Insert(t.Context(), hook))
|
|
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/wiki/_pages")
|
|
ctx.SetPathParam("id", strconv.FormatInt(hook.ID, 10))
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
TestHook(ctx)
|
|
assert.Equal(t, http.StatusNoContent, ctx.Resp.WrittenStatus())
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &webhook.HookTask{
|
|
HookID: hook.ID,
|
|
}, unittest.Cond("is_delivered=?", false))
|
|
}
|