feature/namespace #2

Merged
jem merged 15 commits from feature/namespace into master 2024-02-20 17:24:37 +00:00
3 changed files with 60 additions and 0 deletions
Showing only changes of commit 73e2ebd12f - Show all commits

View 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)]))

View file

@ -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)))

View 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"}))))