Test for map function
This commit is contained in:
parent
012ed9ba0a
commit
7dc0cc68f1
3 changed files with 58 additions and 2 deletions
|
@ -26,6 +26,11 @@
|
||||||
|
|
||||||
(def auth? (s/keys :req-un [::user-name ::user-password]))
|
(def auth? (s/keys :req-un [::user-name ::user-password]))
|
||||||
|
|
||||||
|
|
||||||
|
(defn replace-values-in-vector
|
||||||
|
[map keys value]
|
||||||
|
)
|
||||||
|
|
||||||
(defn generate-config [my-config my-auth]
|
(defn generate-config [my-config my-auth]
|
||||||
(->
|
(->
|
||||||
(yaml/from-string (yaml/load-resource "config.yaml"))
|
(yaml/from-string (yaml/load-resource "config.yaml"))
|
||||||
|
@ -68,6 +73,8 @@
|
||||||
:http {:paths [{:backend {:serviceName "keycloak"
|
:http {:paths [{:backend {:serviceName "keycloak"
|
||||||
:servicePort 8080}}]}}]))))
|
:servicePort 8080}}]}}]))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn generate-service []
|
(defn generate-service []
|
||||||
(yaml/from-string (yaml/load-resource "service.yaml")))
|
(yaml/from-string (yaml/load-resource "service.yaml")))
|
||||||
|
|
||||||
|
@ -84,3 +91,5 @@
|
||||||
(yaml/to-string (generate-service))
|
(yaml/to-string (generate-service))
|
||||||
"---"
|
"---"
|
||||||
(yaml/to-string (generate-deployment my-auth))]))
|
(yaml/to-string (generate-deployment my-auth))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
(:require
|
(:require
|
||||||
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||||
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||||
[dda.k8s-keycloak.core :as cut]))
|
[dda.k8s-keycloak.core :as cut]
|
||||||
|
[dda.k8s-keycloak.yaml :as yaml]))
|
||||||
|
|
||||||
(deftest should-generate-yaml
|
(deftest should-generate-yaml
|
||||||
(is (= {:apiVersion "v1", :kind "ConfigMap"
|
(is (= {:apiVersion "v1", :kind "ConfigMap"
|
||||||
|
@ -82,3 +83,18 @@
|
||||||
:ports [{:name "http", :containerPort 8080}]
|
:ports [{:name "http", :containerPort 8080}]
|
||||||
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}}
|
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}}
|
||||||
(cut/generate-deployment {:user-name "testuser" :user-password "test1234"}))))
|
(cut/generate-deployment {:user-name "testuser" :user-password "test1234"}))))
|
||||||
|
|
||||||
|
(deftest test-vector-replace-fqdn-function
|
||||||
|
(let [ingress-yaml (yaml/from-string (yaml/load-resource "ingress.yaml"))
|
||||||
|
fqdn "some_host"
|
||||||
|
desired-result (-> ingress-yaml
|
||||||
|
(assoc-in [:spec :rules] [{:host fqdn
|
||||||
|
:http {:paths [{:backend {:serviceName "keycloak"
|
||||||
|
:servicePort 8080}}]}}
|
||||||
|
{:host fqdn
|
||||||
|
:http {:paths [{:backend {:serviceName "another_keycloak"
|
||||||
|
:servicePort 8081}}]}}]))]
|
||||||
|
(is (= desired-result (cut/replace-values-in-vector ingress-yaml [:spec :rules :host] fqdn))))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
31
src/test/resources/ingress_test.yaml
Normal file
31
src/test/resources/ingress_test.yaml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
apiVersion: networking.k8s.io/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: ingress-cloud
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-staging-issuer
|
||||||
|
nginx.ingress.kubernetes.io/proxy-body-size: "256m"
|
||||||
|
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||||
|
nginx.ingress.kubernetes.io/rewrite-target: /
|
||||||
|
nginx.ingress.kubernetes.io/proxy-connect-timeout: "300"
|
||||||
|
nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
|
||||||
|
nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- fqdn
|
||||||
|
secretName: keycloak-secret
|
||||||
|
rules:
|
||||||
|
- host: fqdn
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
serviceName: keycloak
|
||||||
|
servicePort: 8080
|
||||||
|
- host: fqdn
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
serviceName: another_keycloak
|
||||||
|
servicePort: 8081
|
Loading…
Reference in a new issue