This commit is contained in:
Lunny Xiao
2026-04-20 12:34:52 -07:00
parent 469a6d3466
commit ab7dc97518
3 changed files with 48 additions and 48 deletions

View File

@@ -148,11 +148,11 @@ func TestWebhookConfigConstruction(t *testing.T) {
func TestWebhookCreateOptions(t *testing.T) { func TestWebhookCreateOptions(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
webhookType string webhookType string
events []string events []string
active bool active bool
config map[string]string config map[string]string
branchFilter string branchFilter string
authHeader string authHeader string
}{ }{

View File

@@ -128,10 +128,10 @@ func TestUpdateActiveInactiveFlags(t *testing.T) {
func TestUpdateConfigPreservation(t *testing.T) { func TestUpdateConfigPreservation(t *testing.T) {
// Test that existing configuration is preserved when not updated // Test that existing configuration is preserved when not updated
originalConfig := map[string]string{ originalConfig := map[string]string{
"url": "https://old.example.com/webhook", "url": "https://old.example.com/webhook",
"secret": "old-secret", "secret": "old-secret",
"http_method": "post", "http_method": "post",
"content_type": "json", "content_type": "json",
} }
tests := []struct { tests := []struct {
@@ -145,32 +145,32 @@ func TestUpdateConfigPreservation(t *testing.T) {
"url": "https://new.example.com/webhook", "url": "https://new.example.com/webhook",
}, },
expectedConfig: map[string]string{ expectedConfig: map[string]string{
"url": "https://new.example.com/webhook", "url": "https://new.example.com/webhook",
"secret": "old-secret", "secret": "old-secret",
"http_method": "post", "http_method": "post",
"content_type": "json", "content_type": "json",
}, },
}, },
{ {
name: "Update secret", name: "Update secret",
updates: map[string]string{ updates: map[string]string{
"secret": "new-secret", "secret": "new-secret",
}, },
expectedConfig: map[string]string{ expectedConfig: map[string]string{
"url": "https://old.example.com/webhook", "url": "https://old.example.com/webhook",
"secret": "new-secret", "secret": "new-secret",
"http_method": "post", "http_method": "post",
"content_type": "json", "content_type": "json",
}, },
}, },
{ {
name: "No updates", name: "No updates",
updates: map[string]string{}, updates: map[string]string{},
expectedConfig: map[string]string{ expectedConfig: map[string]string{
"url": "https://old.example.com/webhook", "url": "https://old.example.com/webhook",
"secret": "old-secret", "secret": "old-secret",
"http_method": "post", "http_method": "post",
"content_type": "json", "content_type": "json",
}, },
}, },
} }
@@ -214,12 +214,12 @@ func TestUpdateBranchFilterAndAuthHeaderHandling(t *testing.T) {
expectedAuthHeader: "Bearer old-token", expectedAuthHeader: "Bearer old-token",
}, },
{ {
name: "Update branch filter", name: "Update branch filter",
originalBranchFilter: "main", originalBranchFilter: "main",
setBranchFilter: true, setBranchFilter: true,
newBranchFilter: "develop", newBranchFilter: "develop",
expectedBranchFilter: "develop", expectedBranchFilter: "develop",
expectedAuthHeader: "", expectedAuthHeader: "",
}, },
{ {
name: "Update authorization header", name: "Update authorization header",

View File

@@ -81,17 +81,17 @@ func TestWebhookDetails(t *testing.T) {
ID: 123, ID: 123,
Type: "gitea", Type: "gitea",
Config: map[string]string{ Config: map[string]string{
"url": "https://example.com/webhook", "url": "https://example.com/webhook",
"content_type": "json", "content_type": "json",
"http_method": "post", "http_method": "post",
"secret": "secret-value", "secret": "secret-value",
}, },
BranchFilter: "main,develop", BranchFilter: "main,develop",
AuthorizationHeader: "Bearer token123", AuthorizationHeader: "Bearer token123",
Events: []string{"push", "pull_request", "issues"}, Events: []string{"push", "pull_request", "issues"},
Active: true, Active: true,
Created: now.Add(-24 * time.Hour), Created: now.Add(-24 * time.Hour),
Updated: now, Updated: now,
}, },
}, },
{ {
@@ -238,10 +238,10 @@ func TestWebhookConfigHandling(t *testing.T) {
{ {
name: "Config with all fields", name: "Config with all fields",
config: map[string]string{ config: map[string]string{
"url": "https://example.com/webhook", "url": "https://example.com/webhook",
"secret": "my-secret", "secret": "my-secret",
"content_type": "json", "content_type": "json",
"http_method": "post", "http_method": "post",
}, },
expectedURL: "https://example.com/webhook", expectedURL: "https://example.com/webhook",
hasSecret: true, hasSecret: true,
@@ -339,17 +339,17 @@ func TestWebhookDetailsFormatting(t *testing.T) {
ID: 123, ID: 123,
Type: "gitea", Type: "gitea",
Config: map[string]string{ Config: map[string]string{
"url": "https://example.com/webhook", "url": "https://example.com/webhook",
"content_type": "json", "content_type": "json",
"http_method": "post", "http_method": "post",
"secret": "secret-value", "secret": "secret-value",
}, },
BranchFilter: "main,develop", BranchFilter: "main,develop",
AuthorizationHeader: "Bearer token123", AuthorizationHeader: "Bearer token123",
Events: []string{"push", "pull_request", "issues"}, Events: []string{"push", "pull_request", "issues"},
Active: true, Active: true,
Created: now.Add(-24 * time.Hour), Created: now.Add(-24 * time.Hour),
Updated: now, Updated: now,
} }
// Test that all expected fields are included in details // Test that all expected fields are included in details