aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-fetch--definitions-timeout-returns-unreachable.el
blob: 8067ddebb26dbeefe53325b5ee64c04b0a22c87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;; test-gloss-fetch--definitions-timeout-returns-unreachable.el --- timeout path -*- lexical-binding: t -*-

;; SPDX-License-Identifier: GPL-3.0-or-later

;;; Commentary:
;; A timeout (or any other transport-level failure) makes
;; `url-retrieve-synchronously' return nil; the source maps to
;; :unreachable, which joins :failed at the rollup.

;;; Code:

(require 'ert)
(require 'cl-lib)
(require 'gloss-fetch)
(require 'testutil-gloss-fetch)

(ert-deftest test-gloss-fetch-definitions-timeout-rolls-up-to-failed ()
  "Normal: nil from url-retrieve-synchronously rolls up to :failed."
  (gloss-fetch-test--with-mocked-url
      (lambda (_url) nil)
    (let ((result (gloss-fetch-definitions "anaphora")))
      (should (eq (car result) :empty))
      (should (member 'wiktionary (plist-get (cdr result) :failed)))
      (should-not (plist-get (cdr result) :no-defs)))))

(ert-deftest test-gloss-fetch-definitions-timeout-marks-source-unreachable ()
  "Boundary: per-source status is :unreachable, distinct from :server-error."
  (gloss-fetch-test--with-mocked-url
      (lambda (_url) nil)
    (let* ((per-source (gloss-fetch--collect "anaphora"))
           (entry (car per-source)))
      (should (eq (plist-get entry :source) 'wiktionary))
      (should (eq (plist-get entry :status) :unreachable)))))

(ert-deftest test-gloss-fetch-definitions-error-signal-marks-source-unreachable ()
  "Error: a signaled error inside url-retrieve-synchronously also yields :unreachable."
  (gloss-fetch-test--with-mocked-url
      (lambda (_url) (error "Connection refused"))
    (let* ((per-source (gloss-fetch--collect "anaphora"))
           (entry (car per-source)))
      (should (eq (plist-get entry :status) :unreachable)))))

(provide 'test-gloss-fetch--definitions-timeout-returns-unreachable)
;;; test-gloss-fetch--definitions-timeout-returns-unreachable.el ends here