[WIP] Update postgres and tests
This commit is contained in:
parent
65dd1d1ca2
commit
1cadd0e993
3 changed files with 24 additions and 24 deletions
|
@ -33,18 +33,16 @@
|
|||
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
|
||||
|
||||
#?(:cljs
|
||||
(defmethod yaml/load-resource :postgres [resource-name]
|
||||
(case resource-name
|
||||
"postgres/config-2gb.yaml" (rc/inline "postgres/config-2gb.yaml")
|
||||
"postgres/config-4gb.yaml" (rc/inline "postgres/config-4gb.yaml")
|
||||
"postgres/config-8gb.yaml" (rc/inline "postgres/config-8gb.yaml")
|
||||
"postgres/config-16gb.yaml" (rc/inline "postgres/config-16gb.yaml")
|
||||
"postgres/deployment.yaml" (rc/inline "postgres/deployment.yaml")
|
||||
"postgres/persistent-volume.yaml" (rc/inline "postgres/persistent-volume.yaml")
|
||||
"postgres/pvc.yaml" (rc/inline "postgres/pvc.yaml")
|
||||
"postgres/secret.yaml" (rc/inline "postgres/secret.yaml")
|
||||
"postgres/service.yaml" (rc/inline "postgres/service.yaml")
|
||||
(throw (js/Error. "Undefined Resource!")))))
|
||||
(defmethod yaml/allowed-resources :postgres []
|
||||
["postgres/config-2gb.yaml"
|
||||
"postgres/config-4gb.yaml"
|
||||
"postgres/config-8gb.yaml"
|
||||
"postgres/config-16gb.yaml"
|
||||
"postgres/deployment.yaml"
|
||||
"postgres/persistent-volume.yaml"
|
||||
"postgres/pvc.yaml"
|
||||
"postgres/secret.yaml"
|
||||
"postgres/service.yaml"]))
|
||||
|
||||
(defn-spec generate-config cp/map-or-seq?
|
||||
[& config (s/? pg-config?)]
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
[shadow.resource :as rc]
|
||||
[dda.c4k-common.predicate :as cp]))
|
||||
|
||||
(defn string-or-keyword? [input]
|
||||
(or (string? input) (keyword? input)))
|
||||
|
||||
(defn-spec from-string cp/map-or-seq?
|
||||
[input string?]
|
||||
(js->clj (yaml/load input)
|
||||
|
@ -16,22 +19,23 @@
|
|||
(yaml/dump (clj->js edn)))
|
||||
|
||||
(defn-spec dispatch-by-resource-name keyword?
|
||||
[resource string?]
|
||||
:cljs)
|
||||
[resource string-or-keyword?]
|
||||
(keyword (first (st/split resource #"/"))))
|
||||
|
||||
(defmulti load-resource dispatch-by-resource-name)
|
||||
|
||||
(defmethod load-resource :cljs [allowed-resources resource-name]
|
||||
(defmethod load-resource :default [allowed-resources resource-name]
|
||||
(if (some #(= % resource-name) allowed-resources)
|
||||
(rc/inline resource-name)
|
||||
(throw (js/Error. "Undefined Resource!"))))
|
||||
|
||||
(defmulti load-as-edn dispatch-by-resource-name)
|
||||
|
||||
(defmethod load-as-edn :cljs [allowed-resource resource-name]
|
||||
(from-string (load-resource (allowed-resource) resource-name)))
|
||||
(defmethod load-as-edn :default [resource-name]
|
||||
(let [allowed-resources (allowed-resources)]
|
||||
(from-string (load-resource allowed-resources resource-name))))
|
||||
|
||||
(defmulti allowed-resources dispatch-by-resource-name)
|
||||
|
||||
(defmethod allowed-resources :cljs []
|
||||
[])
|
||||
(defmethod allowed-resources :default []
|
||||
[])
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
(st/instrument `cut/to-string)
|
||||
(st/instrument `cut/dispatch-by-resource-name)
|
||||
|
||||
(defmethod cut/load-resource :test [resource-name]
|
||||
(case resource-name
|
||||
"test/ingress_test.yaml" (rc/inline "test/ingress_test.yaml")
|
||||
(throw (js/Error. "Undefined Resource!"))))
|
||||
#?(:cljs (defmethod cut/allowed-resources :cljs []
|
||||
["test/ingress_test.yaml"]))
|
||||
|
||||
(deftest should-dispatch-by-resource-name
|
||||
(is (= :postgres
|
||||
|
@ -56,4 +54,4 @@
|
|||
[{:backend
|
||||
{:serviceName "another_keycloak"
|
||||
:servicePort 8081}}]}}]}}
|
||||
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
|
||||
(cut/load-as-edn "test/ingress_test.yaml"))))
|
||||
|
|
Loading…
Reference in a new issue