suite: podDisruptionBudget validation test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should fail with name longer than 63 characters
    set:
      podDisruptionBudget:
        my-poddisruptionbudget-super-long-name-that-is-longer-than-63-characters:
          enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Name [test-release-name-common-test-my-poddisruptionbudget-super-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

  - it: should fail with name starting with underscore
    set:
      podDisruptionBudget:
        _my-poddisruptionbudget:
          enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Name [test-release-name-common-test-_my-poddisruptionbudget] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

  - it: should fail with namespace longer than 63 characters
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          minAvailable: 1
          targetSelector: my-pod
          namespace: my-extra-super-duper-long-name-that-is-longer-than-63-characters
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Namespace [my-extra-super-duper-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

  - it: should fail with labels not a dict
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          labels: "not a dict"
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected [labels] to be a dictionary, but got [string]

  - it: should fail with annotations not a dict
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          annotations: "not a dict"
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected [annotations] to be a dictionary, but got [string]

  - it: should fail with not valid unhealthyPodEvictionPolicy
    set:
      configmap:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          unhealthyPodEvictionPolicy: "not valid"
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected [unhealthyPodEvictionPolicy] to be one of [IfHealthyBudget, AlwaysAllow], but got [not valid]

  - it: should fail with empty minAvailable
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          minAvailable:
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected the defined key [minAvailable] in [podDisruptionBudget.my-poddisruptionbudget] to not be empty

  - it: should fail with empty maxUnavailable
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          maxUnavailable:
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected the defined key [maxUnavailable] in [podDisruptionBudget.my-poddisruptionbudget] to not be empty

  - it: should fail without at least one key defined
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected at least one of [minAvailable, maxUnavailable] to be defined in [podDisruptionBudget.my-poddisruptionbudget]

  - it: should fail with empty enabled
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled:
          targetSelector: my-pod
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected the defined key [enabled] in [podDisruptionBudget.my-poddisruptionbudget] to not be empty

  - it: should fail with pod targetSelector not a string
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector:
            pod: "not a string"
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected [targetSelector] to be [string], but got [map]

  - it: should fail without either targetSelector or customLabels
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected one of [targetSelector, customLabels] to be defined in [podDisruptionBudget.my-poddisruptionbudget]

  - it: should fail with both targetSelector and customLabels
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          customLabels:
            label1: label1
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected only one of [targetSelector, customLabels] to be defined in [podDisruptionBudget.my-poddisruptionbudget]

  - it: should fail with selected pod that does not exist
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          minAvailable: 1
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Selected pod [my-pod] is not defined

  - it: should fail with both minAvailable and maxUnavailable
    set:
      podDisruptionBudget:
        my-poddisruptionbudget:
          enabled: true
          targetSelector: my-pod
          minAvailable: 1
          maxUnavailable: 1
    asserts:
      - failedTemplate:
          errorMessage: Pod Disruption Budget - Expected one of [minAvailable, maxUnavailable] to be defined in [podDisruptionBudget.my-poddisruptionbudget], but got both
