From 4f988450d638c476c8803ea9a3b046eac7c3e8af Mon Sep 17 00:00:00 2001 From: bom Date: Tue, 2 Jul 2024 16:01:05 +0200 Subject: [PATCH] Fix tests --- src/main/cljc/dda/c4k_shynet/core.cljc | 3 +- src/main/cljc/dda/c4k_shynet/shynet.cljc | 3 +- src/test/cljc/dda/c4k_shynet/core_test.cljc | 10 +-- src/test/cljc/dda/c4k_shynet/shynet_test.cljc | 64 ++++++++----------- .../cljs/dda/c4k_shynet/browser_test.cljs | 10 --- .../resources/shynet-test/valid-auth.yaml | 6 ++ .../resources/shynet-test/valid-config.yaml | 7 ++ src/test/resources/valid-auth.edn | 5 -- src/test/resources/valid-config.edn | 6 -- 9 files changed, 49 insertions(+), 65 deletions(-) delete mode 100644 src/test/cljs/dda/c4k_shynet/browser_test.cljs create mode 100644 src/test/resources/shynet-test/valid-auth.yaml create mode 100644 src/test/resources/shynet-test/valid-config.yaml delete mode 100644 src/test/resources/valid-auth.edn delete mode 100644 src/test/resources/valid-config.edn diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index 38647b5..085ac1e 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -16,6 +16,7 @@ (def config? (s/keys :req-un [::shynet/fqdn] :opt-un [::shynet/issuer + ::postgres/postgres-data-volume-path ::mon-cfg])) (def auth? (s/keys :req-un [::shynet/django-secret-key @@ -35,7 +36,7 @@ (postgres/generate-service config) (shynet/generate-webserver-deployment) (shynet/generate-celeryworker-deployment) - (shynet/generate-ingress config) + (shynet/generate-ingress-and-cert config) (shynet/generate-service-redis) (shynet/generate-service-webserver) (shynet/generate-statefulset) diff --git a/src/main/cljc/dda/c4k_shynet/shynet.cljc b/src/main/cljc/dda/c4k_shynet/shynet.cljc index cacc48c..1d97179 100644 --- a/src/main/cljc/dda/c4k_shynet/shynet.cljc +++ b/src/main/cljc/dda/c4k_shynet/shynet.cljc @@ -15,7 +15,6 @@ (defmethod yaml/load-resource :shynet [resource-name] (case resource-name "shynet/secret.yaml" (rc/inline "shynet/secret.yaml") - "shynet/certificate.yaml" (rc/inline "shynet/certificate.yaml") "shynet/deployments.yaml" (rc/inline "shynet/deployments.yaml") "shynet/service-redis.yaml" (rc/inline "shynet/service-redis.yaml") "shynet/service-webserver.yaml" (rc/inline "shynet/service-webserver.yaml") @@ -43,7 +42,7 @@ (-> (yaml/load-as-edn "shynet/deployments.yaml") (cm/replace-all-matching "shynet-application" shynet-application)))) -(defn generate-ingress [config] +(defn generate-ingress-and-cert [config] (ing/generate-ingress-and-cert config)) (defn generate-statefulset [] diff --git a/src/test/cljc/dda/c4k_shynet/core_test.cljc b/src/test/cljc/dda/c4k_shynet/core_test.cljc index 37afa6f..e79de13 100644 --- a/src/test/cljc/dda/c4k_shynet/core_test.cljc +++ b/src/test/cljc/dda/c4k_shynet/core_test.cljc @@ -8,12 +8,12 @@ [dda.c4k-shynet.core :as cut])) #?(:cljs - (defmethod yaml/load-resource :jitsi-test [resource-name] + (defmethod yaml/load-resource :shynet-test [resource-name] (case resource-name - "valid-auth.yaml" (rc/inline "valid-auth.yaml") - "valid-config.yaml" (rc/inline "valid-config.yaml") + "shynet-test/valid-auth.yaml" (rc/inline "shynet-test/valid-auth.yaml") + "shynet-test/valid-config.yaml" (rc/inline "shynet-test/valid-config.yaml") (throw (js/Error. "Undefined Resource!"))))) (deftest validate-valid-resources - (is (s/valid? cut/config? (yaml/load-as-edn "valid-config.yaml"))) - (is (s/valid? cut/auth? (yaml/load-as-edn "valid-auth.yaml")))) \ No newline at end of file + (is (s/valid? cut/config? (yaml/load-as-edn "shynet-test/valid-config.yaml"))) + (is (s/valid? cut/auth? (yaml/load-as-edn "shynet-test/valid-auth.yaml")))) \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_shynet/shynet_test.cljc b/src/test/cljc/dda/c4k_shynet/shynet_test.cljc index eee44f3..f4c38ea 100644 --- a/src/test/cljc/dda/c4k_shynet/shynet_test.cljc +++ b/src/test/cljc/dda/c4k_shynet/shynet_test.cljc @@ -48,42 +48,34 @@ :envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}} (cut/generate-celeryworker-deployment)))) -(deftest should-generate-certificate - (is (= {:apiVersion "cert-manager.io/v1" - :kind "Certificate" - :metadata {:name "shynet-cert", :namespace "default"} - :spec - {:secretName "shynet-cert" - :commonName "test.com" - :duration "2160h", - :renewBefore "360h", - :dnsNames ["test.com"] - :issuerRef {:name "staging", :kind "ClusterIssuer"}}} - (cut/generate-certificate {:fqdn "test.com" :issuer :staging})))) - -(deftest should-generate-ingress - (is (= {:apiVersion "networking.k8s.io/v1" - :kind "Ingress" - :metadata - {:name "shynet-webserver-ingress" - :annotations - {:ingress.kubernetes.io/force-ssl-redirect "true" - :ingress.kubernetes.io/ssl-redirect "true" - :cert-manager.io/cluster-issuer - "staging"}} - :spec - {:tls [{:hosts ["test.com"], :secretName "shynet-cert"}] - :rules - [{:host "test.com" - :http - {:paths - [{:backend - {:service - {:name "shynet-webserver-service" - :port {:number 8080}}} - :path "/" - :pathType "Prefix"}]}}]}} - (cut/generate-ingress {:fqdn "test.com" :issuer :staging})))) +(deftest should-generate-ingress-and-cert + (is (= [{:apiVersion "cert-manager.io/v1", + :kind "Certificate", + :metadata + {:name nil, + :labels {:app.kubernetes.part-of nil}, + :namespace "default"}, + :spec + {:secretName nil, + :commonName nil, + :duration "2160h", + :renewBefore "720h", + :dnsNames nil, + :issuerRef {:name "staging", :kind "ClusterIssuer"}}} + {:apiVersion "networking.k8s.io/v1", + :kind "Ingress", + :metadata + {:namespace "default", + :annotations + {:traefik.ingress.kubernetes.io/router.entrypoints + "web, websecure", + :traefik.ingress.kubernetes.io/router.middlewares + "default-redirect-https@kubernetescrd", + :metallb.universe.tf/address-pool "public"}, + :name nil, + :labels {:app.kubernetes.part-of nil}}, + :spec {:tls [{:hosts nil, :secretName nil}], :rules []}}] + (cut/generate-ingress-and-cert {:fqdn "test.com" :issuer :staging})))) (deftest should-generate-secret (is (= {:apiVersion "v1" diff --git a/src/test/cljs/dda/c4k_shynet/browser_test.cljs b/src/test/cljs/dda/c4k_shynet/browser_test.cljs deleted file mode 100644 index e194844..0000000 --- a/src/test/cljs/dda/c4k_shynet/browser_test.cljs +++ /dev/null @@ -1,10 +0,0 @@ -(ns dda.c4k-shynet.browser-test - (:require - [cljs.test :refer-macros [deftest is are testing run-tests]] - [hickory.render :as hr] - [dda.c4k-shynet.browser :as cut])) - -(deftest should-generate-group - (is (= "
id1
content
" - (apply hr/hickory-to-html - (cut/generate-group "id1" "content"))))) diff --git a/src/test/resources/shynet-test/valid-auth.yaml b/src/test/resources/shynet-test/valid-auth.yaml new file mode 100644 index 0000000..2b245f5 --- /dev/null +++ b/src/test/resources/shynet-test/valid-auth.yaml @@ -0,0 +1,6 @@ +django-secret-key: "django" +postgres-db-user: "shynet" +postgres-db-password: "shynet-db-password" +mon-auth: + grafana-cloud-user: "user" + grafana-cloud-password: "password" diff --git a/src/test/resources/shynet-test/valid-config.yaml b/src/test/resources/shynet-test/valid-config.yaml new file mode 100644 index 0000000..8f161e2 --- /dev/null +++ b/src/test/resources/shynet-test/valid-config.yaml @@ -0,0 +1,7 @@ +fqdn: "statistics.test.meissa-gmbh.de" +issuer: "staging" +postgres-data-volume-path: "/var/postgres" +mon-cfg: + grafana-cloud-url: "url-for-your-prom-remote-write-endpoint" + cluster-name: "jitsi" + cluster-stage: "test" diff --git a/src/test/resources/valid-auth.edn b/src/test/resources/valid-auth.edn deleted file mode 100644 index 70867c0..0000000 --- a/src/test/resources/valid-auth.edn +++ /dev/null @@ -1,5 +0,0 @@ -{:django-secret-key "django" - :postgres-db-user "shynet" - :postgres-db-password "shynet-db-password" - :mon-auth {:grafana-cloud-user "user" - :grafana-cloud-password "password"}} diff --git a/src/test/resources/valid-config.edn b/src/test/resources/valid-config.edn deleted file mode 100644 index 1babe5f..0000000 --- a/src/test/resources/valid-config.edn +++ /dev/null @@ -1,6 +0,0 @@ -{:fqdn "statistics.test.meissa-gmbh.de" - :issuer "staging" - :postgres-data-volume-path "/var/postgres" - :mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint" - :k3s-cluster-name "jitsi" - :k3s-cluster-stage "test"}}