api.sendTimeout = time.Hour
ctx, cancel := context.WithCancel(t.Context())
time.AfterFunc(50*time.Millisecond, cancel)
+
start = time.Now()
err = tc.send(ctx, api)
require.Error(t, err)
name: "rate limit waits as asked",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusTooManyRequests)
+
_, _ = io.WriteString(w, `{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 3","parameters":{"retry_after":3}}`)
},
retry: true,
name: "server error page is retried",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadGateway)
+
_, _ = io.WriteString(w, "<html>bad gateway</html>")
},
retry: true,
name: "token echoed in a description is hidden",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusUnauthorized)
+
_, _ = io.WriteString(w, `{"ok":false,"error_code":401,"description":"Unauthorized: bot`+telegramTestToken+`"}`)
},
retry: false,
name: "bad request is a refusal",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadRequest)
+
_, _ = io.WriteString(w, `{"ok":false,"error_code":400,"description":"Bad Request: can't parse"}`)
},
retry: false,
name: "unknown method is a refusal",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
+
_, _ = io.WriteString(w, `{"ok":false,"error_code":404,"description":"Not Found"}`)
},
retry: false,
name: "not found page of a proxy is not a refusal",
reply: func(w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
+
_, _ = io.WriteString(w, "<html>not found</html>")
},
retry: false,