suite: Controller Prometheus PrometheusRule
release:
  name: my-release
  namespace: my-namespace
templates:
  - jenkins-controller-alerting-rules.yaml
tests:
  - it: defaults
    asserts:
    - hasDocuments:
        count: 0
  - it: enabled
    set:
      controller.prometheus:
        enabled: true
        alertingrules:
          - name: ./jenkins.rules
            rules:
              - alert: JenkinsFailedPlugins
                expr: jenkins_plugins_failed > 0
                for: 10m
                labels:
                  severity: warning
                annotations:
                  message: Some Jenkins plugins failed to load
    asserts:
      - isKind:
          of: PrometheusRule
      - equal:
          path: apiVersion
          value: monitoring.coreos.com/v1
      - equal:
          path: metadata.name
          value: my-release-jenkins
      - matchRegex:
          path: metadata.labels.helm\.sh/chart
          pattern: ^jenkins-
      - equal:
          path: metadata.namespace
          value: my-namespace
      - matchRegex:
          path: metadata.labels.helm\.sh/chart
          pattern: ^jenkins-
      - equal:
          path: spec
          value:
            groups:
            - name: ./jenkins.rules
              rules:
                - alert: JenkinsFailedPlugins
                  expr: jenkins_plugins_failed > 0
                  for: 10m
                  labels:
                    severity: warning
                  annotations:
                    message: Some Jenkins plugins failed to load
  - it: disable helm.sh label
    set:
      renderHelmLabels: false
      controller.prometheus:
        enabled: true
        alertingrules:
          - name: ./jenkins.rules
            rules:
              - alert: JenkinsFailedPlugins
                expr: jenkins_plugins_failed > 0
                for: 10m
                labels:
                  severity: warning
                annotations:
                  message: Some Jenkins plugins failed to load
    asserts:
      - equal:
          path: metadata.labels
          value:
            app.kubernetes.io/component: jenkins-controller
            app.kubernetes.io/instance: my-release
            app.kubernetes.io/managed-by: Helm
            app.kubernetes.io/name: jenkins