X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/7088b82414bdf947a6f88918c0a7b2c7fb0c53ef..4c199e7d93b6a4529ed5956807911b5f6c5489a7:/telegram_api_test.go?ds=sidebyside diff --git a/telegram_api_test.go b/telegram_api_test.go index 9b66aa4..98aa232 100644 --- a/telegram_api_test.go +++ b/telegram_api_test.go @@ -123,6 +123,7 @@ func TestSendCallsTimeOutOnAStalledConnection(t *testing.T) { 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) @@ -155,6 +156,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { 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, @@ -165,6 +167,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { name: "server error page is retried", reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusBadGateway) + _, _ = io.WriteString(w, "bad gateway") }, retry: true, @@ -174,6 +177,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { 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, @@ -183,6 +187,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { 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, @@ -193,6 +198,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { 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, @@ -203,6 +209,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { name: "not found page of a proxy is not a refusal", reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusNotFound) + _, _ = io.WriteString(w, "not found") }, retry: false, @@ -220,7 +227,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { tc.reply(w) })) t.Cleanup(server.Close)