From 8f714c3bdd4d7aaa7db8b90dff8f432be85093e8 Mon Sep 17 00:00:00 2001 From: Mirco Date: Fri, 2 Aug 2024 16:17:30 +0200 Subject: [PATCH] Added Tests: web-service, etherpad-service, excalidraw-backend-service, excalidraw-deployment, meapp-development, meapp-fullstack-service --- src/main/cljc/dda/c4k_jitsi/jitsi.cljc | 48 +++++++++---- .../resources/jitsi/etherpad-service.yaml | 1 + .../jitsi/excalidraw-backend-service.yaml | 1 + .../jitsi/excalidraw-deployment.yaml | 1 + .../resources/jitsi/meapp-deployment.yaml | 1 + .../jitsi/meapp-fullstack-service.yaml | 1 + src/main/resources/jitsi/web-service.yaml | 1 + src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc | 67 +++++++++++++++++++ 8 files changed, 109 insertions(+), 12 deletions(-) diff --git a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc index a0fabf0..c70905e 100644 --- a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc +++ b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc @@ -83,17 +83,33 @@ (yaml/from-string (yaml/load-resource "jitsi/jvb-service.yaml")) (cm/replace-all-matching "NAMESPACE" namespace)))) -(defn-spec generate-web-service cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/web-service.yaml")) +(defn-spec generate-web-service cp/map-or-seq? + [config config?] + (let [{:keys [namespace]} config] + (-> + (yaml/load-as-edn "jitsi/web-service.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) -(defn-spec generate-etherpad-service cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/etherpad-service.yaml")) +(defn-spec generate-etherpad-service cp/map-or-seq? + [config config?] + (let [{:keys [namespace]} config] + (-> + (yaml/load-as-edn "jitsi/etherpad-service.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) -(defn-spec generate-excalidraw-backend-service cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/excalidraw-backend-service.yaml")) +(defn-spec generate-excalidraw-backend-service cp/map-or-seq? + [config config?] + (let [{:keys [namespace]} config] + (-> + (yaml/load-as-edn "jitsi/excalidraw-backend-service.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) -(defn-spec generate-meapp-fullstack-service cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/meapp-fullstack-service.yaml")) +(defn-spec generate-meapp-fullstack-service cp/map-or-seq? + [config config?] + (let [{:keys [namespace]} config] + (-> + (yaml/load-as-edn "jitsi/meapp-fullstack-service.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) (defn-spec generate-deployment cp/map-or-seq? [config config?] @@ -108,8 +124,16 @@ (cm/replace-all-matching "REPLACE_EXCALIDRAW_BACKEND_URL" (str "https://excalidraw-backend." fqdn))))) -(defn-spec generate-excalidraw-deployment cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/excalidraw-deployment.yaml")) +(defn-spec generate-excalidraw-deployment cp/map-or-seq? + [config config?] + (let [{:keys [fqdn namespace]} config] + (-> + (yaml/load-as-edn "jitsi/excalidraw-deployment.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) -(defn-spec generate-meapp-deployment cp/map-or-seq? [] - (yaml/load-as-edn "jitsi/meapp-deployment.yaml")) +(defn-spec generate-meapp-deployment cp/map-or-seq? + [config config?] + (let [{:keys [fqdn namespace]} config] + (-> + (yaml/load-as-edn "jitsi/meapp-deployment.yaml") + (cm/replace-all-matching "NAMESPACE" namespace)))) diff --git a/src/main/resources/jitsi/etherpad-service.yaml b/src/main/resources/jitsi/etherpad-service.yaml index e124fc0..7538aa8 100644 --- a/src/main/resources/jitsi/etherpad-service.yaml +++ b/src/main/resources/jitsi/etherpad-service.yaml @@ -4,6 +4,7 @@ metadata: labels: service: etherpad name: etherpad + namespace: NAMESPACE spec: ports: - name: etherpad diff --git a/src/main/resources/jitsi/excalidraw-backend-service.yaml b/src/main/resources/jitsi/excalidraw-backend-service.yaml index dcee873..d7ab698 100644 --- a/src/main/resources/jitsi/excalidraw-backend-service.yaml +++ b/src/main/resources/jitsi/excalidraw-backend-service.yaml @@ -4,6 +4,7 @@ metadata: labels: service: excalidraw-backend name: excalidraw-backend + namespace: NAMESPACE spec: ports: - name: excalidraw-backend diff --git a/src/main/resources/jitsi/excalidraw-deployment.yaml b/src/main/resources/jitsi/excalidraw-deployment.yaml index 587c93b..e5c3301 100644 --- a/src/main/resources/jitsi/excalidraw-deployment.yaml +++ b/src/main/resources/jitsi/excalidraw-deployment.yaml @@ -4,6 +4,7 @@ metadata: labels: app: excalidraw-backend name: excalidraw-backend + namespace: NAMESPACE spec: strategy: type: Recreate diff --git a/src/main/resources/jitsi/meapp-deployment.yaml b/src/main/resources/jitsi/meapp-deployment.yaml index 1586514..ba4a8e7 100644 --- a/src/main/resources/jitsi/meapp-deployment.yaml +++ b/src/main/resources/jitsi/meapp-deployment.yaml @@ -4,6 +4,7 @@ metadata: labels: app: meapp-fullstack name: meapp-fullstack + namespace: NAMESPACE spec: replicas: 1 strategy: diff --git a/src/main/resources/jitsi/meapp-fullstack-service.yaml b/src/main/resources/jitsi/meapp-fullstack-service.yaml index 94579f6..33faf78 100644 --- a/src/main/resources/jitsi/meapp-fullstack-service.yaml +++ b/src/main/resources/jitsi/meapp-fullstack-service.yaml @@ -4,6 +4,7 @@ metadata: labels: service: meapp-fullstack name: meapp-fullstack + namespace: NAMESPACE spec: ports: - name: "http" diff --git a/src/main/resources/jitsi/web-service.yaml b/src/main/resources/jitsi/web-service.yaml index 4af33ff..0b1ce43 100644 --- a/src/main/resources/jitsi/web-service.yaml +++ b/src/main/resources/jitsi/web-service.yaml @@ -4,6 +4,7 @@ metadata: labels: service: web name: web + namespace: NAMESPACE spec: ports: - name: "http" diff --git a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc index 454ab0f..f0a948e 100644 --- a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc +++ b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc @@ -168,3 +168,70 @@ (cut/generate-jvb-service {:fqdn "xy.xy.xy" :namespace "jitsi"})))) + +(deftest should-generate-web-service + (is (= {:apiVersion "v1", + :kind "Service", + :metadata {:labels {:service "web"}, :name "web", :namespace "jitsi"}, + :spec + {:ports + [{:name "http", :port 80, :targetPort 80} + {:name "https", :port 443, :targetPort 443}], + :selector {:app "jitsi"}}} + (cut/generate-web-service + {:fqdn "xy.xy.xy" + :namespace "jitsi"})))) + +(deftest should-generate-etherpad-service + (is (= {:apiVersion "v1", + :kind "Service", + :metadata + {:labels {:service "etherpad"}, :name "etherpad", :namespace "jitsi"}, + :spec + {:ports [{:name "etherpad", :port 9001, :targetPort 9001}], + :selector {:app "jitsi"}}} + (cut/generate-etherpad-service + {:fqdn "xy.xy.xy" + :namespace "jitsi"})))) + +(deftest should-generate-excalidraw-backend-service + (is (= {:apiVersion "v1", + :kind "Service", + :metadata + {:labels {:service "excalidraw-backend"}, + :name "excalidraw-backend", + :namespace "jitsi"}, + :spec + {:ports [{:name "excalidraw-backend", :port 3002, :targetPort 80}], + :selector {:app "excalidraw-backend"}}} + (cut/generate-excalidraw-backend-service + {:fqdn "xy.xy.xy" + :namespace "jitsi"})))) + +(deftest should-generate-meapp-fullstack-service + (is (= {:apiVersion "v1", + :kind "Service", + :metadata + {:labels {:service "excalidraw-backend"}, + :name "excalidraw-backend", + :namespace "jitsi"}, + :spec + {:ports [{:name "excalidraw-backend", :port 3002, :targetPort 80}], + :selector {:app "excalidraw-backend"}}} + (cut/generate-excalidraw-backend-service + {:fqdn "xy.xy.xy" + :namespace "jitsi"})))) + +(deftest should-generate-excalidraw-deployment + (is (= {:apiVersion "v1", + :kind "Service", + :metadata + {:labels {:service "excalidraw-backend"}, + :name "excalidraw-backend", + :namespace "jitsi"}, + :spec + {:ports [{:name "excalidraw-backend", :port 3002, :targetPort 80}], + :selector {:app "excalidraw-backend"}}} + (cut/generate-excalidraw-backend-service + {:fqdn "xy.xy.xy" + :namespace "jitsi"})))) \ No newline at end of file