apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[TechPreview] Backup"
crd: 0000_10_config-operator_01_backup-TechPreviewNoUpgrade.crd.yaml
tests:
  onCreate:
  - name: Should be able to create a Backup with a valid spec
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* 2 * * *"
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* 2 * * *"
          pvcName: etcdbackup-pvc
  - name: Should be able to create an EtcdBackup without the pvcName specified
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* 2 * * *"
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* 2 * * *"
  - name: Should be able to create a Backup with a valid schedule - At 22:00 on every day-of-week from Monday through Friday
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "0 22 * * 1-5"
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "0 22 * * 1-5"
          pvcName: etcdbackup-pvc
  - name: Should be able to create a Backup with a valid schedule - At 04:05 on Sunday.
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "5 4 * * SUN"
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "5 4 * * SUN"
          pvcName: etcdbackup-pvc
  - name: Should be able to create a Backup with a valid schedule - Predefined hourly
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "@hourly"
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "@hourly"
          pvcName: etcdbackup-pvc
  - name: Should fail to create an EtcdBackup with an invalid schedule - At 04:05 on invalid day FOO.
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "5 4 * * FOO"
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.schedule in body should match"
  - name: Should fail to create an EtcdBackup with an invalid schedule - Predefined typo @hourli instead of @hourly.
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "@hourli"
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.schedule in body should match"
  - name: Should fail to create an EtcdBackup with an invalid schedule - Non standard L last Friday in month
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* * * * 5L"
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.schedule in body should match"
  - name: Should fail to create an EtcdBackup with an invalid schedule - Non standard L 5th day before last day of month
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* * L-5 * *"
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.schedule in body should match"
  - name: Should fail to create an EtcdBackup with an invalid schedule - Non standard W closest weekday to 15th of month
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          schedule: "* * 15W * *"
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.schedule in body should match"
  - name: Should be able to create a Backup with a valid time zone - Africa/Banjul
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Africa/Banjul
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Africa/Banjul
          pvcName: etcdbackup-pvc
  - name: Should be able to create a Backup with a valid time zone - Etc/GMT-8
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Etc/GMT-8
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Etc/GMT-8
          pvcName: etcdbackup-pvc
  - name: Should be able to create a Backup with a valid time zone - Etc/UTC
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Etc/UTC
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: Etc/UTC
          pvcName: etcdbackup-pvc
  - name: Should be able to create a Backup with a valid time zone - America/Argentina/Catamarca
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: America/Argentina/Catamarca
          pvcName: etcdbackup-pvc
    expected: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: America/Argentina/Catamarca
          pvcName: etcdbackup-pvc
  - name: Should fail to create an EtcdBackup with an invalid time zone - GMT2
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: GMT2
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.timeZone in body should match"
  - name: Should fail to create an EtcdBackup with an invalid time zone - GMT+3
    initial: |
      apiVersion: config.openshift.io/v1alpha1
      kind: Backup
      spec:
        etcd:
          timeZone: GMT+3
          pvcName: etcdbackup-pvc
    expectedError: "spec.etcd.timeZone in body should match"
  
