From f1e41b3333330e69a0609d138ca6af56598fea48 Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 7 Mar 2024 11:44:59 +0100 Subject: [PATCH] added test for generate-build-configmap --- src/main/cljc/dda/c4k_website/website.cljc | 26 +++++++--------- .../cljc/dda/c4k_website/website_test.cljc | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index 9dd6142..8065ca6 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -53,17 +53,17 @@ ; https://your.gitea.host/api/v1/repos///archive/.zip (defn-spec generate-gitrepourl string? [host pred/fqdn-string? + owner string? repo string? - user string? branch string?] - (str "https://" host "/api/v1/repos/" user "/" repo "/archive/" branch ".zip")) + (str "https://" host "/api/v1/repos/" owner "/" repo "/archive/" branch ".zip")) ; https://your.gitea.host/api/v1/repos///git/commits/HEAD (defn-spec generate-gitcommiturl string? [host pred/fqdn-string? - repo string? - user string?] - (str "https://" host "/api/v1/repos/" user "/" repo "/git/" "commits/" "HEAD")) + owner string? + repo string?] + (str "https://" host "/api/v1/repos/" owner "/" repo "/git/" "commits/" "HEAD")) (defn-spec replace-all-matching-prefixes map? @@ -104,7 +104,7 @@ #"REDIRECTS" (generate-redirects config 2))))))) -; TODO add test & add to build-cron env +; TODO add to build-cron env (defn-spec generate-build-configmap pred/map-or-seq? [config websiteconfig?] (let [{:keys [unique-name @@ -116,17 +116,15 @@ (-> (yaml/load-as-edn "website/build-configmap.yaml") (replace-all-matching-prefixes "NAME" name) - (cm/replace-all-matching-values-by-new-value "REPOURL" (b64/encode - (generate-gitrepourl + (cm/replace-all-matching-values-by-new-value "REPOURL" (generate-gitrepourl forgejo-host - forgejo-repo repo-user - branchname))) - (cm/replace-all-matching-values-by-new-value "COMMITURL" (b64/encode - (generate-gitcommiturl + forgejo-repo + branchname)) + (cm/replace-all-matching-values-by-new-value "COMMITURL" (generate-gitcommiturl forgejo-host - forgejo-repo - repo-user)))))) + repo-user + forgejo-repo))))) (defn-spec generate-build-secret pred/map-or-seq? [auth websiteauth?] diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index a94dffd..d6de269 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -19,6 +19,14 @@ (st/instrument `cut/generate-nginx-service) +(deftest should-generate-gitrepourl + (is (= "https://mygit.de/api/v1/repos/someuser/repo/archive/main.zip" + (cut/generate-gitrepourl "mygit.de" "someuser" "repo" "main")))) + +(deftest should-generate-gitcommiturl + (is (= "https://mygit.de/api/v1/repos/someuser/repo/git/commits/HEAD" + (cut/generate-gitcommiturl "mygit.de" "someuser" "repo")))) + (deftest should-generate-redirects (is (= "rewrite ^/products.html\\$ /offer.html permanent;\n rewrite ^/one-more\\$ /redirect permanent;" (cut/generate-redirects {:issuer "staging" @@ -220,6 +228,29 @@ :unique-name "test.io", :redirects []})))) +(deftest should-generate-build-configmap + (is (= {:apiVersion "v1", + :kind "ConfigMap", + :metadata {:name "build-configmap", + :namespace "test-io", + :labels {:app.kubernetes.part-of "test-io-website"}}, + :data + {:GITREPOURL "https://mygit.de/api/v1/repos/someuser/repo/archive/main.zip" + :GITCOMMITURL "https://mygit.de/api/v1/repos/someuser/repo/git/commits/HEAD"}} + (cut/generate-build-configmap {:issuer "staging" + :build-cpu-request "500m" + :build-cpu-limit "1700m" + :build-memory-request "256Mi" + :build-memory-limit "512Mi" + :volume-size "3" + :forgejo-host "mygit.de", + :repo-user "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :forgejo-repo "repo", + :branchname "main", + :unique-name "test.io", + :redirects []})))) + (deftest should-generate-build-secret (is (= {:apiVersion "v1", :kind "Secret",