]> git.giacomolli.uk - onechat/blobdiff - telegram_fake_helper_test.go
Prove direct cancellation during a pending sync
[onechat] / telegram_fake_helper_test.go
index 6ca755e6545383cefe0b4a3d4066aea784587283..5ed4e2d43d60137938f45ee792f1a5f1a13d1c24 100644 (file)
@@ -101,7 +101,9 @@ func (f *TelegramFake) serve(w http.ResponseWriter, r *http.Request) {
                        return
                }
 
                        return
                }
 
-               _, _ = w.Write(data)
+               // The client can cancel a media request before this reply is
+               // written.
+               w.Write(data) // nolint: errcheck
 
                return
        }
 
                return
        }
@@ -188,7 +190,9 @@ func (f *TelegramFake) serve(w http.ResponseWriter, r *http.Request) {
                        wait = 1
                }
 
                        wait = 1
                }
 
-               _, _ = fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":%d}}`, status, description, wait)
+               // A test can cancel the request after the handler selects its
+               // reply.
+               fmt.Fprintf(w, `{"ok":false,"error_code":%d,"description":%q,"parameters":{"retry_after":%d}}`, status, description, wait) // nolint: errcheck
 
                return
        }
 
                return
        }
@@ -197,7 +201,8 @@ func (f *TelegramFake) serve(w http.ResponseWriter, r *http.Request) {
        f.record(call)
 
        if method == "getFile" {
        f.record(call)
 
        if method == "getFile" {
-               _ = json.NewEncoder(w).Encode(map[string]any{
+               // A cancelled client does not need a response body.
+               json.NewEncoder(w).Encode(map[string]any{ // nolint: errcheck
                        "ok":     true,
                        "result": map[string]any{"file_path": params["file_id"]},
                })
                        "ok":     true,
                        "result": map[string]any{"file_path": params["file_id"]},
                })
@@ -206,7 +211,9 @@ func (f *TelegramFake) serve(w http.ResponseWriter, r *http.Request) {
        }
 
        if method != "getUpdates" {
        }
 
        if method != "getUpdates" {
-               _, _ = io.WriteString(w, `{"ok":true,"result":true}`)
+               // A cancelled client does not need a response body.
+               io.WriteString(w, `{"ok":true,"result":true}`) // nolint: errcheck
+
                return
        }
 
                return
        }
 
@@ -222,7 +229,8 @@ func (f *TelegramFake) serve(w http.ResponseWriter, r *http.Request) {
                updates = f.from(offset)
        }
 
                updates = f.from(offset)
        }
 
-       _ = json.NewEncoder(w).Encode(map[string]any{
+       // A cancelled client does not need a response body.
+       json.NewEncoder(w).Encode(map[string]any{ // nolint: errcheck
                "ok":     true,
                "result": updates,
        })
                "ok":     true,
                "result": updates,
        })