add test for webhook default method

https://github.com/go-gitea/gitea/pull/29690
This commit is contained in:
oliverpool 2024-03-11 09:42:58 +01:00 committed by Earl Warren
parent c243323b4a
commit ed6f724a5d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -234,6 +234,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
type hookCase struct {
gotBody chan []byte
expectedMethod string
}
cases := map[string]hookCase{
@ -257,6 +258,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
},
webhook_module.MATRIX: {
gotBody: make(chan []byte, 1),
expectedMethod: "PUT",
},
webhook_module.WECHATWORK: {
gotBody: make(chan []byte, 1),
@ -271,6 +273,13 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
typ := strings.Split(r.URL.Path, "/")[1] // take first segment (after skipping leading slash)
hc := cases[typ]
if hc.expectedMethod != "" {
assert.Equal(t, hc.expectedMethod, r.Method, r.URL.Path)
} else {
assert.Equal(t, "POST", r.Method, r.URL.Path)
}
require.NotNil(t, hc.gotBody, r.URL.Path)
body, err := io.ReadAll(r.Body)
assert.NoError(t, err)
@ -293,7 +302,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
IsActive: true,
Type: typ,
URL: s.URL + "/" + typ,
HTTPMethod: "POST",
HTTPMethod: "", // should fallback to POST, when left unset by the specific hook
ContentType: 0, // set to 0 so that falling back to default request fails with "invalid content type"
Meta: "{}",
}