Commit 51b35801 authored by Martin Schurz's avatar Martin Schurz
Browse files

fix: update tests for CronJob

parent c18ea75b
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -12,12 +12,16 @@ items:
  metadata:
    name: "{{ template "trackableappname" $ }}-{{ $jobName}}"
    annotations:
      {{ if $.Values.gitlab.app }}app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}{{ end }}
      {{ if $.Values.gitlab.env }}app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}{{ end }}
      {{- if $.Values.gitlab.app }}
      app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}
      {{- end }}
      {{- if $.Values.gitlab.env }}
      app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}
      {{- end }}
    labels:
      track: "{{ $.Values.application.track }}"
      tier: "{{ $.Values.application.tier }}"
      {{ include "sharedlabels" $ | nindent 6 }}
      {{- include "sharedlabels" $ | nindent 6 }}
  spec:
    concurrencyPolicy: {{ default "Forbid" $jobConfig.concurrencyPolicy }}
    failedJobsHistoryLimit: {{ default 1 $jobConfig.failedJobsHistoryLimit }}
@@ -36,8 +40,12 @@ items:
          metadata:
            annotations:
              checksum/application-secrets: "{{ $.Values.application.secretChecksum }}"
              {{ if $.Values.gitlab.app }}app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}{{ end }}
              {{ if $.Values.gitlab.env }}app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}{{ end }}
              {{- if $.Values.gitlab.app }}
              app.gitlab.com/app: {{ $.Values.gitlab.app | quote }}
              {{- end }}
              {{- if $.Values.gitlab.env }}
              app.gitlab.com/env: {{ $.Values.gitlab.env | quote }}
              {{- end }}
              {{- if $.Values.podAnnotations }}
              {{- toYaml $.Values.podAnnotations | nindent 14 }}
              {{- end }}
+17 −104
Original line number Diff line number Diff line
@@ -161,14 +161,7 @@ func TestCronjobSchedule(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -226,14 +219,7 @@ func TestCronjobImage(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -368,14 +354,7 @@ func TestCronjobLivenessAndReadiness(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -436,14 +415,7 @@ func TestCronjobNodeSelector(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -527,14 +499,7 @@ func TestCronjobTolerations(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -607,12 +572,7 @@ func TestCronjobResources(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -626,7 +586,6 @@ func TestCronjobResources(t *testing.T) {

func TestCronjobTemplateWithVolumeMounts(t *testing.T) {
	releaseName := "cronjob-with-volume-mounts-test"
	templates := []string{"templates/cronjob.yaml"}

	hostPathDirectoryType := coreV1.HostPathDirectory
	configMapOptional := false
@@ -697,18 +656,11 @@ func TestCronjobTemplateWithVolumeMounts(t *testing.T) {

	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
			options := &helm.Options{
				ValuesFiles: tc.valueFiles,
				SetValues:   tc.values,
			}
			output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates)

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -817,14 +769,7 @@ func TestCronjobAffinity(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -838,7 +783,6 @@ func TestCronjobAffinity(t *testing.T) {

func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) {
	releaseName := "cronjob-with-extra-envfrom-test"
	templates := []string{"templates/cronjob.yaml"}

	tcs := []struct {
		name            string
@@ -892,17 +836,10 @@ func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) {

	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
			options := &helm.Options{
				SetValues: tc.values,
			}
			output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates)

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -915,7 +852,6 @@ func TestCronJobTemplateWithExtraEnvFrom(t *testing.T) {

func TestCronJobTemplateWithSecurityContext(t *testing.T) {
	releaseName := "cronjob-with-security-context"
	templates := []string{"templates/cronjob.yaml"}

	tcs := []struct {
		name                        string
@@ -933,17 +869,11 @@ func TestCronJobTemplateWithSecurityContext(t *testing.T) {

	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
			options := &helm.Options{
				SetValues: tc.values,
			}
			output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates)

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -956,7 +886,6 @@ func TestCronJobTemplateWithSecurityContext(t *testing.T) {

func TestCronJobTemplateWithContainerSecurityContext(t *testing.T) {
	releaseName := "cronjob-with-container-security-context"
	templates := []string{"templates/cronjob.yaml"}

	tcs := []struct {
		name                        				string
@@ -976,17 +905,11 @@ func TestCronJobTemplateWithContainerSecurityContext(t *testing.T) {

	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			opts := &helm.Options{
			options := &helm.Options{
				SetValues: tc.values,
			}
			output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates)

			if err != nil {
				t.Error(err)
				return
			}

			require.NotRegexp(t, regexp.MustCompile("\n[[:space:]]*\n"), output, "found empty lines in output")
			output := renderTemplate(t, options, releaseName, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -1088,12 +1011,7 @@ func TestCronjobImagePullSecrets(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)
@@ -1183,12 +1101,7 @@ func TestCronjobPodAnnotations(t *testing.T) {
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output, err := helm.RenderTemplateE(t, options, helmChartPath, tc.Release, []string{"templates/cronjob.yaml"})

			if err != nil {
				t.Error(err)
				return
			}
			output := renderTemplate(t, options, tc.Release, []string{"templates/cronjob.yaml"}, nil)

			var cronjobs batchV1beta1.CronJobList
			helm.UnmarshalK8SYaml(t, output, &cronjobs)