add some tests

This commit is contained in:
jem 2021-07-05 18:39:39 +02:00
parent 2fc6a177ad
commit f76a254b04
5 changed files with 47 additions and 34 deletions

View file

@ -14,39 +14,31 @@
:opt-un [::jira/issuer ::jira/jira-data-volume-path :opt-un [::jira/issuer ::jira/jira-data-volume-path
::postgres/postgres-data-volume-path])) ::postgres/postgres-data-volume-path]))
(def auth? (s/keys :req-un [::postgres/db-user-name ::postgres/db-user-password])) (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password]))
(defn k8s-objects [config]
(into
[]
(concat [(yaml/to-string (postgres/generate-config))
(yaml/to-string (postgres/generate-secret config))]
(when (contains? config :postgres-data-volume-path)
[(yaml/to-string (postgres/generate-persistent-volume config))])
[(yaml/to-string (postgres/generate-pvc))
(yaml/to-string (postgres/generate-deployment))
(yaml/to-string (postgres/generate-service))]
(when (contains? config :jira-data-volume-path)
[(yaml/to-string (jira/generate-persistent-volume config))])
[(yaml/to-string (jira/generate-pvc))
(yaml/to-string (jira/generate-pod config))
(yaml/to-string (jira/generate-service))
(yaml/to-string (jira/generate-certificate config))
(yaml/to-string (jira/generate-ingress config))
(yaml/to-string (jira/generate-service))])))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config config?
my-auth auth?] my-auth auth?]
(let [resulting-config (merge config-defaults my-config my-auth)] (let [resulting-config (merge config-defaults my-config my-auth)]
(cs/join (cs/join
"\n" "\n---\n"
(into (k8s-objects resulting-config))))
[(yaml/to-string (postgres/generate-config))
"---"
(yaml/to-string (postgres/generate-secret resulting-config))]
(when-some [{:keys [postgres-data-volume-path]} resulting-config]
["---"
(yaml/to-string (postgres/generate-persistent-volume resulting-config))])
["---"
(yaml/to-string (postgres/generate-pvc))
"---"
(yaml/to-string (postgres/generate-deployment))
"---"
(yaml/to-string (postgres/generate-service))]
(when-some [{:keys [jira-data-volume-path]} resulting-config]
["---"
(yaml/to-string (jira/generate-persistent-volume resulting-config))])
["---"
(yaml/to-string (jira/generate-pvc))
"---"
(yaml/to-string (jira/generate-pod resulting-config))
"---"
(yaml/to-string (jira/generate-service))
"---"
(yaml/to-string (jira/generate-certificate resulting-config))
"---"
(yaml/to-string (jira/generate-ingress resulting-config))
"---"
(yaml/to-string (jira/generate-service))]))))

View file

@ -46,6 +46,6 @@ spec:
- name: postgres-config-volume - name: postgres-config-volume
configMap: configMap:
name: postgres-config name: postgres-config
- name: postgre-d - name: postgre-data-volume
persistentVolumeClaim: persistentVolumeClaim:
claimName: postgres-claim claimName: postgres-claim

View file

@ -0,0 +1,19 @@
(ns dda.c4k-jira.core-test
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.c4k-jira.core :as cut]))
(deftest should-k8s-objects
(is (= 13
(count (cut/k8s-objects {:fqdn "jira-neu.prod.meissa-gmbh.de"
:postgres-db-user "jira"
:postgres-db-password "jira-db-password"
:issuer :prod
:jira-data-volume-path "/var/jira"
:postgres-data-volume-path "/var/postgres"}))))
(is (= 11
(count (cut/k8s-objects {:fqdn "jira-neu.prod.meissa-gmbh.de"
:postgres-db-user "jira"
:postgres-db-password "jira-db-password"
:issuer :prod})))))

View file

@ -1,2 +1,2 @@
{:db-user-name "jira" {:postgres-db-user "jira"
:db-user-password "jira-db-password"} :postgres-db-password "jira-db-password"}

View file

@ -1 +1,3 @@
{:fqdn "jira-neu.prod.meissa-gmbh.de"} {:fqdn "jira-neu.prod.meissa-gmbh.de"
:jira-data-volume-path "/var/jira"
:postgres-data-volume-path "/var/postgres"}