From b689d520ce065800042eac29a14644b0f45d8f3f Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Tue, 30 May 2023 09:20:58 +0200 Subject: [PATCH] wrote tests upfront --- src/main/cljc/dda/c4k_forgejo/core.cljc | 2 +- src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 16 +++++----------- src/main/resources/forgejo/deployment.yaml | 2 +- src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc | 14 ++++++++++++-- .../resources/forgejo-test/valid-config.yaml | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/cljc/dda/c4k_forgejo/core.cljc b/src/main/cljc/dda/c4k_forgejo/core.cljc index d63b477..1dad792 100644 --- a/src/main/cljc/dda/c4k_forgejo/core.cljc +++ b/src/main/cljc/dda/c4k_forgejo/core.cljc @@ -43,7 +43,7 @@ (postgres/generate-deployment {:postgres-image "postgres:14" :postgres-size :2gb}) (postgres/generate-service) - (forgejo/generate-deployment) + (forgejo/generate-deployment config) (forgejo/generate-service) (forgejo/generate-service-ssh) (forgejo/generate-data-volume config) diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc index 0a011dd..48028d1 100644 --- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc +++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc @@ -21,7 +21,7 @@ (pred/string-of-separated-by? pred/fqdn-string? #"," input))) (s/def ::default-app-name string?) -(s/def ::forgejo-image-name string?) +(s/def ::federated boolean?) (s/def ::fqdn pred/fqdn-string?) (s/def ::mailer-from pred/bash-env-string?) (s/def ::mailer-host pred/bash-env-string?) @@ -39,11 +39,11 @@ ::mailer-from ::mailer-host ::mailer-port - ::service-noreply-address - ::deploy-federated] + ::service-noreply-address] :opt-un [::issuer ::default-app-name - ::service-domain-whitelist])) + ::service-domain-whitelist + ::federated])) (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password ::mailer-user ::mailer-pw])) @@ -121,13 +121,7 @@ ; ToDo: Need to add default image-name to config? Or hardcode? (defn-spec generate-deployment pred/map-or-seq? [config config?] - (let [{:keys [deploy-federated]} config - deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))] - (-> - (yaml/load-as-edn "forgejo/deployment.yaml") - #(if deploy-federated-bool - (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" federated-image-name) - (cm/replace-all-matching-values-by-new-value %"IMAGE_NAME" default-name))))) + (yaml/load-as-edn "forgejo/deployment.yaml")) (defn generate-service [] diff --git a/src/main/resources/forgejo/deployment.yaml b/src/main/resources/forgejo/deployment.yaml index 93fa1ef..110ec43 100644 --- a/src/main/resources/forgejo/deployment.yaml +++ b/src/main/resources/forgejo/deployment.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: forgejo - image: codeberg.org/meissa/forgejo:federated-latest #codeberg.org/forgejo/forgejo:1.19 + image: codeberg.org/forgejo/forgejo:1.19 imagePullPolicy: IfNotPresent # config settings envFrom: diff --git a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc index ef03fa6..1887e1a 100644 --- a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc +++ b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc @@ -29,7 +29,9 @@ :FORGEJO__service__EMAIL_DOMAIN_WHITELIST-c1 "adb.de", :FORGEJO__service__EMAIL_DOMAIN_WHITELIST-c2 "test.com,test.net", :FORGEJO__service__NO_REPLY_ADDRESS-c1 "", - :FORGEJO__service__NO_REPLY_ADDRESS-c2 "noreply@test.com"} + :FORGEJO__service__NO_REPLY_ADDRESS-c2 "noreply@test.com" + :FORGEJO__federation__ENABLED-c1 "true" + :FORGEJO__federation__ENABLED-c2 "false"} (th/map-diff (cut/generate-appini-env {:default-app-name "" :fqdn "test.de" :mailer-from "" @@ -37,6 +39,7 @@ :mailer-port "123" :service-domain-whitelist "adb.de" :service-noreply-address "" + :federated true }) (cut/generate-appini-env {:default-app-name "test forgejo" :fqdn "test.com" @@ -45,6 +48,7 @@ :mailer-port "456" :service-domain-whitelist "test.com,test.net" :service-noreply-address "noreply@test.com" + :federated false }))))) (deftest should-generate-secret @@ -69,4 +73,10 @@ (is (= {:storage-c1 "1Gi", :storage-c2 "15Gi"} (th/map-diff (cut/generate-data-volume {:volume-total-storage-size 1}) - (cut/generate-data-volume {:volume-total-storage-size 15}))))) \ No newline at end of file + (cut/generate-data-volume {:volume-total-storage-size 15}))))) + +(deftest should-generate-deployment + (is (= {:image-c1 "codeberg.org/forgejo/forgejo:1.19", + :image-c2 "domaindrivenarchitecture/c4k-forgejo-fed"} + (th/map-diff (cut/generate-deployment {:federated false}) + (cut/generate-deployment {:federated true}))))) \ No newline at end of file diff --git a/src/test/resources/forgejo-test/valid-config.yaml b/src/test/resources/forgejo-test/valid-config.yaml index d847ff9..a16d121 100644 --- a/src/test/resources/forgejo-test/valid-config.yaml +++ b/src/test/resources/forgejo-test/valid-config.yaml @@ -8,7 +8,7 @@ service-whitelist-domains: "test.de" service-noreply-address: "noreply@test.de" volume-total-storage-size: 6 restic-repository: "repo-path" -deploy-federated: "false" +federated: false mon-cfg: grafana-cloud-url: "url-for-your-prom-remote-write-endpoint" cluster-name: "forgejo"