mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/modules/structs"
|
|
"gitea.dev/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTestHookValidation(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
cases := []struct {
|
|
name string
|
|
hookType string
|
|
config map[string]string
|
|
status int
|
|
}{
|
|
{"Test Validation", "gitea", map[string]string{"content_type": "json", "url": "https://example.com/webhook"}, 0}, // not written yet
|
|
{"Test Validation with invalid URL", "gitea", map[string]string{"content_type": "json", "url": "example.com/webhook"}, http.StatusUnprocessableEntity},
|
|
{"Test Validation with invalid webhook type", "unknown", map[string]string{"content_type": "json", "url": "example.com/webhook"}, http.StatusUnprocessableEntity},
|
|
{"Test Validation with empty content type", "unknown", map[string]string{"url": "https://example.com/webhook"}, http.StatusUnprocessableEntity},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/hooks")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
|
|
checkCreateHookOption(ctx, &structs.CreateHookOption{
|
|
Type: tc.hookType,
|
|
Config: tc.config,
|
|
})
|
|
assert.Equal(t, tc.status, ctx.Resp.WrittenStatus())
|
|
})
|
|
}
|
|
}
|