9a5720e8ad
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/unittest"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/structs"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTestHookValidation(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
t.Run("Test Validation", 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: "gitea",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "https://example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, 0, ctx.Resp.WrittenStatus()) // not written yet
|
|
})
|
|
|
|
t.Run("Test Validation with invalid URL", 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: "gitea",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
|
|
t.Run("Test Validation with invalid webhook type", 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: "unknown",
|
|
Config: map[string]string{
|
|
"content_type": "json",
|
|
"url": "example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
|
|
t.Run("Test Validation with empty content type", 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: "unknown",
|
|
Config: map[string]string{
|
|
"url": "https://example.com/webhook",
|
|
},
|
|
})
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
})
|
|
}
|