suite: Dependency checks | Customization integrity | postgresql-ha
release:
  name: gitea-unittests
  namespace: testing
set:
  postgresql:
    enabled: false
  postgresql-ha:
    enabled: true
    global:
      postgresql:
        database: gitea-database
        password: gitea-password
        username: gitea-username
    postgresql:
      repmgrPassword: custom-password-repmgr
      postgresPassword: custom-password-postgres
      password: custom-password-overwritten-by-global-postgresql-password
    pgpool:
      adminPassword: custom-password-pgpool
    service:
      ports:
        postgresql: 1234
    persistence:
      size: 1337Mi
tests:
  - it: "[postgresql-ha] DB settings are applied as expected"
    template: charts/postgresql-ha/templates/postgresql/statefulset.yaml
    asserts:
      - documentIndex: 0
        contains:
          path: spec.template.spec.containers[0].env
          content:
            name: POSTGRES_DB
            value: "gitea-database"
      - documentIndex: 0
        contains:
          path: spec.template.spec.containers[0].env
          content:
            name: POSTGRES_USER
            value: "gitea-username"
  - it: "[postgresql-ha] DB passwords are applied as expected"
    template: charts/postgresql-ha/templates/postgresql/secrets.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: data["repmgr-password"]
          value: "Y3VzdG9tLXBhc3N3b3JkLXJlcG1ncg=="
      - documentIndex: 0
        equal:
          path: data["postgres-password"]
          value: "Y3VzdG9tLXBhc3N3b3JkLXBvc3RncmVz"
      - documentIndex: 0
        equal:
          path: data["password"]
          value: "Z2l0ZWEtcGFzc3dvcmQ=" # postgresql-ha.postgresql.password is overwritten by postgresql-ha.global.postgresql.password and should not be referenced here
  - it: "[postgresql-ha] pgpool.adminPassword is applied as expected"
    template: charts/postgresql-ha/templates/pgpool/secrets.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: data["admin-password"]
          value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA=="
  - it: "[postgresql-ha] pgpool.adminPassword is applied as expected"
    template: charts/postgresql-ha/templates/pgpool/secrets.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: data["admin-password"]
          value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA=="
  - it: "[postgresql-ha] pgpool.adminPassword is applied as expected"
    template: charts/postgresql-ha/templates/pgpool/secrets.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: data["admin-password"]
          value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA=="
  - it: "[postgresql-ha] persistence.size is applied as expected"
    template: charts/postgresql-ha/templates/postgresql/statefulset.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: spec.volumeClaimTemplates[0].spec.resources.requests.storage
          value: "1337Mi"
  - it: "[postgresql-ha] service.ports.postgresql is applied as expected"
    template: charts/postgresql-ha/templates/pgpool/service.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: spec.ports[0].port
          value: 1234
  - it: "[postgresql-ha] renders the referenced service"
    template: charts/postgresql-ha/templates/pgpool/service.yaml
    asserts:
      - containsDocument:
          kind: Service
          apiVersion: v1
          name: gitea-unittests-postgresql-ha-pgpool
          namespace: testing
  - it: "[gitea] connects to pgpool service"
    template: templates/gitea/config.yaml
    asserts:
      - documentIndex: 0
        matchRegex:
          path: stringData.database
          pattern: HOST=gitea-unittests-postgresql-ha-pgpool.testing.svc.cluster.local:1234
  - it: "[gitea] connects to configured database"
    template: templates/gitea/config.yaml
    asserts:
      - documentIndex: 0
        matchRegex:
          path: stringData.database
          pattern: NAME=gitea-database
      - documentIndex: 0
        matchRegex:
          path: stringData.database
          pattern: USER=gitea-username
      - documentIndex: 0
        matchRegex:
          path: stringData.database
          pattern: PASSWD=gitea-password
