suite: secret tests
templates:
  - templates/secret.yaml
tests:
  - it: should create app secrets when values are provided (SQLite mode)
    set:
      secrets.secretKey: my-secret-key
      secrets.fuellhornSecret: my-fuellhorn-secret
      database.type: sqlite
    asserts:
      - hasDocuments:
          count: 1
      - isKind:
          of: Secret
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-secrets
      - equal:
          path: data.secret-key
          value: bXktc2VjcmV0LWtleQ==
      - equal:
          path: data.fuellhorn-secret
          value: bXktZnVlbGxob3JuLXNlY3JldA==

  - it: should not create app secrets when existingSecret is set (SQLite mode)
    set:
      secrets.existingSecret: my-existing-secret
      database.type: sqlite
    asserts:
      - hasDocuments:
          count: 0

  - it: should create both app and DB secrets for PostgreSQL
    set:
      secrets.secretKey: test-key
      secrets.fuellhornSecret: test-secret
      database.type: postgresql
      database.external.host: postgres.example.com
      database.external.port: 5432
      database.external.database: fuellhorn
      database.external.username: fuellhorn
      database.external.password: dbpassword
    asserts:
      - hasDocuments:
          count: 2
      - isKind:
          of: Secret
        documentIndex: 0
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-secrets
        documentIndex: 0
      - isKind:
          of: Secret
        documentIndex: 1
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-db
        documentIndex: 1

  - it: should not create DB secret when existingSecret is set
    set:
      secrets.secretKey: test-key
      secrets.fuellhornSecret: test-secret
      database.type: postgresql
      database.external.existingSecret: my-db-secret
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-secrets

  - it: should not create DB secret for SQLite
    set:
      secrets.secretKey: test-key
      secrets.fuellhornSecret: test-secret
      database.type: sqlite
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-secrets

  - it: should only create DB secret when app secrets use existingSecret
    set:
      secrets.existingSecret: my-app-secrets
      database.type: postgresql
      database.external.host: postgres.example.com
      database.external.password: dbpassword
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: metadata.name
          value: RELEASE-NAME-fuellhorn-db
