apiVersion: v1
kind: Pod
metadata:
  name: "{{ include  "mattermost-team-edition.fullname" . }}-test-{{ randAlphaNum 5 | lower }}"
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
  annotations:
    "helm.sh/hook": test-success
spec:
  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 }}-test
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    command: ["/tools/bats/bats", "-t", "/tests/run.sh"]
    volumeMounts:
    - mountPath: /tests
      name: tests
      readOnly: true
    - mountPath: /tools
      name: tools
  volumes:
  - name: tests
    configMap:
      name: {{ include  "mattermost-team-edition.fullname" . }}-tests
  - name: tools
    emptyDir: {}
  restartPolicy: Never
