]> git.giacomolli.uk - onechat/blobdiff - telegram_test.go
Convert reply Markdown to Telegram entities
[onechat] / telegram_test.go
index d18e7948e2b27f430b4fec071a6fe7a1391aa6ae..b1cd6ae7348b9c9aedccb77678330fa55a12d54a 100644 (file)
@@ -202,6 +202,29 @@ func TestBotTriesAgainAfterFailures(t *testing.T) {
        require.NotContains(t, logs.String(), testBotToken)
 }
 
+func TestDeliverTriesAgainAfterATimeout(t *testing.T) {
+       telegram := newFakeBot(t)
+       stalls := 1
+       telegram.stall = func(call fakeBotCall) bool {
+               if call.method != "sendMessage" || stalls == 0 {
+                       return false
+               }
+
+               stalls--
+
+               return true
+       }
+
+       bot, logs := startTestBot(t, telegram)
+       bot.api.sendTimeout = 50 * time.Millisecond
+       bot.deliver(t.Context(), "hello")
+
+       require.Equal(t, []string{"hello"}, telegram.Sent())
+       require.Len(t, telegram.Calls(), 2)
+       require.Contains(t, logs.String(), "no valid answer")
+       require.NotContains(t, logs.String(), testBotToken)
+}
+
 func TestBotLogsNoTokenWhenTheNetworkFails(t *testing.T) {
        telegram := newFakeBot(t)
        telegram.Close()