Fix tests

This commit is contained in:
bom 2024-07-02 16:01:05 +02:00
parent e69d99b7f3
commit 4f988450d6
9 changed files with 49 additions and 65 deletions

View file

@ -16,6 +16,7 @@
(def config? (s/keys :req-un [::shynet/fqdn] (def config? (s/keys :req-un [::shynet/fqdn]
:opt-un [::shynet/issuer :opt-un [::shynet/issuer
::postgres/postgres-data-volume-path
::mon-cfg])) ::mon-cfg]))
(def auth? (s/keys :req-un [::shynet/django-secret-key (def auth? (s/keys :req-un [::shynet/django-secret-key
@ -35,7 +36,7 @@
(postgres/generate-service config) (postgres/generate-service config)
(shynet/generate-webserver-deployment) (shynet/generate-webserver-deployment)
(shynet/generate-celeryworker-deployment) (shynet/generate-celeryworker-deployment)
(shynet/generate-ingress config) (shynet/generate-ingress-and-cert config)
(shynet/generate-service-redis) (shynet/generate-service-redis)
(shynet/generate-service-webserver) (shynet/generate-service-webserver)
(shynet/generate-statefulset) (shynet/generate-statefulset)

View file

@ -15,7 +15,6 @@
(defmethod yaml/load-resource :shynet [resource-name] (defmethod yaml/load-resource :shynet [resource-name]
(case resource-name (case resource-name
"shynet/secret.yaml" (rc/inline "shynet/secret.yaml") "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/deployments.yaml" (rc/inline "shynet/deployments.yaml")
"shynet/service-redis.yaml" (rc/inline "shynet/service-redis.yaml") "shynet/service-redis.yaml" (rc/inline "shynet/service-redis.yaml")
"shynet/service-webserver.yaml" (rc/inline "shynet/service-webserver.yaml") "shynet/service-webserver.yaml" (rc/inline "shynet/service-webserver.yaml")
@ -43,7 +42,7 @@
(-> (yaml/load-as-edn "shynet/deployments.yaml") (-> (yaml/load-as-edn "shynet/deployments.yaml")
(cm/replace-all-matching "shynet-application" shynet-application)))) (cm/replace-all-matching "shynet-application" shynet-application))))
(defn generate-ingress [config] (defn generate-ingress-and-cert [config]
(ing/generate-ingress-and-cert config)) (ing/generate-ingress-and-cert config))
(defn generate-statefulset [] (defn generate-statefulset []

View file

@ -8,12 +8,12 @@
[dda.c4k-shynet.core :as cut])) [dda.c4k-shynet.core :as cut]))
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :jitsi-test [resource-name] (defmethod yaml/load-resource :shynet-test [resource-name]
(case resource-name (case resource-name
"valid-auth.yaml" (rc/inline "valid-auth.yaml") "shynet-test/valid-auth.yaml" (rc/inline "shynet-test/valid-auth.yaml")
"valid-config.yaml" (rc/inline "valid-config.yaml") "shynet-test/valid-config.yaml" (rc/inline "shynet-test/valid-config.yaml")
(throw (js/Error. "Undefined Resource!"))))) (throw (js/Error. "Undefined Resource!")))))
(deftest validate-valid-resources (deftest validate-valid-resources
(is (s/valid? cut/config? (yaml/load-as-edn "valid-config.yaml"))) (is (s/valid? cut/config? (yaml/load-as-edn "shynet-test/valid-config.yaml")))
(is (s/valid? cut/auth? (yaml/load-as-edn "valid-auth.yaml")))) (is (s/valid? cut/auth? (yaml/load-as-edn "shynet-test/valid-auth.yaml"))))

View file

@ -48,42 +48,34 @@
:envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}} :envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}}
(cut/generate-celeryworker-deployment)))) (cut/generate-celeryworker-deployment))))
(deftest should-generate-certificate (deftest should-generate-ingress-and-cert
(is (= {:apiVersion "cert-manager.io/v1" (is (= [{:apiVersion "cert-manager.io/v1",
:kind "Certificate" :kind "Certificate",
:metadata {:name "shynet-cert", :namespace "default"} :metadata
:spec {:name nil,
{:secretName "shynet-cert" :labels {:app.kubernetes.part-of nil},
:commonName "test.com" :namespace "default"},
:duration "2160h", :spec
:renewBefore "360h", {:secretName nil,
:dnsNames ["test.com"] :commonName nil,
:issuerRef {:name "staging", :kind "ClusterIssuer"}}} :duration "2160h",
(cut/generate-certificate {:fqdn "test.com" :issuer :staging})))) :renewBefore "720h",
:dnsNames nil,
(deftest should-generate-ingress :issuerRef {:name "staging", :kind "ClusterIssuer"}}}
(is (= {:apiVersion "networking.k8s.io/v1" {:apiVersion "networking.k8s.io/v1",
:kind "Ingress" :kind "Ingress",
:metadata :metadata
{:name "shynet-webserver-ingress" {:namespace "default",
:annotations :annotations
{:ingress.kubernetes.io/force-ssl-redirect "true" {:traefik.ingress.kubernetes.io/router.entrypoints
:ingress.kubernetes.io/ssl-redirect "true" "web, websecure",
:cert-manager.io/cluster-issuer :traefik.ingress.kubernetes.io/router.middlewares
"staging"}} "default-redirect-https@kubernetescrd",
:spec :metallb.universe.tf/address-pool "public"},
{:tls [{:hosts ["test.com"], :secretName "shynet-cert"}] :name nil,
:rules :labels {:app.kubernetes.part-of nil}},
[{:host "test.com" :spec {:tls [{:hosts nil, :secretName nil}], :rules []}}]
:http (cut/generate-ingress-and-cert {:fqdn "test.com" :issuer :staging}))))
{:paths
[{:backend
{:service
{:name "shynet-webserver-service"
:port {:number 8080}}}
:path "/"
:pathType "Prefix"}]}}]}}
(cut/generate-ingress {:fqdn "test.com" :issuer :staging}))))
(deftest should-generate-secret (deftest should-generate-secret
(is (= {:apiVersion "v1" (is (= {:apiVersion "v1"

View file

@ -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 (= "<div class=\"rounded border border-3 m-3 p-2\"><b style=\"z-index: 1; position: relative; top: -1.3rem;\">id1</b><fieldset>content</fieldset></div>"
(apply hr/hickory-to-html
(cut/generate-group "id1" "content")))))

View file

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

View file

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

View file

@ -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"}}

View file

@ -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"}}