suite: pvc data name test
templates:
  - common.yaml
tests:
  - it: should create pvc
    set:
      persistence:
        my-volume1:
          enabled: true
          type: pvc
    asserts:
      - documentIndex: &pvcDoc 0
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        isAPIVersion:
          of: v1
      - documentIndex: *pvcDoc
        equal:
          path: metadata.name
          value: release-name-common-test-my-volume1
      - documentIndex: *pvcDoc
        equal:
          path: spec.accessModes
          value:
            - ReadWriteOnce
      - documentIndex: *pvcDoc
        equal:
          path: spec.resources.requests.storage
          value: 1Gi
      - documentIndex: *pvcDoc
        isNull:
          path: spec.volumeName
      - documentIndex: *pvcDoc
        isNull:
          path: spec.storageClassName

  - it: should not create pvc when existingClaim is set
    set:
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          existingClaim: some-existing-claim
    asserts:
      - hasDocuments:
          of: 0

  - it: should create pvc with accessModes set as string
    set:
      some_mode: ReadWriteMany
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          accessModes: "{{ .Values.some_mode }}"
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.accessModes
          value:
            - ReadWriteMany

  - it: should create pvc with accessModes set as list
    set:
      some_mode: ReadWriteMany
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          accessModes:
            - "{{ .Values.some_mode }}"
            - ReadWriteOnce
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.accessModes
          value:
            - ReadWriteMany
            - ReadWriteOnce

  - it: should create pvc with size set
    set:
      some_size: 20Gi
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          size: "{{ .Values.some_size }}"
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.resources.requests.storage
          value: 20Gi

  - it: should create pvc with volumeName set
    set:
      some_vol_name: some-pv-name
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          volumeName: "{{ .Values.some_vol_name }}"
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.volumeName
          value: some-pv-name

  - it: should create pvc with storageClass set "-"
    set:
      some_storage_class: "-"
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          storageClass: "{{ .Values.some_storage_class }}"
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.storageClassName
          value: ""

  - it: should create pvc with storageClass set
    set:
      some_storage_class: "some-storage-class"
      persistence:
        my-volume1:
          enabled: true
          type: pvc
          storageClass: "{{ .Values.some_storage_class }}"
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.storageClassName
          value: some-storage-class

  - it: should create pvc with storageClass not set, but have fallbackDefaults set
    set:
      fallbackDefaults:
        storageClass: some-storage-class
      persistence:
        my-volume1:
          enabled: true
          type: pvc
    asserts:
      - documentIndex: *pvcDoc
        isKind:
          of: PersistentVolumeClaim
      - documentIndex: *pvcDoc
        equal:
          path: spec.storageClassName
          value: some-storage-class
