suite: "Controller RBAC leader election"
templates:
  - leader_election_role.yaml
  - leader_election_role_binding.yaml
tests:
  - it: should not render leader election resources when replicaCount is 1
    set:
      controller:
        replicaCount: 1
    release:
      name: "test-arc"
      namespace: "test-ns"
    asserts:
      - hasDocuments:
          count: 0
        template: leader_election_role.yaml
      - hasDocuments:
          count: 0
        template: leader_election_role_binding.yaml

  - it: should render leader election resources when replicaCount > 1
    set:
      controller:
        replicaCount: 2
    release:
      name: "test-arc"
      namespace: "test-ns"
    asserts:
      - equal:
          path: kind
          value: "Role"
        template: leader_election_role.yaml
      - equal:
          path: metadata.name
          value: "test-arc-gha-rs-controller-leader-election"
        template: leader_election_role.yaml
      - equal:
          path: metadata.namespace
          value: "test-ns"
        template: leader_election_role.yaml
      - equal:
          path: kind
          value: "RoleBinding"
        template: leader_election_role_binding.yaml
      - equal:
          path: roleRef.name
          value: "test-arc-gha-rs-controller-leader-election"
        template: leader_election_role_binding.yaml
      - equal:
          path: subjects[0].name
          value: "test-arc-gha-rs-controller"
        template: leader_election_role_binding.yaml
