suite: Dependency checks | Customization integrity | postgresql
release:
  name: gitea-unittests
  namespace: testing
set:
  postgresql-ha:
    enabled: false
  postgresql:
    enabled: true
    global:
      postgresql:
        auth:
          password: gitea-password
          database: gitea-database
          username: gitea-username
        service:
          ports:
            postgresql: 1234
    primary:
      persistence:
        size: 1337Mi
tests:
  - it: "[postgresql] DB settings are applied as expected"
    template: charts/postgresql/templates/primary/statefulset.yaml
    asserts:
      - documentIndex: 0
        contains:
          path: spec.template.spec.containers[0].env
          content:
            name: POSTGRES_DATABASE
            value: "gitea-database"
      - documentIndex: 0
        contains:
          path: spec.template.spec.containers[0].env
          content:
            name: POSTGRES_USER
            value: "gitea-username"
  - it: "[postgresql] DB password is applied as expected"
    template: charts/postgresql/templates/secrets.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: data["password"]
          value: "Z2l0ZWEtcGFzc3dvcmQ="
  - it: "[postgresql] primary.persistence.size is applied as expected"
    template: charts/postgresql/templates/primary/statefulset.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: spec.volumeClaimTemplates[0].spec.resources.requests.storage
          value: "1337Mi"
  - it: "[postgresql] global.postgresql.service.ports.postgresql is applied as expected"
    template: charts/postgresql/templates/primary/svc.yaml
    asserts:
      - documentIndex: 0
        equal:
          path: spec.ports[0].port
          value: 1234
  - it: "[postgresql] renders the referenced service"
    template: charts/postgresql/templates/primary/svc.yaml
    asserts:
      - containsDocument:
          kind: Service
          apiVersion: v1
          name: gitea-unittests-postgresql
          namespace: testing
  - it: "[gitea] connects to postgresql service"
    template: templates/gitea/config.yaml
    asserts:
      - documentIndex: 0
        matchRegex:
          path: stringData.database
          pattern: HOST=gitea-unittests-postgresql.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
