Skip to main content

Add a test for missing hostnames

ID
6a18e90
date
2024-05-16 20:36:26+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
cea623d
message
Add a test for missing hostnames
changed files
2 files, 17 additions, 1 deletion

Changed files

save_safari_webarchive.swift (3410) → save_safari_webarchive.swift (3406)

diff --git a/save_safari_webarchive.swift b/save_safari_webarchive.swift
index 0bbf451..704f91b 100755
--- a/save_safari_webarchive.swift
+++ b/save_safari_webarchive.swift
@@ -39,7 +39,7 @@ class ExitOnFailureDelegate: NSObject, WKNavigationDelegate {
     didFailProvisionalNavigation: WKNavigation!,
     withError error: Error
   ) {
-    fputs("Failed to load \(self.urlString) (2): \(error.localizedDescription)\n", stderr)
+    fputs("Failed to load \(self.urlString): \(error.localizedDescription)\n", stderr)
     exit(1)
   }
 

tests/test_save_safari_webarchive.py (2346) → tests/test_save_safari_webarchive.py (2848)

diff --git a/tests/test_save_safari_webarchive.py b/tests/test_save_safari_webarchive.py
index 45229b1..9cd1ea0 100755
--- a/tests/test_save_safari_webarchive.py
+++ b/tests/test_save_safari_webarchive.py
@@ -75,3 +75,19 @@ def test_it_fails_if_non_200_status_code(
 
     # Check a web archive wasn't created
     assert not out_path.exists()
+
+
+def test_it_fails_if_cannot_load_domain(tmp_path: pathlib.Path) -> None:
+    out_path = tmp_path / "example.webarchive"
+    assert not out_path.exists()
+
+    result = save_safari_webarchive(["https://doesnotexist.tk/", str(out_path)])
+
+    assert result["returncode"] == 1
+    assert result["stdout"] is None
+    assert (
+        result["stderr"]
+        == "Failed to load https://doesnotexist.tk/: A server with the specified hostname could not be found.\n"
+    )
+
+    assert not out_path.exists()