suite: "Test GitHub Secret Data"
templates:
  - githubsecret.yaml
tests:
  - it: should render PAT token when configured
    set:
      scaleset.name: "test"
      auth.url: "https://github.com/org"
      auth.githubToken: "gh_token12345"
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - exists:
          path: data.github_token
      - equal:
          path: data.github_token
          value: "Z2hfdG9rZW4xMjM0NQ=="
      - notExists:
          path: data.github_app_id
      - notExists:
          path: data.github_app_installation_id
      - notExists:
          path: data.github_app_private_key

  - it: should render GitHub App keys when app is configured
    set:
      scaleset.name: "test"
      auth.url: "https://github.com/org"
      auth.app:
        clientId: "123"
        installationId: "456"
        privateKey: "mykey"
    release:
      name: "test-name"
      namespace: "test-namespace"
    asserts:
      - notExists:
          path: data.github_token
      - equal:
          path: data.github_app_id
          value: "MTIz"
      - equal:
          path: data.github_app_installation_id
          value: "NDU2"
      - equal:
          path: data.github_app_private_key
          value: "bXlrZXk="

  - it: should fail if app is configured without installationId
    set:
      scaleset.name: "test"
      auth.url: "https://github.com/org"
      auth.app:
        clientId: "123"
        privateKey: "mykey"
    asserts:
      - failedTemplate:
          errorMessage: ".Values.auth.app.installationId is required when using GitHub App auth"

  - it: should fail if app is configured without privateKey
    set:
      scaleset.name: "test"
      auth.url: "https://github.com/org"
      auth.app:
        clientId: "123"
        installationId: "456"
    asserts:
      - failedTemplate:
          errorMessage: ".Values.auth.app.privateKey is required when using GitHub App auth"

  - it: should fail if neither PAT token nor GitHub App is configured
    set:
      scaleset.name: "test"
      auth.url: "https://github.com/org"
    asserts:
      - failedTemplate:
          errorMessage: ".Values.auth.githubToken is required when auth.secretName and auth.app.clientId are not set"
