suite: ServiceAccount configuration
templates:
  - serviceaccount.yaml
release:
  namespace: default
tests:
  - it: should provide a single service account by default
    asserts:
      - isKind:
            of: ServiceAccount
      - hasDocuments:
          count: 1
      - equal:
          path: automountServiceAccountToken
          value: true

  - it: should provide a way to disable service account
    set:
      serviceAccount:
        create: false
    asserts:
      - hasDocuments:
          count: 0

  - it: should support annotations without template variables
    set:
      serviceAccount:
        annotations:
          eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/external-dns-role
          eks.amazonaws.com/sts-regional-endpoints: "true"
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: metadata.annotations
          value:
            eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/external-dns-role
            eks.amazonaws.com/sts-regional-endpoints: "true"

  - it: should support annotations with template variables
    release:
      name: v1
    set:
      account: 9876-dynamic-account-id
      serviceAccount:
        annotations:
          eks.amazonaws.com/role-arn: arn:aws:iam::{{ .Values.account }}:role/external-dns-role
          eks.amazonaws.com/sts-regional-endpoints: "true"
          tags.k8s.io/service: service-{{ include "external-dns.fullname" . }}
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: metadata.annotations
          value:
            eks.amazonaws.com/role-arn: arn:aws:iam::9876-dynamic-account-id:role/external-dns-role
            eks.amazonaws.com/sts-regional-endpoints: "true"
            tags.k8s.io/service: service-v1-external-dns
      - isType:
          path: metadata.annotations["eks.amazonaws.com/sts-regional-endpoints"]
          type: string
