Skip to content

Commit

Permalink
Merge pull request #356 from unnoy/fix-invalid-method-test-webhook-en…
Browse files Browse the repository at this point in the history
…dpoint

fix: Use POST method for Test Webhook endpoiont
  • Loading branch information
Yang-33 committed Sep 22, 2023
2 parents 796bef3 + 283255b commit 0706a9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion linebot/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (call *TestWebhook) WithContext(ctx context.Context) *TestWebhook {

// Do method
func (call *TestWebhook) Do() (*TestWebhookResponse, error) {
res, err := call.c.get(call.ctx, call.c.endpointBase, call.endpoint, nil)
res, err := call.c.post(call.ctx, call.endpoint, nil)
if err != nil {
return nil, err
}
Expand Down
26 changes: 24 additions & 2 deletions linebot/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,28 @@ func TestTestWebhook(t *testing.T) {
},
},
},
{
Label: "Failed with timeout",
ResponseCode: 200,
Response: []byte(`{
"success": false,
"timestamp": "2023-09-12T14:00:10.015Z",
"statusCode": 0,
"reason": "REQUEST_TIMEOUT",
"detail": "Request timeout: https://example.com/"
}`),
Want: want{
URLPath: APIEndpointTestWebhook,
RequestBody: []byte(""),
Response: &TestWebhookResponse{
Success: false,
Timestamp: time.Date(2023, time.September, 12, 14, 00, 10, int(15*time.Millisecond), time.UTC),
StatusCode: 0,
Reason: "REQUEST_TIMEOUT",
Detail: "Request timeout: https://example.com/",
},
},
},
{
Label: "Internal server error",
ResponseCode: 500,
Expand Down Expand Up @@ -1897,8 +1919,8 @@ func TestTestWebhook(t *testing.T) {
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
tc := testCases[currentTestIdx]
if r.Method != http.MethodGet {
t.Errorf("Method %s; want %s", r.Method, http.MethodGet)
if r.Method != http.MethodPost {
t.Errorf("Method %s; want %s", r.Method, http.MethodPost)
}
if r.URL.Path != tc.Want.URLPath {
t.Errorf("URLPath %s; want %s", r.URL.Path, tc.Want.URLPath)
Expand Down

0 comments on commit 0706a9a

Please sign in to comment.