]> git.giacomolli.uk - onechat/blobdiff - telegram_api_test.go
Deliver messages between parent and child agents
[onechat] / telegram_api_test.go
index 9b66aa45937984a3b9397332974e7e75aefff1aa..98aa232a9539894007921f177c3622c81a88462d 100644 (file)
@@ -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)
                        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)
                        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)
                        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,
                                _, _ = 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)
                        name: "server error page is retried",
                        reply: func(w http.ResponseWriter) {
                                w.WriteHeader(http.StatusBadGateway)
+
                                _, _ = io.WriteString(w, "<html>bad gateway</html>")
                        },
                        retry:     true,
                                _, _ = io.WriteString(w, "<html>bad gateway</html>")
                        },
                        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)
                        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,
                                _, _ = 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)
                        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,
                                _, _ = 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)
                        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,
                                _, _ = 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)
                        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,
                                _, _ = io.WriteString(w, "<html>not found</html>")
                        },
                        retry:     false,
@@ -220,7 +227,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) {
 
        for _, tc := range testCases {
                t.Run(tc.name, func(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)
                                tc.reply(w)
                        }))
                        t.Cleanup(server.Close)