Add unittests for predicates
This commit is contained in:
parent
16c440b872
commit
9a065943c9
2 changed files with 38 additions and 2 deletions
|
@ -1,4 +1,8 @@
|
||||||
(ns dda.c4k-common.predicate)
|
(ns dda.c4k-common.predicate
|
||||||
|
(:require
|
||||||
|
[clojure.string :as str]
|
||||||
|
#?(:clj [clojure.edn :as edn]
|
||||||
|
:cljs [cljs.reader :as edn])))
|
||||||
|
|
||||||
(defn bash-env-string?
|
(defn bash-env-string?
|
||||||
[input]
|
[input]
|
||||||
|
@ -10,6 +14,10 @@
|
||||||
(and (string? input)
|
(and (string? input)
|
||||||
(some? (re-matches #"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)" input))))
|
(some? (re-matches #"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)" input))))
|
||||||
|
|
||||||
|
(defn list-of-separated-by?
|
||||||
|
[input spec-function separator]
|
||||||
|
(every? true? (map spec-function (str/split input separator))))
|
||||||
|
|
||||||
(defn letsencrypt-issuer?
|
(defn letsencrypt-issuer?
|
||||||
[input]
|
[input]
|
||||||
(contains? #{"prod" "staging"} input))
|
(contains? #{"prod" "staging"} input))
|
||||||
|
@ -21,3 +29,18 @@
|
||||||
(defn pvc-storage-class-name?
|
(defn pvc-storage-class-name?
|
||||||
[input]
|
[input]
|
||||||
(contains? #{:manual :local-path} input))
|
(contains? #{:manual :local-path} input))
|
||||||
|
|
||||||
|
(defn port-number?
|
||||||
|
[input]
|
||||||
|
(and (integer? input)
|
||||||
|
(> input 0)
|
||||||
|
(<= input 65535)))
|
||||||
|
|
||||||
|
(defn host-and-port-string?
|
||||||
|
[input]
|
||||||
|
(and (string? input)
|
||||||
|
(let [split-string (str/split input #":")]
|
||||||
|
(and (= (count split-string) 2)
|
||||||
|
(fqdn-string? (first split-string))
|
||||||
|
(port-number? (edn/read-string (second split-string)))))))
|
||||||
|
|
||||||
|
|
13
src/test/cljc/dda/c4k_common/predicate_test.cljc
Normal file
13
src/test/cljc/dda/c4k_common/predicate_test.cljc
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
(ns dda.c4k-common.predicate-test
|
||||||
|
(:require
|
||||||
|
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||||
|
[clojure.spec.test.alpha :as st]
|
||||||
|
[dda.c4k-common.predicate :as cut]))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest test-bash-env-string?
|
||||||
|
(is (true? (cut/bash-env-string? "abcd")))
|
||||||
|
(is (false? (cut/bash-env-string? "$abdc")))
|
||||||
|
(is (false? (cut/bash-env-string? "\"abdc"))))
|
||||||
|
|
Loading…
Reference in a new issue