From 80ad4b720dd879134f11579e091356a1abd031dc Mon Sep 17 00:00:00 2001
From: Michael Jerger <michael.jerger@meissa-gmbh.de>
Date: Thu, 20 Feb 2025 16:29:45 +0100
Subject: [PATCH] clean up coturn & add over all test

---
 src/main/cljc/dda/c4k_jitsi/core.cljc         |  1 -
 src/main/cljc/dda/c4k_jitsi/jitsi.cljc        |  9 +------
 .../resources/jitsi/coturn-auth-secret.yaml   | 10 --------
 ...lt-cm.yaml => coturn-config-extra-cm.yaml} |  0
 src/test/cljc/dda/c4k_jitsi/core_test.cljc    | 24 ++++++++++++-------
 src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc   |  7 ------
 6 files changed, 17 insertions(+), 34 deletions(-)
 delete mode 100644 src/main/resources/jitsi/coturn-auth-secret.yaml
 rename src/main/resources/jitsi/{coturn-config-default-cm.yaml => coturn-config-extra-cm.yaml} (100%)

diff --git a/src/main/cljc/dda/c4k_jitsi/core.cljc b/src/main/cljc/dda/c4k_jitsi/core.cljc
index 1f09cd9..3202e6e 100644
--- a/src/main/cljc/dda/c4k_jitsi/core.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/core.cljc
@@ -77,6 +77,5 @@
         #(not (nil? %))
         (cm/concat-vec
          (jitsi/prosody-auth config auth)
-         (jitsi/coturn-auth config auth)
          (when (:contains? config :mon-cfg)
            (mon/generate-auth (:mon-cfg config) (:mon-auth auth))))))))
diff --git a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
index b59c9af..e62f6f9 100644
--- a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
@@ -163,18 +163,11 @@
   (let [{:keys [namespace]} config]
     [(load-and-adjust-namespace "jitsi/modelector-config-service.yaml" namespace)
      (load-and-adjust-namespace "jitsi/modelector-config-deployment.yaml" namespace)]))
-
-(defn-spec coturn-auth cp/map-or-seq?
-  [config config?
-   auth auth?]
-  (let [{:keys [namespace]} config
-        {:keys []} auth]
-    [(load-and-adjust-namespace "jitsi/coturn-auth-secret.yaml" namespace)]))
   
 (defn-spec coturn-config cp/map-or-seq?
   [config config?]
   (let [{:keys [namespace fqdn]} config]
-    [(load-and-adjust-namespace "jitsi/coturn-config-default-cm.yaml" namespace)
+    [(load-and-adjust-namespace "jitsi/coturn-config-extra-cm.yaml" namespace)
      (-> 
       (load-and-adjust-namespace "jitsi/coturn-config-init-cm.yaml" namespace)
       (cm/replace-key-value
diff --git a/src/main/resources/jitsi/coturn-auth-secret.yaml b/src/main/resources/jitsi/coturn-auth-secret.yaml
deleted file mode 100644
index 93223f2..0000000
--- a/src/main/resources/jitsi/coturn-auth-secret.yaml
+++ /dev/null
@@ -1,10 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
-  namespace: NAMESPACE
-  name: coturn-auth-secret
-  labels:
-    app.kubernetes.io/name: "coturn"
-data:
-  username: ""
-  password: ""
\ No newline at end of file
diff --git a/src/main/resources/jitsi/coturn-config-default-cm.yaml b/src/main/resources/jitsi/coturn-config-extra-cm.yaml
similarity index 100%
rename from src/main/resources/jitsi/coturn-config-default-cm.yaml
rename to src/main/resources/jitsi/coturn-config-extra-cm.yaml
diff --git a/src/test/cljc/dda/c4k_jitsi/core_test.cljc b/src/test/cljc/dda/c4k_jitsi/core_test.cljc
index e77e1f2..2c9067a 100644
--- a/src/test/cljc/dda/c4k_jitsi/core_test.cljc
+++ b/src/test/cljc/dda/c4k_jitsi/core_test.cljc
@@ -1,20 +1,28 @@
 (ns dda.c4k-jitsi.core-test
   (:require
-   #?(:cljs [shadow.resource :as rc])
    #?(:clj [clojure.test :refer [deftest is are testing run-tests]]
       :cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
    [clojure.spec.alpha :as s]
    [dda.c4k-common.yaml :as yaml]
-   [dda.c4k-jitsi.core :as cut]))
+   [dda.c4k-jitsi.core :as cut]
+   #?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])))
+
 
 #?(:cljs
    (defmethod yaml/load-resource :jitsi-test [resource-name]
-     (case resource-name
-       "jitsi-test/valid-auth.yaml"   (rc/inline "jitsi-test/valid-auth.yaml")
-       "jitsi-test/valid-config.yaml" (rc/inline "jitsi-test/valid-config.yaml")
-       (throw (js/Error. "Undefined Resource!")))))
+     (get (inline-resources "jitsi-test") resource-name)))
 
 (deftest validate-valid-resources
   (is (s/valid? cut/config? (yaml/load-as-edn "jitsi-test/valid-config.yaml")))
-  (is (s/valid? cut/auth? (yaml/load-as-edn "jitsi-test/valid-auth.yaml")))
-  )
\ No newline at end of file
+  (is (s/valid? cut/auth? (yaml/load-as-edn "jitsi-test/valid-auth.yaml"))))
+
+(deftest test-whole-generation
+  (is (= 63
+         (count
+          (cut/config-objects
+           (yaml/load-as-edn "jitsi-test/valid-config.yaml")))))
+  (is (= 6
+         (count
+          (cut/auth-objects
+           (yaml/load-as-edn "jitsi-test/valid-config.yaml")
+           (yaml/load-as-edn "jitsi-test/valid-auth.yaml"))))))
\ No newline at end of file
diff --git a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
index b3ba9d4..364d778 100644
--- a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
+++ b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
@@ -168,13 +168,6 @@
                   :namespace "jitsi"})))))
 
 (deftest should-generate-coturn
-  (is (= 1
-         (count (cut/coturn-auth
-                 {:fqdn "xy.xy.xy"
-                  :namespace "jitsi"}
-                 {:jvb-auth-password "jvb-auth"
-                  :jicofo-auth-password "jicofo-auth"
-                  :jicofo-component-secret "jicofo-comp"}))))
    (is (= 5
          (count (cut/coturn-config
                  {:fqdn "xy.xy.xy"