suite: test MySQL envs for deployments
templates:
  - engine/deployment.yaml
  - engine/job-migrate.yaml
  - celery/deployment.yaml
  - telegram-polling/deployment.yaml
release:
  name: oncall
tests:
  - it: mariadb.enabled=false -> external MySQL default settings
    set:
      telegramPolling.enabled: true
      mariadb.enabled: false
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: DATABASE_TYPE
        not: true
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_DB_NAME
            value: oncall
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_PORT
            value: "3306"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_USER
            value: root
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_HOST
            value: oncall-mariadb

  - it: externalMysql -> use external MySQL custom settings
    set:
      telegramPolling.enabled: true
      mariadb.enabled: false
      externalMysql:
        host: test-host
        port: 5555
        db_name: grafana_oncall
        user: test_user
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_DB_NAME
            value: grafana_oncall
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_PORT
            value: "5555"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_USER
            value: test_user
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_HOST
            value: test-host

  - it: externalMysql -> use external MySQL custom settings with additional options
    set:
      telegramPolling.enabled: true
      mariadb.enabled: false
      externalMysql:
        host: test-host
        port: 5555
        db_name: grafana_oncall
        user: test_user
        options: "ssl_ca=/mnt/ssl/ca.crt ssl_key=/mnt/ssl/client.key ssl_cert=/mnt/ssl/client.crt"
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_OPTIONS
            value: "ssl_ca=/mnt/ssl/ca.crt ssl_key=/mnt/ssl/client.key ssl_cert=/mnt/ssl/client.crt"

  - it: mariadb.enabled=true -> internal MySQL default settings
    set:
      telegramPolling.enabled: true
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_DB_NAME
            value: oncall
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_PORT
            value: "3306"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_USER
            value: root
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_HOST
            value: oncall-mariadb

  - it: mariadb.auth -> internal MySQL custom settings
    set:
      telegramPolling.enabled: true
      mariadb:
        auth:
          database: grafana_oncall
          username: grafana_oncall
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_DB_NAME
            value: grafana_oncall
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_PORT
            value: "3306"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_USER
            value: grafana_oncall
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: MYSQL_HOST
            value: oncall-mariadb
