summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-10-30 11:35:45 +0800
committereltrac <hi@eltr.ac>2026-10-30 11:35:45 +0800
commitdd4c7ca7850f166af4997912a3ded5639bd14a56 (patch)
tree889994e1b5b413fc50bc7e19c49b07546e44e626 /test
parentae0fda1ee522cf04f7b843d4cb2803435546cfb8 (diff)
test, downloader: tidy up downloader and add tests
- simplify (.mkdirs parent-dir) and with (io/make-parents file) - should return false when HTTP request fails, not nil - check if corrputed file exitsts before deleting it - add tests
Diffstat (limited to 'test')
-rw-r--r--test/weepinbell/downloader_test.clj15
1 files changed, 13 insertions, 2 deletions
diff --git a/test/weepinbell/downloader_test.clj b/test/weepinbell/downloader_test.clj
index 7a2d6b3..469c9ba 100644
--- a/test/weepinbell/downloader_test.clj
+++ b/test/weepinbell/downloader_test.clj
@@ -1,6 +1,7 @@
(ns weepinbell.downloader-test
(:require [weepinbell.http.downloader :refer [download-file]]
[clojure.java.io :as io]
+ [weepinbell.http.client]
[org.httpkit.server :refer [run-server]]
[clojure.test :refer [deftest testing is]]))
@@ -29,5 +30,15 @@
(testing "Downloading a non-existant file"
(let [file-dst (io/file "tmp/should-not-exist.txt")]
(is (not (download-file "https://localhost:18888" file-dst)))
- (is (not (.exists file-dst))))))
-
+ (is (not (.exists file-dst)))))
+ (testing "Exception/Error thrown while downloading"
+ (with-redefs [weepinbell.http.client/get!
+ (fn [& _] (throw (.Error "Test error")))]
+ (is (false? (download-file "" "")))))
+ (testing "Deletes possibly corrupted file when failure is caught"
+ (with-redefs [weepinbell.http.client/get!
+ (fn [& _] (throw (.Error "Test error")))]
+ (let [dest "dest"]
+ (spit dest "CORRUPTED")
+ (is (false? (download-file "" dest)))
+ (is (not (.exists (io/file dest))))))))