From 8710defbb40c53046f888d43192b4dc62124714e Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 8 Oct 2024 18:18:04 +0200
Subject: [PATCH] seperate environment property functions

---
 src/main/helm/templates/_helpers.tpl          | 16 ++++++++++++++
 src/main/helm/templates/deployment.yaml       |  4 ++--
 ...ment_nachrichten_manager_address_test.yaml | 21 ++++++++++++++-----
 .../deployment_vorgang_manager_env_test.yaml  | 14 +++++++++++--
 4 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl
index 8df40f5ed..fe0cc4a15 100644
--- a/src/main/helm/templates/_helpers.tpl
+++ b/src/main/helm/templates/_helpers.tpl
@@ -77,6 +77,22 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }}
 {{ printf "http://%s.%s:8080" .Values.administrationName .Release.Namespace }}
 {{- end -}}
 
+{{- define "app.getApplicationAddress" -}}
+{{- if .Values.applicationAddress -}}
+{{  .Values.applicationAddress }}
+{{- else -}}
+{{ printf "dns:///%s.%s:9090" .Values.vorgangmanagerName .Release.Namespace }}
+{{- end -}}
+{{- end -}}
+
+{{- define "app.getNachrichtenManagerAddress" -}}
+{{- if .Values.nachrichtenManagerAddress -}}
+{{  .Values.nachrichtenManagerAddress }}
+{{- else -}}
+{{ printf "%s.%s:9090" .Values.vorgangmanagerName .Release.Namespace }}
+{{- end -}}
+{{- end -}}
+
 {{- define "app.databaseSecretName" -}}
 {{- if (.Values.database).secretName -}}
 {{  .Values.database.secretName }}
diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml
index 65b3f7d20..52451fef2 100644
--- a/src/main/helm/templates/deployment.yaml
+++ b/src/main/helm/templates/deployment.yaml
@@ -64,9 +64,9 @@ spec:
           - name: spring_profiles_active
             value: {{ include "app.envSpringProfiles" . }}
           - name: ozgcloud_application_address
-            value: {{ include "app.ozgcloud_vorgangmanager_address" . }}
+            value: {{ include "app.getApplicationAddress" . }}
           - name: ozgcloud_nachrichten-manager_address
-            value: {{ include "app.ozgcloud_vorgangmanager_address" . }}
+            value: {{ include "app.getNachrichtenManagerAddress" . }}
           {{- if .Values.env.ozgcloudAktenzeichen.enabled }}
           - name: ozgcloud_aktenzeichen
             value: {{ .Values.env.ozgcloudAktenzeichen.value | default "de.ozgcloud.vorgang.vorgang.AktenzeichenProviderEA" }}
diff --git a/src/test/helm/deployment_nachrichten_manager_address_test.yaml b/src/test/helm/deployment_nachrichten_manager_address_test.yaml
index f8d47d58c..38907692a 100644
--- a/src/test/helm/deployment_nachrichten_manager_address_test.yaml
+++ b/src/test/helm/deployment_nachrichten_manager_address_test.yaml
@@ -22,23 +22,34 @@
 # unter der Lizenz sind dem Lizenztext zu entnehmen.
 #
 
-suite: test environments nachrichten-manager_url
+suite: deployment nachrichten-manager_url
 release:
   name: vorgang-manager
-  namespace: sh-helm-test
+  namespace: by-helm-test
 templates:
   - templates/deployment.yaml
 set:
-  baseUrl: test.sh.ozg-cloud.de
+  baseUrl: test.by.ozg-cloud.de
   ozgcloud:
     environment: dev
     bezeichner: helm
   imagePullSecret: test-image-pull-secret
 tests:
-  - it: check if nachrichten-manager address is correct
+  - it: should generate nachrichten-manager address if not exists
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
             name: ozgcloud_nachrichten-manager_address
-            value:  dns:///vorgang-manager.sh-helm-test:9090
+            value:  vorgang-manager.by-helm-test:9090
+
+  - it: should have set nachrichten-manager address
+    set:
+      nachrichtenManagerAddress: localSettedAddress
+    asserts:
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: ozgcloud_nachrichten-manager_address
+            value:  localSettedAddress
+  
\ No newline at end of file
diff --git a/src/test/helm/deployment_vorgang_manager_env_test.yaml b/src/test/helm/deployment_vorgang_manager_env_test.yaml
index 140a1715e..88948502d 100644
--- a/src/test/helm/deployment_vorgang_manager_env_test.yaml
+++ b/src/test/helm/deployment_vorgang_manager_env_test.yaml
@@ -35,10 +35,20 @@ set:
     bezeichner: helm
   imagePullSecret: test-image-pull-secret
 tests:
-  - it: check if application address is set
+  - it: should generate application address if its not set
     asserts:
       - contains:
           path: spec.template.spec.containers[0].env
           content:
             name: ozgcloud_application_address
-            value: dns:///vorgang-manager.by-helm-test:9090
\ No newline at end of file
+            value: dns:///vorgang-manager.by-helm-test:9090
+            
+  - it: should keep application address if its set
+    set:
+      applicationAddress: localSettedAddress
+    asserts:
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: ozgcloud_application_address
+            value: localSettedAddress
\ No newline at end of file
-- 
GitLab