apiVersion: v1
kind: Pod
metadata:
  name: "{{ include "openfga.fullname" . }}-test-auth-secret"
  labels:
    {{- include "openfga.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: test-auth
      image: "busybox" 
      command: 
        - "/bin/sh"
        - "-ec"  # Adding -e to fail on error, -c to run command
        - |
          echo "Starting auth secret test..."
          
          # Check if secret is mounted
          if [ -z "$OPENFGA_AUTHN_PRESHARED_KEYS_SECRET" ]; then
            echo "ERROR: OPENFGA_AUTHN_PRESHARED_KEYS_SECRET environment variable is not set"
            exit 1
          fi
          
          echo "Secret environment variable is set to: $OPENFGA_AUTHN_PRESHARED_KEYS_SECRET"
          echo "Test completed successfully"
      env:
        - name: OPENFGA_AUTHN_PRESHARED_KEYS_SECRET
          valueFrom:
            secretKeyRef:
              name: test-auth-secret
              key: keys
  restartPolicy: Never
---
apiVersion: v1
kind: Secret
metadata:
  name: test-auth-secret
  labels:
    {{- include "openfga.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test
    "helm.sh/hook-weight": "-5"  # Ensure secret is created before the test pod
type: Opaque
data:
  keys: {{ "test-key-1,test-key-2" | b64enc }}