suite: deployment template
release:
  name: gitea-unittests
  namespace: testing
templates:
  - templates/gitea/deployment.yaml
  - templates/gitea/config.yaml
tests:
  - it: Renders a deployment
    template: templates/gitea/deployment.yaml
    asserts:
      - hasDocuments:
          count: 1
      - containsDocument:
          kind: Deployment
          apiVersion: apps/v1
          name: gitea-unittests
  - it: Deployment with empty additionalConfigFromEnvs
    template: templates/gitea/deployment.yaml
    set:
      gitea.additionalConfigFromEnvs: []
    asserts:
      - hasDocuments:
          count: 1
      - exists:
          path: spec.template.spec.initContainers[1].env
      - lengthEqual:
          path: spec.template.spec.initContainers[1].env
          count: 6
      - isSubset:
          path: spec.template.spec.initContainers[1]
          content:
            env:
              - name: GITEA_APP_INI
                value: /data/gitea/conf/app.ini
              - name: GITEA_CUSTOM
                value: /data/gitea
              - name: GITEA_WORK_DIR
                value: /data
              - name: GITEA_TEMP
                value: /tmp/gitea
              - name: TMP_EXISTING_ENVS_FILE
                value: /tmp/existing-envs
              - name: ENV_TO_INI_MOUNT_POINT
                value: /env-to-ini-mounts
  - it: Deployment with standard additionalConfigFromEnvs
    template: templates/gitea/deployment.yaml
    set:
      gitea.additionalConfigFromEnvs: [{name: GITEA_database_HOST, value: my-db:123}, {name: GITEA_database_USER, value: my-user}]
    asserts:
      - hasDocuments:
          count: 1
      - exists:
          path: spec.template.spec.initContainers[1].env
      - lengthEqual:
          path: spec.template.spec.initContainers[1].env
          count: 8
      - isSubset:
          path: spec.template.spec.initContainers[1]
          content:
            env:
              - name: GITEA_APP_INI
                value: /data/gitea/conf/app.ini
              - name: GITEA_CUSTOM
                value: /data/gitea
              - name: GITEA_WORK_DIR
                value: /data
              - name: GITEA_TEMP
                value: /tmp/gitea
              - name: TMP_EXISTING_ENVS_FILE
                value: /tmp/existing-envs
              - name: ENV_TO_INI_MOUNT_POINT
                value: /env-to-ini-mounts
              - name: GITEA_database_HOST
                value: my-db:123
              - name: GITEA_database_USER
                value: my-user
  - it: Deployment with templated additionalConfigFromEnvs
    template: templates/gitea/deployment.yaml
    set:
      gitea.misc.host: my-db-host:321
      gitea.misc.user: my-db-user
      gitea.additionalConfigFromEnvs: [{name: GITEA_database_HOST, value: "{{ .Values.gitea.misc.host }}"}, {name: GITEA_database_USER, value: "{{ .Values.gitea.misc.user }}"}]
    asserts:
      - hasDocuments:
          count: 1
      - exists:
          path: spec.template.spec.initContainers[1].env
      - lengthEqual:
          path: spec.template.spec.initContainers[1].env
          count: 8
      - isSubset:
          path: spec.template.spec.initContainers[1]
          content:
            env:
              - name: GITEA_APP_INI
                value: /data/gitea/conf/app.ini
              - name: GITEA_CUSTOM
                value: /data/gitea
              - name: GITEA_WORK_DIR
                value: /data
              - name: GITEA_TEMP
                value: /tmp/gitea
              - name: TMP_EXISTING_ENVS_FILE
                value: /tmp/existing-envs
              - name: ENV_TO_INI_MOUNT_POINT
                value: /env-to-ini-mounts
              - name: GITEA_database_HOST
                value: my-db-host:321
              - name: GITEA_database_USER
                value: my-db-user
  - it: Deployment with additionalConfigFromEnvs templated secret name
    template: templates/gitea/deployment.yaml
    set:
      gitea.misc.existingSecret: my-db-secret
      gitea.additionalConfigFromEnvs[0]:
        name: GITEA_database_HOST
        valueFrom:
          secretKeyRef:
            name: "{{ .Values.gitea.misc.existingSecret }}"
            key: password
    asserts:
      - hasDocuments:
          count: 1
      - exists:
          path: spec.template.spec.initContainers[1].env
      - lengthEqual:
          path: spec.template.spec.initContainers[1].env
          count: 7
      - isSubset:
          path: spec.template.spec.initContainers[1]
          content:
            env:
              - name: GITEA_APP_INI
                value: /data/gitea/conf/app.ini
              - name: GITEA_CUSTOM
                value: /data/gitea
              - name: GITEA_WORK_DIR
                value: /data
              - name: GITEA_TEMP
                value: /tmp/gitea
              - name: TMP_EXISTING_ENVS_FILE
                value: /tmp/existing-envs
              - name: ENV_TO_INI_MOUNT_POINT
                value: /env-to-ini-mounts
              - name: GITEA_database_HOST
                valueFrom:
                  secretKeyRef:
                    name: "my-db-secret"
                    key: password
