From 0d9324017db38f17b9f7bcf4d1832ac438496bfe Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 30 Aug 2024 16:50:18 +0200 Subject: [PATCH] improve testing & fix deps --- deps.edn | 10 ++++++---- src/dda/backup/core/domain.clj | 1 + src/dda/backup/postgresql/domain.clj | 8 +++++--- test/dda/backup/backup/domain_test.clj | 5 ----- test/dda/backup/core/domain_test.clj | 8 +++++++- test/dda/backup/monitoring/domain_test.clj | 2 +- test/dda/backup/postgresql/domain_test.clj | 5 ----- test/dda/backup/restic/domain_test.clj | 2 +- test/dda/backup/restore/domain_test.clj | 4 ---- tests.edn | 12 +----------- 10 files changed, 22 insertions(+), 35 deletions(-) diff --git a/deps.edn b/deps.edn index cd4c453..ea6758e 100644 --- a/deps.edn +++ b/deps.edn @@ -9,9 +9,10 @@ ;; --------------------------------------------------------- :deps {;; Application - org.clojure/clojure {:mvn/version "1.11.4"} - org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha" - :git/sha "79e7daaead944583eece42ff5665be208d019861"} + ;;org.clojure/clojure {:mvn/version "1.11.4"} + org.clojure/spec.alpha {:mvn/version "0.5.238"} +;; org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha" +;; :git/sha "644a7fc216e43d5da87b07471b0f87d874107d1a"} orchestra/orchestra {:mvn/version "2021.01.01-1"} babashka/babashka.curl {:mvn/version "0.1.2"}} ;; --------------------------------------------------------- @@ -28,7 +29,8 @@ ;; call with :watch? true to start file watcher and re-run tests on saved changes :test/run {:extra-paths ["test"] - :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}} + :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"} + expound/expound {:mvn/version "0.9.0"}} :main-opts ["-m" "kaocha.runner"] :exec-fn kaocha.runner/exec-fn :exec-args {:randomize? false diff --git a/src/dda/backup/core/domain.clj b/src/dda/backup/core/domain.clj index c137266..fb82843 100644 --- a/src/dda/backup/core/domain.clj +++ b/src/dda/backup/core/domain.clj @@ -3,6 +3,7 @@ [clojure.spec.alpha :as s])) (s/def ::command (s/cat + :opts (s/? map?) :app string? :params (s/* string?))) (s/def ::commands (s/coll-of ::command)) diff --git a/src/dda/backup/postgresql/domain.clj b/src/dda/backup/postgresql/domain.clj index df26fa2..d04b72d 100644 --- a/src/dda/backup/postgresql/domain.clj +++ b/src/dda/backup/postgresql/domain.clj @@ -30,9 +30,11 @@ (s/merge ::pg-config ::rd/restic-config)) +(s/def ::pg-command (s/* string?)) + (defn-spec psql-command ::cd/command [config ::pg-config - command ::cd/command] + command ::pg-command] (let [{:keys [pg-host pg-port pg-db pg-user]} config] (into ["psql" "-d" pg-db "-h" pg-host "-p" (str pg-port) "-U" pg-user @@ -41,7 +43,7 @@ (defn-spec pgdumpall-command ::cd/command [config ::pg-role-dump-config - command ::cd/command] + command ::pg-command] (let [{:keys [pg-host pg-port pg-user pg-role-prefix]} config] (into [] @@ -54,7 +56,7 @@ (defn-spec pgdump-command ::cd/command [config ::pg-db-dump-config - command ::cd/command] + command ::pg-command] (let [{:keys [pg-host pg-port pg-db pg-user]} config] (into [] diff --git a/test/dda/backup/backup/domain_test.clj b/test/dda/backup/backup/domain_test.clj index 1e7a9d5..c0c81a8 100644 --- a/test/dda/backup/backup/domain_test.clj +++ b/test/dda/backup/backup/domain_test.clj @@ -1,13 +1,8 @@ (ns dda.backup.backup.domain-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [clojure.spec.test.alpha :as st] [dda.backup.backup.domain :as cut])) -(st/instrument `cut/backup-files-command) -(st/instrument `cut/backup-role-command) -(st/instrument `cut/backup-db-command) - (deftest should-calculate-backup-files-command (is (= [[{:dir "dir-to-backup"} "restic" diff --git a/test/dda/backup/core/domain_test.clj b/test/dda/backup/core/domain_test.clj index 7f7c2c3..9770ca4 100644 --- a/test/dda/backup/core/domain_test.clj +++ b/test/dda/backup/core/domain_test.clj @@ -6,7 +6,13 @@ (deftest should-verify-command (is (= {:app "restic", :params ["-r" "repo/dir" "-v" "init" "--cacert" "ca"]} - (s/conform ::cut/command ["restic" "-r" "repo/dir" "-v" "init" "--cacert" "ca"])))) + (s/conform ::cut/command ["restic" "-r" "repo/dir" "-v" "init" "--cacert" "ca"]))) + (is (= {:app "restic"} + (s/conform ::cut/command ["restic"]))) + (is (= {:opts {:dir "dir"} :app "restic", :params ["-r" "repo/dir" "-v" "init" "--cacert" "ca"]} + (s/conform ::cut/command [{:dir "dir"} "restic" "-r" "repo/dir" "-v" "init" "--cacert" "ca"]))) + (is (= {:opts {:dir "dir"} :app "restic"} + (s/conform ::cut/command [{:dir "dir"} "restic"])))) (deftest should-verify-commands (is (= [{:app "ls"} diff --git a/test/dda/backup/monitoring/domain_test.clj b/test/dda/backup/monitoring/domain_test.clj index 4602e86..df383f2 100644 --- a/test/dda/backup/monitoring/domain_test.clj +++ b/test/dda/backup/monitoring/domain_test.clj @@ -1,7 +1,7 @@ (ns dda.backup.monitoring.domain-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [clojure.spec.test.alpha :as st] + [orchestra.spec.test :as st] [dda.backup.monitoring.domain :as cut])) (deftest should-generate-monitoring-data diff --git a/test/dda/backup/postgresql/domain_test.clj b/test/dda/backup/postgresql/domain_test.clj index 6ed97ba..4a54c72 100644 --- a/test/dda/backup/postgresql/domain_test.clj +++ b/test/dda/backup/postgresql/domain_test.clj @@ -1,13 +1,8 @@ (ns dda.backup.postgresql.domain-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [clojure.spec.test.alpha :as st] [dda.backup.postgresql.domain :as cut])) -(st/instrument `cut/pgpass) -(st/instrument `cut/db-drop-command) -(st/instrument `cut/db-create-command) - (deftest should-calculate-pgpass (is (= "localhost:5432:mydb:user:password\nlocalhost:5432:template1:user:password\n" (cut/pgpass {:restic-repository "repo" diff --git a/test/dda/backup/restic/domain_test.clj b/test/dda/backup/restic/domain_test.clj index d4e7a4f..919c222 100644 --- a/test/dda/backup/restic/domain_test.clj +++ b/test/dda/backup/restic/domain_test.clj @@ -1,7 +1,7 @@ (ns dda.backup.restic.domain-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [clojure.spec.test.alpha :as st] + [orchestra.spec.test :as st] [dda.backup.restic.domain :as cut])) (st/instrument `cut/repo-command) diff --git a/test/dda/backup/restore/domain_test.clj b/test/dda/backup/restore/domain_test.clj index 5813783..38204c7 100644 --- a/test/dda/backup/restore/domain_test.clj +++ b/test/dda/backup/restore/domain_test.clj @@ -1,12 +1,8 @@ (ns dda.backup.restore.domain-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [clojure.spec.test.alpha :as st] [dda.backup.restore.domain :as cut])) -(st/instrument `cut/restore-dir-command) -(st/instrument `cut/restore-db-command) - (deftest should-calculate-restore-dir (is (= [["rm" "-rf" "dir-to-backup"] ["restic" diff --git a/tests.edn b/tests.edn index 629f0ab..a585ca2 100644 --- a/tests.edn +++ b/tests.edn @@ -10,16 +10,6 @@ ;; --------------------------------------------------------- -#kaocha/v1 {:plugins [:orchestra - :kaocha.plugin.alpha/info - :profiling - :print-invocations - :hooks - :notifier - :kaocha.plugin/version-filter] - - :kaocha/bindings {kaocha.stacktrace/*stacktrace-filters* [] - kaocha.stacktrace/*stacktrace-stop-list* []} - +#kaocha/v1 {:plugins [:orchestra] :reporter kaocha.report/documentation}