fixed tests

This commit is contained in:
jem 2021-11-05 19:35:16 +01:00
parent 47b7a412c9
commit d5e3810d02
3 changed files with 20 additions and 15 deletions

View file

@ -23,9 +23,9 @@
(s/def ::postgres-size postgres-size?) (s/def ::postgres-size postgres-size?)
(s/def ::db-name cp/bash-env-string?) (s/def ::db-name cp/bash-env-string?)
(defn pg-config? [input] (defn pg-config? [input]
(s/keys :un-opt [::postgres-size ::db-name ::postgres-data-volume-path])) (s/keys :opt-un [::postgres-size ::db-name ::postgres-data-volume-path]))
(defn pg-auth? [input] (defn pg-auth? [input]
(s/keys :un-opt [::postgres-db-user ::postgres-db-password])) (s/keys :opt-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]))
@ -44,18 +44,20 @@
(throw (js/Error. "Undefined Resource!"))))) (throw (js/Error. "Undefined Resource!")))))
(defn-spec generate-config cp/map-or-seq? (defn-spec generate-config cp/map-or-seq?
[& args pg-config?] [& config (s/? pg-config?)]
(let [{:keys [postgres-size db-name] (let [{:keys [postgres-size db-name]
:or {postgres-size :2gb :or {postgres-size :2gb
db-name "postgres"}} args] db-name "postgres"}} (first config)]
(-> (->
(yaml/from-string (yaml/load-resource (str "postgres/config-" (name postgres-size) ".yaml"))) (yaml/from-string (yaml/load-resource
(str "postgres/config-" (name postgres-size) ".yaml")))
(assoc-in [:data :postgres-db] db-name)))) (assoc-in [:data :postgres-db] db-name))))
(defn-spec generate-deployment cp/map-or-seq? (defn-spec generate-deployment cp/map-or-seq?
[& args postgres-image?] [& config (s/? pg-config?)]
(let [{:keys [postgres-image] (let [{:keys [postgres-image]
:or {postgres-image "postgres:13"}} args] :or {postgres-image "postgres:13"}} (first config)]
(-> (->
(yaml/from-string (yaml/load-resource "postgres/deployment.yaml")) (yaml/from-string (yaml/load-resource "postgres/deployment.yaml"))
(assoc-in [:spec :template :spec :containers 0 :image] postgres-image)))) (assoc-in [:spec :template :spec :containers 0 :image] postgres-image))))
@ -72,7 +74,7 @@
(yaml/from-string (yaml/load-resource "postgres/pvc.yaml"))) (yaml/from-string (yaml/load-resource "postgres/pvc.yaml")))
(defn-spec generate-secret cp/map-or-seq? (defn-spec generate-secret cp/map-or-seq?
[my-auth pg-auth?] [my-auth any?]
(let [{:keys [postgres-db-user postgres-db-password]} my-auth] (let [{:keys [postgres-db-user postgres-db-password]} my-auth]
(-> (->
(yaml/from-string (yaml/load-resource "postgres/secret.yaml")) (yaml/from-string (yaml/load-resource "postgres/secret.yaml"))

View file

@ -1,8 +1,10 @@
(ns dda.c4k-common.yaml-test (ns dda.c4k-common.yaml-test
(:require (:require
[clojure.test :refer [deftest is are testing run-tests]] [clojure.test :refer [deftest is are testing run-tests]]
[dda.c4k-common.yaml :as cut] [orchestra.spec.test :as st]
[orchestra.spec.test :as st])) [dda.c4k-common.yaml :as cut]))
(st/instrument)
(deftest should-dispatch-by-resource-name (deftest should-dispatch-by-resource-name
(is (= :clj (is (= :clj
@ -47,5 +49,3 @@
{:serviceName "another_keycloak" {:serviceName "another_keycloak"
:servicePort 8081}}]}}]}} :servicePort 8081}}]}}]}}
(cut/from-string (cut/load-resource "test/ingress_test.yaml"))))) (cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
(st/instrument)

View file

@ -2,8 +2,11 @@
(:require (:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]] #?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) :cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[orchestra.spec.test :as st]
[dda.c4k-common.postgres :as cut])) [dda.c4k-common.postgres :as cut]))
(st/instrument)
(deftest should-generate-config (deftest should-generate-config
(is (= {:postgres-db "postgres" (is (= {:postgres-db "postgres"
:postgresql.conf :postgresql.conf
@ -12,11 +15,11 @@
(is (= {:postgres-db "postgres" (is (= {:postgres-db "postgres"
:postgresql.conf :postgresql.conf
"max_connections = 700\nwork_mem = 3MB\nshared_buffers = 2048MB\n"} "max_connections = 700\nwork_mem = 3MB\nshared_buffers = 2048MB\n"}
(:data (cut/generate-config :postgres-size :8gb)))) (:data (cut/generate-config {:postgres-size :8gb}))))
(is (= {:postgres-db "test" (is (= {:postgres-db "test"
:postgresql.conf :postgresql.conf
"max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"} "max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"}
(:data (cut/generate-config :db-name "test")))) (:data (cut/generate-config {:db-name "test"}))))
) )
(deftest should-generate-persistent-volume (deftest should-generate-persistent-volume
@ -64,5 +67,5 @@
:readOnly true} :readOnly true}
{:name "postgre-data-volume" {:name "postgre-data-volume"
:mountPath "/var/lib/postgresql/data"}]}] :mountPath "/var/lib/postgresql/data"}]}]
(get-in (cut/generate-deployment :postgres-image "postgres:14") (get-in (cut/generate-deployment {:postgres-image "postgres:14"})
[:spec :template :spec :containers])))) [:spec :template :spec :containers]))))