suite: volumeSnapshotClass spec test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should generate correct spec
    set:
      some_driver: csi-hostpath-snapshots
      some_key: parameter1
      some_value: value1
      volumeSnapshotClass:
        example1:
          enabled: true
          driver: csi-hostpath-snapshots
          deletionPolicy: Delete
        example2:
          enabled: true
          driver: "{{ .Values.some_driver }}"
          parameters:
            "{{ .Values.some_key }}": "{{ .Values.some_value }}"
            parameter2: 5
    asserts:
      - documentIndex: &volumeSnapshotDoc 0
        isKind:
          of: VolumeSnapshotClass
      - documentIndex: *volumeSnapshotDoc
        isAPIVersion:
          of: snapshot.storage.k8s.io/v1
      - documentIndex: *volumeSnapshotDoc
        equal:
          path: driver
          value: csi-hostpath-snapshots
      - documentIndex: *volumeSnapshotDoc
        equal:
          path: deletionPolicy
          value: Delete
      - documentIndex: &otherVolumeSnapshotDoc 1
        isKind:
          of: VolumeSnapshotClass
      - documentIndex: *otherVolumeSnapshotDoc
        isAPIVersion:
          of: snapshot.storage.k8s.io/v1
      - documentIndex: *otherVolumeSnapshotDoc
        equal:
          path: driver
          value: csi-hostpath-snapshots
      - documentIndex: *otherVolumeSnapshotDoc
        equal:
          path: deletionPolicy
          value: Retain
      - documentIndex: *otherVolumeSnapshotDoc
        equal:
          path: parameters
          value:
            parameter1: value1
            parameter2: "5"

  # Failures
  - it: should fail with invalid deletionPolicy
    set:
      volumeSnapshotClass:
        class1:
          enabled: true
          driver: csi-hostpath-snapshots
          deletionPolicy: Invalid
    asserts:
      - failedTemplate:
          errorMessage: Volume Snapshot Class - Expected [deletionPolicy] to be one of [Retain, Delete], but got [Invalid]

  - it: should fail without driver
    set:
      volumeSnapshotClass:
        class1:
          enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Volume Snapshot Class - Expected non empty [driver]

  - it: should fail with empty enabled
    set:
      volumeSnapshotClass:
        class1:
          enabled:
    asserts:
      - failedTemplate:
          errorMessage: Volume Snapshot Class - Expected the defined key [enabled] in [volumeSnapshotClass.class1] to not be empty
