{{- if .Values.master.testEnabled }}
apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-ui-test-{{ randAlphaNum 5 | lower }}"
  namespace: {{ template "jenkins.namespace" . }}
  annotations:
    "helm.sh/hook": test-success
spec:
  {{- if .Values.master.nodeSelector }}
  nodeSelector:
{{ toYaml .Values.master.nodeSelector | indent 4 }}
  {{- end }}
  {{- if .Values.master.tolerations }}
  tolerations:
{{ toYaml .Values.master.tolerations | indent 4 }}
  {{- end }}
  initContainers:
    - name: "test-framework"
      image: "dduportal/bats:0.4.0"
      command:
      - "bash"
      - "-c"
      - |
        set -ex
        # copy bats to tools dir
        cp -R /usr/local/libexec/ /tools/bats/
      volumeMounts:
      - mountPath: /tools
        name: tools
  containers:
    - name: {{ .Release.Name }}-ui-test
{{- if .Values.master.imageTag }}
      image: {{ .Values.master.image }}:{{ .Values.master.imageTag }}
{{- else }}
      image: {{ .Values.master.image }}:{{ .Values.master.tag }}
{{- end }}
      command: ["/tools/bats/bats", "-t", "/tests/run.sh"]
      volumeMounts:
      - mountPath: /tests
        name: tests
        readOnly: true
      - mountPath: /tools
        name: tools
  volumes:
  - name: tests
    configMap:
      name: {{ template "jenkins.fullname" . }}-tests
  - name: tools
    emptyDir: {}
  restartPolicy: Never
{{- end }}
