X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/add3cf6416e33c24331fd1e90e99284f44d2aae2..6c7859cfea123479aba046614ee81028651ddaf5:/telegram_api_test.go?ds=sidebyside diff --git a/telegram_api_test.go b/telegram_api_test.go index ca11274..4395d6b 100644 --- a/telegram_api_test.go +++ b/telegram_api_test.go @@ -149,9 +149,13 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { name: "refused connection is retried", reply: func(w http.ResponseWriter) { conn, _, err := http.NewResponseController(w).Hijack() - if err == nil { - _ = conn.Close() + if err != nil { + panic(err) } + + // This forced disconnect has no response or + // retry after close. + conn.Close() // nolint: errcheck }, retry: true, errorText: "no answer", @@ -161,7 +165,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { 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}}`) + _, err := io.WriteString(w, `{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 3","parameters":{"retry_after":3}}`) + if err != nil { + panic(err) + } }, retry: true, wait: 3 * time.Second, @@ -172,7 +179,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusBadGateway) - _, _ = io.WriteString(w, "bad gateway") + _, err := io.WriteString(w, "bad gateway") + if err != nil { + panic(err) + } }, retry: true, errorText: "502 Bad Gateway", @@ -182,7 +192,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusUnauthorized) - _, _ = io.WriteString(w, `{"ok":false,"error_code":401,"description":"Unauthorized: bot`+telegramTestToken+`"}`) + _, err := io.WriteString(w, `{"ok":false,"error_code":401,"description":"Unauthorized: bot`+telegramTestToken+`"}`) + if err != nil { + panic(err) + } }, retry: false, errorText: "Unauthorized: botTOKEN", @@ -192,7 +205,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusBadRequest) - _, _ = io.WriteString(w, `{"ok":false,"error_code":400,"description":"Bad Request: can't parse"}`) + _, err := io.WriteString(w, `{"ok":false,"error_code":400,"description":"Bad Request: can't parse"}`) + if err != nil { + panic(err) + } }, retry: false, rejected: true, @@ -203,7 +219,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusNotFound) - _, _ = io.WriteString(w, `{"ok":false,"error_code":404,"description":"Not Found"}`) + _, err := io.WriteString(w, `{"ok":false,"error_code":404,"description":"Not Found"}`) + if err != nil { + panic(err) + } }, retry: false, rejected: true, @@ -214,7 +233,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { reply: func(w http.ResponseWriter) { w.WriteHeader(http.StatusNotFound) - _, _ = io.WriteString(w, "not found") + _, err := io.WriteString(w, "not found") + if err != nil { + panic(err) + } }, retry: false, errorText: "404 Not Found", @@ -222,7 +244,10 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { { name: "broken answer is retried", reply: func(w http.ResponseWriter) { - _, _ = io.WriteString(w, `{"ok":`) + _, err := io.WriteString(w, `{"ok":`) + if err != nil { + panic(err) + } }, retry: true, errorText: "invalid JSON", @@ -234,6 +259,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { tc.reply(w) })) + t.Cleanup(server.Close) err := newTelegramAPI(server.URL, telegramTestToken).SendMessage(t.Context(), telegramTestOwner, "hi", nil)