add test for webhook default method
https://github.com/go-gitea/gitea/pull/29690
This commit is contained in:
parent
c243323b4a
commit
ed6f724a5d
|
@ -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: "{}",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue