suite: test extra envs for deployments
templates:
  - engine/deployment.yaml
  - engine/job-migrate.yaml
  - celery/deployment.yaml
  - telegram-polling/deployment.yaml
release:
  name: oncall
tests:
  - it: env=[] -> should support old syntax
    set:
      telegramPolling.enabled: true
      env:
        - name: SOME_VAR
          value: some_value
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: SOME_VAR
            value: some_value

  - it: env=map[] -> should set multiple envs
    set:
      telegramPolling.enabled: true
      env:
        SOME_VAR: some_value
        another_var: "another_value"
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: SOME_VAR
            value: some_value
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: another_var
            value: "another_value"

  - it: env=[] -> should add envs into initContainer
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
      - telegram-polling/deployment.yaml
    set:
      telegramPolling.enabled: true
      env:
        - name: SOME_VAR
          value: some_value
    asserts:
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: SOME_VAR
            value: some_value

  - it: env=map[] -> should add envs into initContainer
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
      - telegram-polling/deployment.yaml
    set:
      telegramPolling.enabled: true
      env:
        SOME_VAR: some_value
        another_var: "another_value"
    asserts:
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: SOME_VAR
            value: some_value
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: another_var
            value: "another_value"

  - it: database.type=postgresql and env=map[] -> should add envs into initContainer
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
      - telegram-polling/deployment.yaml
    set:
      telegramPolling.enabled: true
      database.type: postgresql
      postgresql.enabled: true
      env:
        SOME_VAR: some_value
        another_var: "another_value"
    asserts:
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: SOME_VAR
            value: some_value
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: another_var
            value: "another_value"

  - it: database.type=postgresql and env=[] -> should support old style for initContainer
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
      - telegram-polling/deployment.yaml
    set:
      telegramPolling.enabled: true
      database.type: postgresql
      postgresql.enabled: true
      env:
        - name: SOME_VAR
          value: some_value
    asserts:
      - contains:
          path: spec.template.spec.initContainers[0].env
          content:
            name: SOME_VAR
            value: some_value
