suite: cnpg backup validation test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should fail without name in manualBackups backup
    set:
      credentials:
        test:
          type: azure
          connectionString: some-connection-string
      cnpg:
        my-pg:
          enabled: true
          backups:
            enabled: true
            credentials: test
            manualBackups:
              - name:
    asserts:
      - failedTemplate:
          errorMessage: CNPG Backup - Expected non-empty [name] in [backups.manualBackups] entry

  - it: should fail with invalid name in manualBackups backup
    set:
      credentials:
        test:
          type: azure
          connectionString: some-connection-string
      cnpg:
        my-pg:
          enabled: true
          backups:
            enabled: true
            credentials: test
            manualBackups:
              - name: _invalid
    asserts:
      - failedTemplate:
          errorMessage: Name [test-release-name-common-test-cnpg-my-pg-backup-_invalid] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 253 characters.

  - it: should fail with invalid url in s3 credentials
    set:
      credentials:
        test:
          type: s3
          url: some-url
          bucket: some-bucket
          encrKey: some-encr-key
          accessKey: some-access-key
          secretKey: some-secret-key
      cnpg:
        my-pg:
          enabled: true
          user: test-user
          database: test-db
          password: test-password
          backups:
            enabled: true
            credentials: test
            manualBackups:
              - name: today
    asserts:
      - failedTemplate:
          errorMessage: CNPG Backup - Expected [url] in [credentials.test] to start with [http://] or [https://]. It was observed that sometimes can cause issues if it does not. Got [some-url]

  - it: should fail with both customCA and customCASecretRef specified in s3 credentials
    set:
      secret:
        my-secret:
          enabled: true
          data:
            my-key: |-
              -----BEGIN CERTIFICATE-----
              ...
              -----END CERTIFICATE-----
      credentials:
        test:
          type: s3
          url: https://valid-url.com
          bucket: some-bucket
          encrKey: some-encr-key
          accessKey: some-access-key
          secretKey: some-secret-key
          customCA: |-
            -----BEGIN CERTIFICATE-----
            ...
            -----END CERTIFICATE-----
          customCASecretRef:
            name: my-secret
            key: my-key
      cnpg:
        my-pg:
          enabled: true
          user: test-user
          database: test-db
          password: test-password
          backups:
            enabled: true
            credentials: test
            manualBackups:
              - name: today
    asserts:
      - failedTemplate:
          errorMessage: CNPG Backup - Both [customCA] and [customCASecretRef] defined in [credentials.test]. Choose one
