mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-19 13:51:38 +00:00
Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/52d595da-6991-440e-9cae-a4e070410229 Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
58 lines
1.5 KiB
Go
58 lines
1.5 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"
|
|
)
|
|
|
|
func TestListSystemWebhookOptions(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
systemHook := &Webhook{
|
|
URL: "https://www.example.com/system",
|
|
ContentType: ContentTypeJSON,
|
|
Events: `{"push_only":true}`,
|
|
IsActive: true,
|
|
IsSystemWebhook: true,
|
|
}
|
|
assert.NoError(t, CreateWebhook(t.Context(), systemHook))
|
|
|
|
defaultHook := &Webhook{
|
|
URL: "https://www.example.com/default",
|
|
ContentType: ContentTypeJSON,
|
|
Events: `{"push_only":true}`,
|
|
IsActive: true,
|
|
IsSystemWebhook: false,
|
|
}
|
|
assert.NoError(t, CreateWebhook(t.Context(), defaultHook))
|
|
|
|
opts := ListSystemWebhookOptions{IsSystem: optional.None[bool]()}
|
|
hooks, _, err := GetGlobalWebhooks(t.Context(), &opts)
|
|
assert.NoError(t, err)
|
|
if assert.Len(t, hooks, 2) {
|
|
assert.Equal(t, systemHook.ID, hooks[0].ID)
|
|
assert.Equal(t, defaultHook.ID, hooks[1].ID)
|
|
}
|
|
|
|
opts.IsSystem = optional.Some(true)
|
|
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
|
|
assert.NoError(t, err)
|
|
if assert.Len(t, hooks, 1) {
|
|
assert.Equal(t, systemHook.ID, hooks[0].ID)
|
|
}
|
|
|
|
opts.IsSystem = optional.Some(false)
|
|
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
|
|
assert.NoError(t, err)
|
|
if assert.Len(t, hooks, 1) {
|
|
assert.Equal(t, defaultHook.ID, hooks[0].ID)
|
|
}
|
|
}
|