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

View file

@ -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 []

View file

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

View file

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

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