suite: cnpg backup provider secret spec test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should create secret for s3 provider
    set:
      credentials:
        test:
          type: s3
          url: http://some-url
          encrKey: some-encr-key
          bucket: some-bucket
          secretKey: some-secret-key
          accessKey: some-access-key
      cnpg:
        my-pg:
          enabled: true
          user: test-user
          database: test-db
          password: test-password
          backups:
            enabled: true
            target: primary
            retentionPolicy: 10d
            credentials: test
            destinationPath: some-path
            manualBackups:
              - name: today
    asserts:
      - documentIndex: &secretDoc 2
        isKind:
          of: Secret
      - documentIndex: *secretDoc
        isAPIVersion:
          of: v1
      - documentIndex: *secretDoc
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds
      - documentIndex: *secretDoc
        equal:
          path: stringData
          value:
            ACCESS_SECRET_KEY: some-secret-key
            ACCESS_KEY_ID: some-access-key

  - it: should create secret for s3 provider with overridden region
    set:
      credentials:
        test:
          type: s3
          url: http://some-url
          region: some-region
          encrKey: some-encr-key
          bucket: some-bucket
          secretKey: some-secret-key
          accessKey: some-access-key
      cnpg:
        my-pg:
          enabled: true
          user: test-user
          database: test-db
          password: test-password
          backups:
            enabled: true
            target: primary
            retentionPolicy: 10d
            credentials: test
            destinationPath: some-path
            manualBackups:
              - name: today
    asserts:
      - documentIndex: *secretDoc
        isKind:
          of: Secret
      - documentIndex: *secretDoc
        isAPIVersion:
          of: v1
      - documentIndex: *secretDoc
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds
      - documentIndex: *secretDoc
        equal:
          path: stringData
          value:
            REGION: some-region
            ACCESS_SECRET_KEY: some-secret-key
            ACCESS_KEY_ID: some-access-key

  - it: should create secrets for s3 provider with customCA
    set:
      credentials:
        test:
          type: s3
          url: http://some-url
          encrKey: some-encr-key
          bucket: some-bucket
          secretKey: some-secret-key
          accessKey: some-access-key
          customCA: |-
            -----BEGIN CERTIFICATE-----
            ...
            -----END CERTIFICATE-----
      cnpg:
        my-pg:
          enabled: true
          user: test-user
          database: test-db
          password: test-password
          backups:
            enabled: true
            target: primary
            retentionPolicy: 10d
            credentials: test
            destinationPath: some-path
            manualBackups:
              - name: today
    asserts:
      - documentIndex: &secretCredDoc 3
        isKind:
          of: Secret
      - documentIndex: *secretCredDoc
        isAPIVersion:
          of: v1
      - documentIndex: *secretCredDoc
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds
      - documentIndex: *secretCredDoc
        equal:
          path: stringData
          value:
            ACCESS_SECRET_KEY: some-secret-key
            ACCESS_KEY_ID: some-access-key
      - documentIndex: &secretCADoc 2
        isKind:
          of: Secret
      - documentIndex: *secretCADoc
        isAPIVersion:
          of: v1
      - documentIndex: *secretCADoc
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-ca
      - documentIndex: *secretCADoc
        equal:
          path: stringData
          value:
            ca.crt: |-
              -----BEGIN CERTIFICATE-----
              ...
              -----END CERTIFICATE-----
