From 2c8ce98d6652fdcc936e8f93d97685854d55fa08 Mon Sep 17 00:00:00 2001 From: jerger Date: Mon, 26 Dec 2022 18:05:52 +0100 Subject: [PATCH] breaking: widen spec for ingress usage --- src/main/cljc/dda/c4k_common/common.cljc | 12 +++++++----- src/main/cljc/dda/c4k_common/predicate.cljc | 9 ++++++++- src/test/cljc/dda/c4k_common/predicate_test.cljc | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 4bf94ff..6717263 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -7,7 +7,6 @@ :cljs [orchestra.core :refer-macros [defn-spec]]) [dda.c4k-common.predicate :as cp])) - ;; deprecated functions were moved to dda.c4k-common.predicate (defn ^{:deprecated "0.1"} bash-env-string? [input] @@ -26,7 +25,7 @@ (defn-spec replace-named-value cp/map-or-seq? [coll cp/map-or-seq? name string? - value string?] + value cp/str-or-number?] (clojure.walk/postwalk #(if (and (map? %) (= name (:name %))) {:name name :value value} @@ -36,7 +35,7 @@ (defn-spec replace-key-value cp/map-or-seq? [coll cp/map-or-seq? key keyword? - value string?] + value cp/str-or-number?] (clojure.walk/postwalk #(if (and (map? %) (contains? % key)) (assoc % key value) @@ -46,7 +45,7 @@ (defn-spec replace-all-matching-values-by-new-value cp/map-or-seq? [coll cp/map-or-seq? value-to-match string? - value-to-replace string?] + value-to-replace cp/str-or-number?] (clojure.walk/postwalk #(if (and (= (type value-to-match) (type %)) (= value-to-match %)) value-to-replace @@ -58,7 +57,10 @@ (into [] (apply concat vs))) -(defn generate-common [my-config my-auth config-defaults k8s-objects] +(defn generate-common + [my-config + my-auth + config-defaults k8s-objects] (let [resulting-config (merge config-defaults my-config)] (cs/join "\n---\n" diff --git a/src/main/cljc/dda/c4k_common/predicate.cljc b/src/main/cljc/dda/c4k_common/predicate.cljc index 9b955ad..49a3132 100644 --- a/src/main/cljc/dda/c4k_common/predicate.cljc +++ b/src/main/cljc/dda/c4k_common/predicate.cljc @@ -28,7 +28,8 @@ (defn map-or-seq? [input] - (or (map? input) (seq? input))) + (or (map? input) + (seq? input))) (defn pvc-storage-class-name? [input] @@ -65,3 +66,9 @@ (and (int? input) (> input n))) +(defn str-or-number? + [input] + (or + (string? input) + (number? input))) + diff --git a/src/test/cljc/dda/c4k_common/predicate_test.cljc b/src/test/cljc/dda/c4k_common/predicate_test.cljc index 4ae1251..a492a0e 100644 --- a/src/test/cljc/dda/c4k_common/predicate_test.cljc +++ b/src/test/cljc/dda/c4k_common/predicate_test.cljc @@ -72,3 +72,8 @@ (is (cut/int-gt-n? 5 6)) (is ((partial cut/int-gt-n? 5) 10)) (is (not ((partial cut/int-gt-n? 5) 4)))) + +(deftest test-str-or-number? + (is (cut/str-or-number? "string")) + (is (cut/str-or-number? 42)) + (is (not (cut/str-or-number? []))))