suite: cnpg scheduled backup spec test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should generate correct spec
    set:
      credentials:
        test:
          type: s3
          url: http://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
            target: primary
            retentionPolicy: 10d
            credentials: test
            destinationPath: some-path
            scheduledBackups:
              - name: daily
                schedule: "0 0 * * *"
                suspend: true
              - name: weekly
                schedule: "0 0 * * 0"
                immediate: true
                backupOwnerReference: cluster
              - name: daily-magic-value
                schedule: "@daily"
              - name: continuous
                schedule: "* * * * *"
    asserts:
      - documentIndex: &cnpgDoc0 0
        isKind:
          of: ScheduledBackup
      - documentIndex: *cnpgDoc0
        isAPIVersion:
          of: postgresql.cnpg.io/v1
      - documentIndex: *cnpgDoc0
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-sched-backup-daily
      - documentIndex: *cnpgDoc0
        equal:
          path: spec
          value:
            schedule: "0 0 * * *"
            backupOwnerReference: none
            suspend: true
            immediate: false
            cluster:
              name: test-release-name-common-test-cnpg-my-pg
      - documentIndex: &cnpgDoc1 1
        isKind:
          of: ScheduledBackup
      - documentIndex: *cnpgDoc1
        isAPIVersion:
          of: postgresql.cnpg.io/v1
      - documentIndex: *cnpgDoc1
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-sched-backup-weekly
      - documentIndex: *cnpgDoc1
        equal:
          path: spec
          value:
            schedule: "0 0 * * 0"
            backupOwnerReference: cluster
            suspend: false
            immediate: true
            cluster:
              name: test-release-name-common-test-cnpg-my-pg
      - documentIndex: &cnpgDoc2 2
        isKind:
          of: ScheduledBackup
      - documentIndex: *cnpgDoc2
        isAPIVersion:
          of: postgresql.cnpg.io/v1
      - documentIndex: *cnpgDoc2
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-sched-backup-daily-magic-value
      - documentIndex: *cnpgDoc2
        equal:
          path: spec
          value:
            schedule: "@daily"
            backupOwnerReference: none
            suspend: false
            immediate: false
            cluster:
              name: test-release-name-common-test-cnpg-my-pg
      - documentIndex: &cnpgDoc3 3
        isKind:
          of: ScheduledBackup
      - documentIndex: *cnpgDoc3
        isAPIVersion:
          of: postgresql.cnpg.io/v1
      - documentIndex: *cnpgDoc3
        equal:
          path: metadata.name
          value: test-release-name-common-test-cnpg-my-pg-sched-backup-continuous
      - documentIndex: *cnpgDoc3
        equal:
          path: spec
          value:
            schedule: "* * * * *"
            backupOwnerReference: none
            suspend: false
            immediate: false
            cluster:
              name: test-release-name-common-test-cnpg-my-pg
