Files
gitea/models/webhook/webhook_system_test.go
Copilot 9b9fb95559 Improve testing init, clean up webhook tests (#37412)
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>
2026-04-25 18:55:18 +00:00

38 lines
1.2 KiB
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package webhook
import (
"testing"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/optional"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestListSystemWebhookOptions(t *testing.T) {
hookSystem := unittest.AssertExistsAndLoadBean(t, &Webhook{URL: "https://www.example.com/system"})
hookDefault := unittest.AssertExistsAndLoadBean(t, &Webhook{URL: "https://www.example.com/default"})
opts := ListSystemWebhookOptions{IsSystem: optional.None[bool]()}
hooks, _, err := GetGlobalWebhooks(t.Context(), &opts)
require.NoError(t, err)
require.Len(t, hooks, 2)
assert.Equal(t, hookSystem.ID, hooks[0].ID)
assert.Equal(t, hookDefault.ID, hooks[1].ID)
opts.IsSystem = optional.Some(true)
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
require.NoError(t, err)
require.Len(t, hooks, 1)
assert.Equal(t, hookSystem.ID, hooks[0].ID)
opts.IsSystem = optional.Some(false)
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
require.NoError(t, err)
require.Len(t, hooks, 1)
assert.Equal(t, hookDefault.ID, hooks[0].ID)
}