suite: test broker secrets creation
release:
  name: oncall
templates:
  - engine/deployment.yaml
  - celery/deployment.yaml
  - secrets.yaml
tests:
  - it: externalRedis.password and broker.type="rabbitmq" -> should create secret -redis-external
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
    set:
      telegramPolling.enabled: true
      rabbitmq.enabled: true
      redis.enabled: false
      broker.type: rabbitmq
      externalRedis:
        host: redis.example.com
        username: user123
        password: abcd123
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: REDIS_USERNAME
            value: user123
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: oncall-redis-external
                key: redis-password
      - containsDocument:
          kind: Secret
          apiVersion: v1
          metadata.name: oncall-redis-external
        template: secrets.yaml
      - equal:
          path: data.redis-password
          value: abcd123
          decodeBase64: true
        documentIndex: 1
        template: secrets.yaml
  - it: |
      externalRedis.password and externalRabbitmq.password -> should create secret
      -redis-external and -rabbitmq-external
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
    set:
      rabbitmq.enabled: false
      redis.enabled: false
      broker.type: rabbitmq
      externalRedis:
        host: redis.example.com
        username: user123
        password: abcd123
      externalRabbitmq:
        host: custom-host
        user: custom-user
        password: custom-password
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: RABBITMQ_USERNAME
            value: custom-user
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: RABBITMQ_PASSWORD
            valueFrom:
              secretKeyRef:
                key: rabbitmq-password
                name: oncall-rabbitmq-external
      - containsDocument:
          kind: Secret
          apiVersion: v1
          metadata.name: oncall-rabbitmq-external
        template: secrets.yaml
      - equal:
          path: data.rabbitmq-password
          value: custom-password
          decodeBase64: true
        documentIndex: 1
        template: secrets.yaml
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: REDIS_USERNAME
            value: user123
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: oncall-redis-external
                key: redis-password
      - containsDocument:
          kind: Secret
          apiVersion: v1
          metadata.name: oncall-redis-external
        template: secrets.yaml
      - equal:
          path: data.redis-password
          value: abcd123
          decodeBase64: true
        documentIndex: 2
        template: secrets.yaml
