// 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
}
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
}