suite: podDisruptionBudget data test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should pass with zero in keys (minAvailable)
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          minAvailable: 0
    asserts:
      - documentIndex: &pdbDoc 0
        isKind:
          of: PodDisruptionBudget
      - documentIndex: *pdbDoc
        isSubset:
          path: spec
          content:
            minAvailable: 0

  - it: should pass with zero in keys (maxUnavailable)
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          maxUnavailable: 0
    asserts:
      - documentIndex: &pdbDoc 0
        isKind:
          of: PodDisruptionBudget
      - documentIndex: *pdbDoc
        isSubset:
          path: spec
          content:
            maxUnavailable: 0

  - it: should pass keys from tpl (minAvailable)
    set:
      k1: 0
      k3: AlwaysAllow
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          minAvailable: "{{ .Values.k1 }}"
          unhealthyPodEvictionPolicy: "{{ .Values.k3 }}"
    asserts:
      - documentIndex: *pdbDoc
        isSubset:
          path: spec
          content:
            minAvailable: 0
            unhealthyPodEvictionPolicy: AlwaysAllow

  - it: should pass keys from tpl (maxUnavailable)
    set:
      k2: 0
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          maxUnavailable: "{{ .Values.k2 }}"
    asserts:
      - documentIndex: *pdbDoc
        isSubset:
          path: spec
          content:
            maxUnavailable: 0

  - it: should pass with percentage in keys
    set:
      percentage: 50%
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          maxUnavailable: "{{ .Values.percentage }}"
    asserts:
      - documentIndex: *pdbDoc
        isSubset:
          path: spec
          content:
            maxUnavailable: 50%

  - it: should pass with minAvailable defined
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          minAvailable: 1
    asserts:
      - documentIndex: *pdbDoc
        equal:
          path: spec.minAvailable
          value: 1

  - it: should pass with maxUnavailable defined
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          maxUnavailable: 2
    asserts:
      - documentIndex: *pdbDoc
        equal:
          path: spec.maxUnavailable
          value: 2

  - it: should pass with unhealthyPodEvictionPolicy defined
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          customLabels:
            label1: value1
          minAvailable: 1
          unhealthyPodEvictionPolicy: IfHealthyBudget
    asserts:
      - documentIndex: *pdbDoc
        equal:
          path: spec.unhealthyPodEvictionPolicy
          value: IfHealthyBudget

  - it: should create custom labels for selector
    set:
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          minAvailable: 1
          customLabels:
            label1: value1
            label2: value2
    asserts:
      - documentIndex: *pdbDoc
        equal:
          path: spec.selector.matchLabels
          value:
            label1: value1
            label2: value2
  - it: should create labels for the selector pod
    set:
      workload:
        my-pod:
          enabled: true
          primary: true
          type: Deployment
          podSpec: {}
      podDisruptionBudget:
        my-pdb1:
          enabled: true
          minAvailable: 1
          targetSelector: my-pod
    asserts:
      - documentIndex: &pdbDoc 1
        isKind:
          of: PodDisruptionBudget
      - documentIndex: *pdbDoc
        equal:
          path: spec.selector.matchLabels
          value:
            pod.name: my-pod
            app.kubernetes.io/name: common-test
            app.kubernetes.io/instance: test-release-name
