suite: Jenkins Agent Service
release:
  name: my-release
  namespace: my-namespace
templates:
  - jenkins-agent-svc.yaml
tests:
  - it: default tests
    asserts:
      - isKind:
          of: Service
      - equal:
          path: apiVersion
          value: v1
      - equal:
          path: metadata.name
          value: my-release-jenkins-agent
      - equal:
          path: metadata.namespace
          value: my-namespace
      - matchRegex:
          path: metadata.labels.helm\.sh/chart
          pattern: ^jenkins-
      - isNull:
          path: metadata.annotations
      - equal:
          path: spec
          value:
            ports:
            - name: agent-listener
              port: 50000
              targetPort: 50000
            selector:
              app.kubernetes.io/component: jenkins-controller
              app.kubernetes.io/instance: my-release
            type: ClusterIP
  - it: other values
    set:
      controller:
        agentListenerServiceAnnotations:
          key: value
        agentListenerPort: 55555
    asserts:
      - equal:
          path: metadata.annotations
          value:
            key: value
      - equal:
          path: spec
          value:
            ports:
            - name: agent-listener
              port: 55555
              targetPort: 55555
            selector:
              app.kubernetes.io/component: jenkins-controller
              app.kubernetes.io/instance: my-release
            type: ClusterIP
  - it: node port random
    set:
      controller:
        agentListenerServiceType: NodePort
    asserts:
      - equal:
          path: spec
          value:
            ports:
            - name: agent-listener
              port: 50000
              targetPort: 50000
            selector:
              app.kubernetes.io/component: jenkins-controller
              app.kubernetes.io/instance: my-release
            type: NodePort
  - it: node port defined
    set:
      controller:
        agentListenerServiceType: NodePort
        agentListenerNodePort: 32123
    asserts:
      - equal:
          path: spec
          value:
            ports:
            - name: agent-listener
              port: 50000
              targetPort: 50000
              nodePort: 32123
            selector:
              app.kubernetes.io/component: jenkins-controller
              app.kubernetes.io/instance: my-release
            type: NodePort
  - it: load balancer
    set:
      controller:
        agentListenerServiceType: LoadBalancer
        agentListenerLoadBalancerIP: 10.10.10.10
    asserts:
      - equal:
          path: spec
          value:
            ports:
            - name: agent-listener
              port: 50000
              targetPort: 50000
            selector:
              app.kubernetes.io/component: jenkins-controller
              app.kubernetes.io/instance: my-release
            type: LoadBalancer
            loadBalancerIP: 10.10.10.10
            loadBalancerSourceRanges:
              - 0.0.0.0/0
  - it: disable helm.sh label
    set:
      renderHelmLabels: false
    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: disable agent service
    set:
      controller:
        agentListenerEnabled: false
    asserts:
    - hasDocuments:
        count: 0