introduce namespace
This commit is contained in:
parent
866ef84f12
commit
73e2ebd12f
3 changed files with 60 additions and 0 deletions
19
src/main/cljc/dda/c4k_common/namespace.cljc
Normal file
19
src/main/cljc/dda/c4k_common/namespace.cljc
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
(ns dda.c4k-common.namespace
|
||||||
|
(:require
|
||||||
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[dda.c4k-common.namespace.namespace-internal :as int]))
|
||||||
|
|
||||||
|
(s/def ::namespace ::int/namespace)
|
||||||
|
|
||||||
|
(def config? (s/keys :req-un []
|
||||||
|
:opt-un [::namespace]))
|
||||||
|
|
||||||
|
(def default-config {:namespace "default"})
|
||||||
|
|
||||||
|
(defn-spec generate seq?
|
||||||
|
[config config?]
|
||||||
|
(let [final-config (merge default-config
|
||||||
|
config)]
|
||||||
|
[(int/generate-namespace final-config)]))
|
|
@ -0,0 +1,23 @@
|
||||||
|
(ns dda.c4k-common.namespace.namespace-internal
|
||||||
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
|
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
|
||||||
|
[dda.c4k-common.yaml :as yaml]))
|
||||||
|
|
||||||
|
(s/def ::namespace string?)
|
||||||
|
|
||||||
|
(def config? (s/keys :req-un [::namespace]
|
||||||
|
:opt-un []))
|
||||||
|
|
||||||
|
(defn-spec generate-namespace map?
|
||||||
|
[config config?]
|
||||||
|
(let [{:keys [namespace]} config]
|
||||||
|
(->
|
||||||
|
(yaml/load-as-edn "namespace/namespace.yaml")
|
||||||
|
(assoc-in [:metadata :name] namespace))))
|
||||||
|
|
||||||
|
#?(:cljs
|
||||||
|
(defmethod yaml/load-resource :namespace [resource-name]
|
||||||
|
(get (inline-resources "namespace") resource-name)))
|
18
src/test/cljc/dda/c4k_common/namespace_test.cljc
Normal file
18
src/test/cljc/dda/c4k_common/namespace_test.cljc
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
(ns dda.c4k-common.namespace-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.namespace :as cut]))
|
||||||
|
|
||||||
|
(st/instrument `cut/generate)
|
||||||
|
|
||||||
|
(deftest should-generate-simple-ingress
|
||||||
|
(is (= [{:apiVersion "v1"
|
||||||
|
:kind "Namespace"
|
||||||
|
:metadata {:name "default"}}]
|
||||||
|
(cut/generate {})))
|
||||||
|
(is (= [{:apiVersion "v1"
|
||||||
|
:kind "Namespace"
|
||||||
|
:metadata {:name "myapp"}}]
|
||||||
|
(cut/generate {:namespace "myapp"}))))
|
Loading…
Reference in a new issue