dda-backup/test/dda/backup/postgresql/domain_test.clj

46 lines
2.1 KiB
Clojure
Raw Normal View History

2024-08-20 05:56:13 +00:00
(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-create-command)
2024-08-20 16:45:32 +00:00
(st/instrument `cut/backup-role-command)
2024-08-20 05:56:13 +00:00
(deftest should-calculate-pgpass
(is (= "localhost:mydb:user:password"
(cut/pgpass {:restic-repository "repo"
:backup-path "dir-at-repo"
:pg-host "localhost"
:pg-port 5432
:pg-db "mydb"
:pg-user "user"
:pg-password "password"}))))
(deftest should-calculate-db-drop-create-command
(is (= [["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
"--no-password" "-c" "\"DROP DATABASE \\\"mydb\\\";\""]
["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
"--no-password" "-c" "\"CREATE DATABASE \\\"mydb\\\";\""]]
(cut/db-drop-create-command {:restic-repository "repo"
:backup-path "dir-at-repo"
:pg-host "localhost"
:pg-port 5432
:pg-db "mydb"
:pg-user "user"
:pg-password "password"}))))
2024-08-20 16:45:32 +00:00
(deftest should-calculate-backup-role-command
(is (= [["bash" "-c" "pg_dumpall -h localhost -p 5432 -U user --no-password --roles-only | grep prefix | restic -r repo/dir-at-repo -v backup --stdin"]]
(cut/backup-role-command {:restic-repository "repo"
:backup-path "dir-at-repo"
:days-to-keep 39
:months-to-keep 3
:pg-host "localhost"
:pg-port 5432
:pg-db "mydb"
:pg-role-prefix "prefix"
:pg-user "user"
:pg-password "password"}))))