suite: "Controller serviceAccount.create toggle"
templates:
  - serviceaccount.yaml
  - deployment.yaml
tests:
  - it: should create ServiceAccount and use it in Deployment when create is true
    set:
      controller:
        manager:
          container:
            image: "ghcr.io/actions/gha-runner-scale-set-controller:latest"
        serviceAccount:
          create: true
          name: ""
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - hasDocuments:
          count: 1
        template: serviceaccount.yaml
      - equal:
          path: spec.template.spec.serviceAccountName
          value: "test-name-gha-rs-controller"
        template: deployment.yaml

  - it: should not create ServiceAccount and use provided name in Deployment when create is false
    set:
      controller:
        manager:
          container:
            image: "ghcr.io/actions/gha-runner-scale-set-controller:latest"
        serviceAccount:
          create: false
          name: "existing-sa"
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - hasDocuments:
          count: 0
        template: serviceaccount.yaml
      - equal:
          path: spec.template.spec.serviceAccountName
          value: "existing-sa"
        template: deployment.yaml
