From ae0fda1ee522cf04f7b843d4cb2803435546cfb8 Mon Sep 17 00:00:00 2001 From: eltrac Date: Fri, 30 Oct 2026 11:21:33 +0800 Subject: test, migration: test edn-jf2ify; test throwable handling during migration --- test/weepinbell/migration_test.clj | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/weepinbell/migration_test.clj b/test/weepinbell/migration_test.clj index 6cf06e0..07a11d6 100644 --- a/test/weepinbell/migration_test.clj +++ b/test/weepinbell/migration_test.clj @@ -8,8 +8,10 @@ [clojure.test :refer [deftest testing is]] [clojure.java.io :as io])) +(def test-source-edn (io/resource "webmention-test.edn")) + (def webmention-test-edn - (with-open [rdr (io/reader (io/resource "webmention-test.edn"))] + (with-open [rdr (io/reader test-source-edn)] (->> rdr line-seq (map edn/read-string) doall))) (deftest test-migration-from-mf-to-jf2 @@ -25,15 +27,38 @@ (deftest test-migration-from-edn-to-h2 (testing "Migrating EDN file storage to H2 database storage" - (let [source-edn (io/resource "webmention-test.edn") - target-h2 "tmp/webmention-test-h2"] + (let [target-h2 "tmp/webmention-test-h2"] ;; assert migration succeed with no error (is (nil? (try - (m/edn->h2 source-edn target-h2) + (m/edn->h2 test-source-edn target-h2) (catch Throwable _ :fail)))) ;; assert data count (let [ds (h2/make-datasource target-h2) result (jdbc/execute! ds ["SELECT count(*) FROM webmention"]) len (get (first result) (keyword "count(*)"))] (is (= len (count webmention-test-edn)))) - (io/delete-file (str target-h2 ".mv.db"))))) + (io/delete-file (str target-h2 ".mv.db")))) + (testing "Exceptions thrown during migration does not abort program" + (with-redefs [weepinbell.storage.h2/insert-webmention + (fn [& _] (throw (Exception. "Test exception")))] + (let [target-h2 "tmp/webmention-test-exception-h2"] + (is (nil? (try + (m/edn->h2 test-source-edn target-h2) + (catch Exception _ :fail))))))) + (testing "Errors thrown during migration should fail migration" + (with-redefs [weepinbell.storage.h2/insert-webmention + (fn [& _] (throw (Error. "Test error")))] + (let [target-h2 "tmp/webmention-test-exception-h2"] + (is (= :fail (try + (m/edn->h2 test-source-edn target-h2) + (catch Error _ :fail)))))))) + +(deftest test-edn-jf2ify + (testing "Convert webmenion-test.edn to webmention-test-jf2.edn with jf2 markup" + (let [target-edn "tmp/webmention-test-jf2ified.edn"] + (m/edn-jf2ify test-source-edn target-edn) + (with-open [rdr (io/reader target-edn)] + (let [all (->> rdr line-seq (map edn/read-string)) + jf2s (->> all (filter :jf2) (map :jf2))] + (is (every? #(not (:microformats %)) all)) + (is (every? #(s/valid? :weepinbell.metadata.jf2-spec/jf2 %) jf2s))))))) -- cgit v1.2.3