From dc0db0f0e12d8af6d1d54a5dde1cd16cf890a33d Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 28 Apr 2026 18:10:17 -0500 Subject: test: add gloss-fetch test suite (red phase) Eight test files cover the network layer's public and internal contract. The boundary mock is `url-retrieve-synchronously', wrapped by a small `testutil-gloss-fetch' helper that builds response buffers in the shape the url library returns. Tests cover the 200 happy paths (anaphora and SBIR fixtures), 404 to :no-defs, 5xx and 4xx-other and malformed JSON to :server-error, 429 to :rate-limited, nil-from-url to :unreachable, the libxml availability probe (one-shot, signals user-error when absent), the registry walker ordering, and the pure HTML strip helper across N/B/E. Tests fail on missing `gloss-fetch--*' functions, as expected for red phase. --- ...-fetch--definitions-500-returns-server-error.el | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test-gloss-fetch--definitions-500-returns-server-error.el (limited to 'tests/test-gloss-fetch--definitions-500-returns-server-error.el') diff --git a/tests/test-gloss-fetch--definitions-500-returns-server-error.el b/tests/test-gloss-fetch--definitions-500-returns-server-error.el new file mode 100644 index 0000000..e81efe2 --- /dev/null +++ b/tests/test-gloss-fetch--definitions-500-returns-server-error.el @@ -0,0 +1,55 @@ +;;; test-gloss-fetch--definitions-500-returns-server-error.el --- 5xx path -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; HTTP 5xx, malformed JSON, schema mismatch, and 4xx other than 404/429 +;; all roll up to :server-error. When every source fails this way, the +;; user-facing rollup is :empty with the source listed under :failed. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'gloss-fetch) +(require 'testutil-gloss-fetch) + +(ert-deftest test-gloss-fetch-definitions-500-rolls-up-to-failed () + "Normal: HTTP 500 maps the source to :server-error (in :failed)." + (gloss-fetch-test--with-mocked-url + (lambda (_url) + (gloss-fetch-test--status-response "HTTP/1.1 500 Internal Server Error" + "Server is sad.")) + (let ((result (gloss-fetch-definitions "anaphora"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :failed))) + (should-not (plist-get result :no-defs))))) + +(ert-deftest test-gloss-fetch-definitions-503-rolls-up-to-failed () + "Normal: HTTP 503 maps the source to :server-error (in :failed)." + (gloss-fetch-test--with-mocked-url + (lambda (_url) + (gloss-fetch-test--status-response "HTTP/1.1 503 Service Unavailable" "")) + (let ((result (gloss-fetch-definitions "anaphora"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :failed)))))) + +(ert-deftest test-gloss-fetch-definitions-malformed-json-rolls-up-to-failed () + "Boundary: a 200 with non-JSON body also maps to :server-error." + (gloss-fetch-test--with-mocked-url + (lambda (_url) (gloss-fetch-test--ok-response "not json")) + (let ((result (gloss-fetch-definitions "anaphora"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :failed)))))) + +(ert-deftest test-gloss-fetch-definitions-400-rolls-up-to-failed () + "Error: HTTP 400 (4xx other than 404/429) maps to :server-error (in :failed)." + (gloss-fetch-test--with-mocked-url + (lambda (_url) + (gloss-fetch-test--status-response "HTTP/1.1 400 Bad Request" "")) + (let ((result (gloss-fetch-definitions "anaphora"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :failed)))))) + +(provide 'test-gloss-fetch--definitions-500-returns-server-error) +;;; test-gloss-fetch--definitions-500-returns-server-error.el ends here -- cgit v1.2.3