add test & fixed some issues

This commit is contained in:
Michael Jerger 2024-02-20 17:33:22 +01:00
parent cca93311e4
commit 674045eba3
3 changed files with 22 additions and 8 deletions

View file

@ -1,14 +1,8 @@
(ns dda.c4k-common.postgres (ns dda.c4k-common.postgres
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]]) :cljs [orchestra.core :refer-macros [defn-spec]])
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.base64 :as b64]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm]
[dda.c4k-common.postgres.postgres-internal :as int])) [dda.c4k-common.postgres.postgres-internal :as int]))
(def postgres-size? int/postgres-size?) (def postgres-size? int/postgres-size?)
@ -75,3 +69,16 @@
(defn-spec generate-service map? (defn-spec generate-service map?
[] []
(int/generate-service)) (int/generate-service))
(defn-spec generate seq?
[config pg-config?
auth pg-auth?]
(let [final-config (merge default-config
config)]
[(int/generate-secret auth)
(int/generate-persistent-volume final-config)
(int/generate-config final-config)
(int/generate-pvc final-config)
(int/generate-deployment final-config)
(int/generate-service)]))

View file

@ -30,7 +30,7 @@
(s/keys :req-un [::postgres-size ::db-name ::postgres-data-volume-path (s/keys :req-un [::postgres-size ::db-name ::postgres-data-volume-path
::pvc-storage-class-name ::pv-storage-size-gb])) ::pvc-storage-class-name ::pv-storage-size-gb]))
(def pg-auth? (def pg-auth?
(s/keys :opt-un [::postgres-db-user ::postgres-db-password])) (s/keys :req-un [::postgres-db-user ::postgres-db-password]))
(def postgres-function (s/keys :opt-un [::deserializer ::optional])) (def postgres-function (s/keys :opt-un [::deserializer ::optional]))

View file

@ -39,3 +39,10 @@
:accessModes ["ReadWriteOnce"] :accessModes ["ReadWriteOnce"]
:resources {:requests {:storage "10Gi"}}}} :resources {:requests {:storage "10Gi"}}}}
(cut/generate-pvc {})))) (cut/generate-pvc {}))))
(deftest should-generate
(is (= 6
(count (cut/generate {}
{:postgres-db-user "user"
:postgres-db-password "password"})))))