suite: "Controller ServiceAccount"
templates:
  - serviceaccount.yaml
tests:
  - it: should render serviceaccount by default
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - equal:
          path: apiVersion
          value: "v1"
      - equal:
          path: kind
          value: "ServiceAccount"
      - equal:
          path: metadata.name
          value: "test-name-gha-rs-controller"
      - equal:
          path: metadata.namespace
          value: "test-namespace"
      - equal:
          path: metadata.labels["actions.github.com/controller-service-account-name"]
          value: "test-name-gha-rs-controller"
      - equal:
          path: metadata.labels["actions.github.com/controller-service-account-namespace"]
          value: "test-namespace"

  - it: should allow overriding serviceAccount.name when create is true
    set:
      controller:
        serviceAccount:
          create: true
          name: "overwritten-name"
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - equal:
          path: metadata.name
          value: "overwritten-name"
      - equal:
          path: metadata.labels["actions.github.com/controller-service-account-name"]
          value: "overwritten-name"

  - it: should render serviceAccount annotations
    set:
      controller:
        serviceAccount:
          create: true
          annotations:
            foo: bar
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - equal:
          path: metadata.annotations.foo
          value: "bar"

  - it: should not render when serviceAccount.create is false
    set:
      controller:
        serviceAccount:
          create: false
          name: "existing-sa"
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - hasDocuments:
          count: 0
