From 1cadd0e993dcc2ac2f992574ca5747d25552d513 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 8 Nov 2022 13:37:08 +0100 Subject: [PATCH] [WIP] Update postgres and tests --- src/main/cljc/dda/c4k_common/postgres.cljc | 22 ++++++++++----------- src/main/cljs/dda/c4k_common/yaml.cljs | 18 ++++++++++------- src/test/cljs/dda/c4k_common/yaml_test.cljs | 8 +++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 314e745..97d0956 100644 --- a/src/main/cljc/dda/c4k_common/postgres.cljc +++ b/src/main/cljc/dda/c4k_common/postgres.cljc @@ -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?)] diff --git a/src/main/cljs/dda/c4k_common/yaml.cljs b/src/main/cljs/dda/c4k_common/yaml.cljs index 057ec62..ef31be5 100644 --- a/src/main/cljs/dda/c4k_common/yaml.cljs +++ b/src/main/cljs/dda/c4k_common/yaml.cljs @@ -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 [] - []) \ No newline at end of file +(defmethod allowed-resources :default [] + []) diff --git a/src/test/cljs/dda/c4k_common/yaml_test.cljs b/src/test/cljs/dda/c4k_common/yaml_test.cljs index cca3846..4f43ce5 100644 --- a/src/test/cljs/dda/c4k_common/yaml_test.cljs +++ b/src/test/cljs/dda/c4k_common/yaml_test.cljs @@ -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"))))