X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/d206de3a2e839ffbda9cbdb10a3ed93c4915fce3..4b063ca25798c78cc03d1d07f67b02c94c95248d:/botapi_test.go?ds=inline diff --git a/botapi_test.go b/botapi_test.go index 565f27d..b571c6a 100644 --- a/botapi_test.go +++ b/botapi_test.go @@ -141,7 +141,9 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { // fakeBot is a fake Bot API server for testBotToken. getUpdates returns the // added updates from the offset on, or waits a short time when there are none. -// The other methods succeed, unless fail gives an error answer for a call. +// The other methods succeed, unless fail gives an error answer for a call. An +// answer with HTTP 429 asks for a wait of one second. Fail runs with the mutex +// held. type fakeBot struct { *httptest.Server @@ -226,18 +228,22 @@ func (f *fakeBot) serve(w http.ResponseWriter, r *http.Request) { } f.mutex.Lock() - fail := f.fail - f.mutex.Unlock() - status, description := 0, "" - if fail != nil { - status, description = fail(call) + if f.fail != nil { + status, description = f.fail(call) } + f.mutex.Unlock() + if status != 0 { f.record(call) w.WriteHeader(status) - _, _ = fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":1}}`, status, description) + wait := 0 + if status == http.StatusTooManyRequests { + wait = 1 + } + + _, _ = fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":%d}}`, status, description, wait) return }