suite: Controller Primary Ingress
release:
  name: my-release
  namespace: my-namespace
templates:
  - jenkins-controller-ingress.yaml
capabilities:
  majorVersion: 1
  minorVersion: 19
tests:
  - it: test defaults
    asserts:
    - hasDocuments:
        count: 0
  - it: enabled
    set:
      controller.ingress:
        enabled: true
        hostName: jenkins.example.com
        ingressClassName: nginx
        tls:
          - secretName: tlsSecret
            hosts:
              - jenkins.example.com
    asserts:
      - isKind:
          of: Ingress
      - equal:
          path: apiVersion
          value: networking.k8s.io/v1
      - equal:
          path: metadata.name
          value: my-release-jenkins
      - equal:
          path: metadata.namespace
          value: my-namespace
      - matchRegex:
          path: metadata.labels.helm\.sh/chart
          pattern: ^jenkins-
      - isNull:
          path: metadata.annotations
      - equal:
          path: spec
          value:
            ingressClassName: nginx
            rules:
              - host: jenkins.example.com
                http:
                  paths:
                    - backend:
                        service:
                          name: my-release-jenkins
                          port:
                            number: 8080
                      pathType: ImplementationSpecific
            tls:
            - hosts:
              - jenkins.example.com
              secretName: tlsSecret
  - it: other values
    set:
      controller.ingress:
        enabled: true
        hostName: jenkins.example.com
        ingressClassName: nginx
        annotations:
          kubernetes.io/ingress.class: nginx
          kubernetes.io/tls-acme: "true"
        paths:
          - backend:
              service:
                name: ssl-redirect
                port:
                  number: use-annotation
            pathType: ImplementationSpecific
          - backend:
              service:
                name: >-
                  {{ template "jenkins.fullname" . }}
                port:
                  number: 8080
            pathType: ImplementationSpecific
        tls:
          - secretName: tlsSecret
            hosts:
              - jenkins.example.com
    asserts:
      - equal:
          path: metadata.annotations
          value:
            kubernetes.io/ingress.class: nginx
            kubernetes.io/tls-acme: "true"
      - equal:
          path: spec
          value:
            ingressClassName: nginx
            rules:
              - host: jenkins.example.com
                http:
                  paths:
                    - backend:
                        service:
                          name: ssl-redirect
                          port:
                            number: use-annotation
                      pathType: ImplementationSpecific
                    - backend:
                        service:
                          name: my-release-jenkins
                          port: 
                            number: 8080
                      pathType: ImplementationSpecific
            tls:
            - hosts:
              - jenkins.example.com
              secretName: tlsSecret
  - it: disable helm.sh label
    set:
      renderHelmLabels: false
      controller.ingress:
        enabled: true
        hostName: jenkins.example.com
        ingressClassName: nginx
    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
  - it: empty paths
    set:
      controller.ingress:
        enabled: true
        paths:
    asserts:
    - equal:
        path: spec.rules
        value:
          - http:
              paths:
                - backend:
                    service:
                      name: my-release-jenkins
                      port:
                        number: 8080
                  pathType: ImplementationSpecific
