suite: service loadBalancer (metallb integration) test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should pass with type LoadBalancer and metallb integration enabled
    set:
      service:
        my-service:
          enabled: true
          primary: true
          type: LoadBalancer
          loadBalancerIPs:
            - 1.2.3.4
            - 5.6.7.8
          integrations:
            metallb:
              enabled: true
          ports:
            port-name:
              enabled: true
              primary: true
              port: 12345
      workload:
        my-workload:
          enabled: true
          primary: true
          type: Deployment
          podSpec: {}
    asserts:
      - documentIndex: &serviceDoc 1
        isKind:
          of: Service
      - documentIndex: *serviceDoc
        isAPIVersion:
          of: v1
      - documentIndex: *serviceDoc
        equal:
          path: metadata.name
          value: test-release-name-common-test
      - documentIndex: *serviceDoc
        equal:
          path: spec
          value:
            type: LoadBalancer
            allocateLoadBalancerNodePorts: false
            publishNotReadyAddresses: false
            ports:
              - name: port-name
                port: 12345
                protocol: TCP
                targetPort: 12345
            selector:
              app.kubernetes.io/instance: test-release-name
              app.kubernetes.io/name: common-test
              pod.name: my-workload
      - documentIndex: *serviceDoc
        isSubset:
          path: metadata.annotations
          content:
            metallb.io/loadBalancerIPs: "1.2.3.4,5.6.7.8"

  - it: should pass with type LoadBalancer and metallb integration enabled and sharedKey set
    set:
      service:
        my-service:
          enabled: true
          primary: true
          type: LoadBalancer
          loadBalancerIPs:
            - 1.2.3.4
            - 5.6.7.8
          integrations:
            metallb:
              enabled: true
              sharedKey: some-key
          ports:
            port-name:
              enabled: true
              primary: true
              port: 12345
      workload:
        my-workload:
          enabled: true
          primary: true
          type: Deployment
          podSpec: {}
    asserts:
      - documentIndex: &serviceDoc 1
        isKind:
          of: Service
      - documentIndex: *serviceDoc
        isAPIVersion:
          of: v1
      - documentIndex: *serviceDoc
        equal:
          path: metadata.name
          value: test-release-name-common-test
      - documentIndex: *serviceDoc
        equal:
          path: spec
          value:
            type: LoadBalancer
            allocateLoadBalancerNodePorts: false
            publishNotReadyAddresses: false
            ports:
              - name: port-name
                port: 12345
                protocol: TCP
                targetPort: 12345
            selector:
              app.kubernetes.io/instance: test-release-name
              app.kubernetes.io/name: common-test
              pod.name: my-workload
      - documentIndex: *serviceDoc
        isSubset:
          path: metadata.annotations
          content:
            metallb.io/loadBalancerIPs: "1.2.3.4,5.6.7.8"
            metallb.io/allow-shared-ip: "some-key"

  - it: should fail with both sharedKey set and externalTrafficPolicy set to Local
    set:
      service:
        my-service:
          enabled: true
          primary: true
          type: LoadBalancer
          loadBalancerIPs:
            - 1.2.3.4
            - 5.6.7.8
          externalTrafficPolicy: Local
          integrations:
            metallb:
              enabled: true
              sharedKey: some-key
          ports:
            port-name:
              enabled: true
              primary: true
              port: 12345
      workload:
        my-workload:
          enabled: true
          primary: true
          type: Deployment
          podSpec: {}
    asserts:
      - failedTemplate:
          errorMessage: Service - [sharedKey], cannot both be used together with [externalTrafficPolicy] set to [Local]
