# helm_charts_consul-test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-ui-test-{{ randAlphaNum 5 | lower }}"
  annotations:
    "helm.sh/hook": test-success
spec:
  {{- if or .Values.test.rbac.create .Values.test.rbac.serviceAccountName }}
  serviceAccountName: {{ if .Values.test.rbac.create }}{{ template "consul.fullname" . }}-test{{ else }}"{{ .Values.test.rbac.serviceAccountName }}"{{ end }}
  {{- 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
      image: {{ .Values.test.image }}:{{ .Values.test.imageTag }}
      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 "consul.fullname" . }}-tests
  - name: tools
    emptyDir: {}
  restartPolicy: Never