mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-26 02:03:30 +02:00
Fix webhook
This commit is contained in:
@@ -130,8 +130,6 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
originalConfig := map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
}
|
||||
@@ -149,37 +147,18 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://new.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Update secret and auth header",
|
||||
name: "Update secret",
|
||||
updates: map[string]string{
|
||||
"secret": "new-secret",
|
||||
"authorization_header": "X-Token: new-token",
|
||||
},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "new-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "X-Token: new-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Clear branch filter",
|
||||
updates: map[string]string{
|
||||
"branch_filter": "",
|
||||
},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
@@ -190,8 +169,6 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
@@ -217,6 +194,61 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateBranchFilterAndAuthHeaderHandling(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
originalBranchFilter string
|
||||
originalAuthHeader string
|
||||
setBranchFilter bool
|
||||
newBranchFilter string
|
||||
setAuthorizationHeader bool
|
||||
newAuthHeader string
|
||||
expectedBranchFilter string
|
||||
expectedAuthHeader string
|
||||
}{
|
||||
{
|
||||
name: "Preserve values",
|
||||
originalBranchFilter: "main",
|
||||
originalAuthHeader: "Bearer old-token",
|
||||
expectedBranchFilter: "main",
|
||||
expectedAuthHeader: "Bearer old-token",
|
||||
},
|
||||
{
|
||||
name: "Update branch filter",
|
||||
originalBranchFilter: "main",
|
||||
setBranchFilter: true,
|
||||
newBranchFilter: "develop",
|
||||
expectedBranchFilter: "develop",
|
||||
expectedAuthHeader: "",
|
||||
},
|
||||
{
|
||||
name: "Update authorization header",
|
||||
originalAuthHeader: "Bearer old-token",
|
||||
setAuthorizationHeader: true,
|
||||
newAuthHeader: "X-Token: new-token",
|
||||
expectedBranchFilter: "",
|
||||
expectedAuthHeader: "X-Token: new-token",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
branchFilter := tt.originalBranchFilter
|
||||
if tt.setBranchFilter {
|
||||
branchFilter = tt.newBranchFilter
|
||||
}
|
||||
|
||||
authHeader := tt.originalAuthHeader
|
||||
if tt.setAuthorizationHeader {
|
||||
authHeader = tt.newAuthHeader
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.expectedBranchFilter, branchFilter)
|
||||
assert.Equal(t, tt.expectedAuthHeader, authHeader)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateEventsHandling(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user