Skip to content
Snippets Groups Projects
Commit c4eeb4f6 authored by OZG-Cloud Team's avatar OZG-Cloud Team
Browse files

Merge branch 'master' into knecht-root-recht-stage

parents 0217e08b dd47e693
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 37 deletions
......@@ -5,6 +5,7 @@ import java.time.LocalDate;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Component;
import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.RequiredArgsConstructor;
@Component
......@@ -17,10 +18,17 @@ public class VorgangNummerSupplier {
static final int SUFFIX_LENGTH = 6;
public String get() {
return get(SUFFIX_LENGTH);
}
public String get(int suffixLength) {
if (suffixLength <1){
throw new TechnicalException("Suffix length must be at least 1");
}
var today = LocalDate.now();
var lastYearNumber = today.getYear() % 10;
return VORGANGNUMMER_TEMPLATE.formatted(lastYearNumber, today.getMonthValue(), today.getDayOfMonth(),
RandomStringUtils.random(SUFFIX_LENGTH, BASE30_ALPHABET));
RandomStringUtils.random(suffixLength, BASE30_ALPHABET));
}
}
package de.ozgcloud.eingang.common.vorgang;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.time.LocalDate;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.test.util.ReflectionTestUtils;
import de.ozgcloud.common.errorhandling.TechnicalException;
class VorgangNummerSupplierTest {
......@@ -26,7 +28,25 @@ class VorgangNummerSupplierTest {
void shouldAddSuffix() {
var result = vorgangNummerSupplier.get();
assertThat(result).hasSize(11);
assertThat(getSuffix(result)).hasSize(VorgangNummerSupplier.SUFFIX_LENGTH);
}
@Test
void shouldHaveSuffixSize() {
var result = vorgangNummerSupplier.get(3);
assertThat(getSuffix(result)).hasSize(3);
}
@DisplayName("should throw exception when")
@ParameterizedTest(name = "suffix length {0}")
@ValueSource(ints = { -1, 0 })
void shouldThrowException(int suffixLength) {
assertThrows(TechnicalException.class, () -> vorgangNummerSupplier.get(suffixLength));
}
private String getSuffix(String string) {
return string.substring(string.indexOf('-') + 1);
}
@Test
......
......@@ -4,4 +4,4 @@ set -e
helm template ./src/main/helm/ -f src/test/helm-linter-values.yaml
helm lint -f src/test/helm-linter-values.yaml ./src/main/helm/
cd src/main/helm && helm unittest -f '../../test/helm/*.yaml' -v '../../test/unit-values.yaml' .
\ No newline at end of file
cd src/main/helm && helm unittest -f '../../test/helm/*.yaml' .
\ No newline at end of file
{{/* vim: set filetype=mustache: */}}
{{/* Truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec) */}}
{{/* Name */}}
{{- define "app.name" -}}
{{- default .Release.Name | toString | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* error check 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec) */}}
{{/* Namespace */}}
{{- define "app.namespace" -}}
{{- default .Release.Namespace | toString | trunc 63 | trimSuffix "-" -}}
{{- if gt (len (.Release.Namespace)) 63 -}}
{{- fail (printf ".Release.Namespace %s ist zu lang (max. 63 Zeichen)" .Release.Namespace) -}}
{{- end -}}
{{/* Version */}}
{{- define "app.version" -}}
{{- default .Chart.Version | toString | trunc 63 | trimSuffix "-" -}}
{{ printf "%s" .Release.Namespace }}
{{- end -}}
{{/* Chart: Name + Version */}}
{{- define "app.chart" -}}
{{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- if gt (len (printf "%s-%s" .Chart.Name .Chart.Version)) 63 -}}
{{- fail (printf ".Chart.Name-.Chart.Version %s-%s ist zu lang (max. 63 Zeichen)" .Chart.Name .Chart.Version) -}}
{{- end -}}
{{ printf "%s-%s" .Chart.Name .Chart.Version }}
{{- end -}}
{{/* Managed-by -> On Helm, this value is always Helm */}}
{{- define "app.managedBy" -}}
{{- default .Release.Service | toString | trunc 63 | trimSuffix "-" -}}
{{- if gt (len (.Release.Service)) 63 -}}
{{- fail (printf ".Release.Service %s ist zu lang (max. 63 Zeichen)" .Release.Service) -}}
{{- end -}}
{{ printf "%s" .Release.Service }}
{{- end -}}
{{/* Default Labels: Helm recommended best-practice labels https://helm.sh/docs/chart_best_practices/labels/ */}}
{{- define "app.defaultLabels" }}
app.kubernetes.io/instance: afm-adapter
app.kubernetes.io/managed-by: {{ include "app.managedBy" . }}
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/name: {{ .Release.Name }}
app.kubernetes.io/part-of: ozgcloud
app.kubernetes.io/version: {{ include "app.version" . }}
app.kubernetes.io/version: {{ .Chart.Version }}
app.kubernetes.io/namespace: {{ include "app.namespace" . }}
helm.sh/chart: {{ include "app.chart" . }}
ozg-component: eingangsadapter
{{- end -}}
{{- define "app.matchLabels" }}
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/name: {{ .Release.Name }}
app.kubernetes.io/namespace: {{ include "app.namespace" . }}
{{- end -}}
......
......@@ -25,7 +25,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "app.name" . }}
name: {{ .Release.Name }}
namespace: {{ include "app.namespace" . }}
labels:
{{- include "app.defaultLabels" . | indent 4 }}
......@@ -56,7 +56,7 @@ spec:
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/name: {{ .Release.Name }}
containers:
- env:
{{- range (.Values.env).grpc }}
......@@ -159,7 +159,7 @@ spec:
{{- if .Values.imagePullSecret }}
- name: {{ .Values.imagePullSecret }}
{{ else }}
- name: {{ include "app.name" . }}-image-pull-secret
- name: {{ .Release.Name }}-image-pull-secret
{{- end }}
restartPolicy: Always
{{- with .Values.hostAliases }}
......
......@@ -26,7 +26,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "app.name" . }}-image-pull-secret
name: {{ .Release.Name }}-image-pull-secret
namespace: {{ include "app.namespace" . }}
type: kubernetes.io/dockerconfigjson
data:
......
......@@ -37,7 +37,7 @@ metadata:
cert-manager.io/cluster-issuer: letsencrypt-prod
{{- end }}
{{- end }}
name: {{ include "app.name" . }}
name: {{ .Release.Name }}
namespace: {{ include "app.namespace" . }}
spec:
{{- if and (.Values.ingress).className }}
......@@ -50,7 +50,7 @@ spec:
service:
port:
number: 8080
name: {{ include "app.name" . }}
name: {{ .Release.Name }}
path: ''
pathType: ImplementationSpecific
host: {{ include "app.ingress.host" . }}
......@@ -61,7 +61,7 @@ spec:
{{- if (.Values.ingress).tlsSecretName }}
secretName: {{ (.Values.ingress).tlsSecretName }}
{{- else }}
secretName: {{ .Values.ozgcloud.bezeichner }}-{{ include "app.name" . }}-tls
secretName: {{ .Values.ozgcloud.bezeichner }}-{{ .Release.Name }}-tls
{{- end }}
{{- end }}
{{- end -}}
\ No newline at end of file
......@@ -26,7 +26,7 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: network-policy-{{ include "app.name" .}}
name: network-policy-{{ .Release.Name}}
namespace: {{ .Release.Namespace }}
spec:
podSelector:
......
......@@ -25,7 +25,7 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "app.name" . }}
name: {{ .Release.Name }}
namespace: {{ include "app.namespace" . }}
labels:
{{- include "app.defaultLabels" . | indent 4 }}
......
......@@ -25,7 +25,7 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "app.name" . }}
name: {{ .Release.Name }}
namespace: {{ include "app.namespace" . }}
labels:
{{- include "app.defaultLabels" . | indent 4 }}
......
......@@ -25,7 +25,7 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "app.name" . }}-test-ingress"
name: "{{ .Release.Name }}-test-ingress"
labels:
{{- include "app.matchLabels" . | nindent 4 }}
annotations:
......
......@@ -25,7 +25,7 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "app.name" . }}-test-connection"
name: "{{ .Release.Name }}-test-connection"
labels:
{{- include "app.matchLabels" . | nindent 4 }}
annotations:
......@@ -35,5 +35,5 @@ spec:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "app.name" . }}:8080/ws/intelliform_formDatas.wsdl']
args: ['{{ .Release.Name }}:8080/ws/intelliform_formDatas.wsdl']
restartPolicy: Never
......@@ -22,7 +22,34 @@
# unter der Lizenz sind dem Lizenztext zu entnehmen.
#
ozgcloud:
bundesland: sh
environment: test
bezeichner: helm
\ No newline at end of file
suite: test deyploment less than 63 chars
release:
name: eingang-manager
namespace: sh-helm-test
chart:
name: eingang-manager
set:
ozgcloud.environment: test
templates:
- templates/deployment.yaml
tests:
- it: should fail on .Release.Namespace length longer than 63 characters
release:
namespace: test1234567890123123456789012345678901234567890123456789012345678901234567890123456789012345678904567890
asserts:
- failedTemplate:
errorMessage: .Release.Namespace test1234567890123123456789012345678901234567890123456789012345678901234567890123456789012345678904567890 ist zu lang (max. 63 Zeichen)
- it: should not fail on .Release.Namespace length less than 63 characters
asserts:
- notFailedTemplate: {}
- it: should fail on .Chart.Name-.Chart.Version length longer than 63 characters
chart:
version: 1.0-test1234567890123123456789012345678901234567890123456789012345678901234567890123456789012345678904567890
asserts:
- failedTemplate:
errorMessage: .Chart.Name-.Chart.Version Intelliform-Adapter-1.0-test1234567890123123456789012345678901234567890123456789012345678901234567890123456789012345678904567890 ist zu lang (max. 63 Zeichen)
- it: should not fail on .Chart.Name-.Chart.Version length less than 63 characters
asserts:
- notFailedTemplate: {}
\ No newline at end of file
......@@ -25,6 +25,8 @@
suite: deployment bindings
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: should have temp-dir volume
asserts:
......
......@@ -28,6 +28,8 @@ release:
namespace: sh-helm-test
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: check default values
asserts:
......
......@@ -30,6 +30,8 @@ templates:
- templates/deployment.yaml
- templates/service_monitor.yaml
- templates/service.yaml
set:
ozgcloud.environment: test
tests:
- it: check default labels
asserts:
......
......@@ -25,6 +25,8 @@
suite: test environments
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: check customList
template: deployment.yaml
......@@ -39,8 +41,6 @@ tests:
name: my_test_environment_name
value: "A test value"
- it: check customList test value is not set by default
set:
ozgcloud.environment: test
template: deployment.yaml
asserts:
- notContains:
......
......@@ -28,6 +28,9 @@ release:
namespace: sh-helm-test
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: should not set hostAliases
asserts:
......
......@@ -28,6 +28,8 @@ release:
namespace: sh-helm-test
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: should use default imagePull secret
asserts:
......
......@@ -27,6 +27,8 @@ release:
name: afm-adapter
templates:
- templates/deployment.yaml
set:
ozgcloud.environment: test
tests:
- it: test resources
set:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment