LogicalBackupCliInstructions.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. buildDirectPostgresConnectionUri,
  4. buildLogicalBackupShellScript,
  5. DB_PASSWORD_PLACEHOLDER,
  6. } from '../../components/layouts/ProjectLayout/LogicalBackupCliInstructions.utils'
  7. describe('buildDirectPostgresConnectionUri', () => {
  8. it('builds a valid postgresql URI from settings', () => {
  9. const uri = buildDirectPostgresConnectionUri({
  10. db_user: 'postgres',
  11. db_host: 'db.abcdef.supabase.co',
  12. db_port: 5432,
  13. db_name: 'postgres',
  14. })
  15. expect(uri).toBe(
  16. `postgresql://postgres:${DB_PASSWORD_PLACEHOLDER}@db.abcdef.supabase.co:5432/postgres`
  17. )
  18. })
  19. it('uses the password placeholder, never a real password', () => {
  20. const uri = buildDirectPostgresConnectionUri({
  21. db_user: 'postgres',
  22. db_host: 'db.abcdef.supabase.co',
  23. db_port: 5432,
  24. db_name: 'postgres',
  25. })
  26. expect(uri).toContain(DB_PASSWORD_PLACEHOLDER)
  27. expect(uri).not.toContain('secret')
  28. })
  29. it('includes a non-default port', () => {
  30. const uri = buildDirectPostgresConnectionUri({
  31. db_user: 'postgres',
  32. db_host: 'db.abcdef.supabase.co',
  33. db_port: 6543,
  34. db_name: 'postgres',
  35. })
  36. expect(uri).toContain(':6543/')
  37. })
  38. })
  39. describe('buildLogicalBackupShellScript', () => {
  40. const testUri = `postgresql://postgres:${DB_PASSWORD_PLACEHOLDER}@db.abcdef.supabase.co:5432/postgres`
  41. it('produces exactly three commands', () => {
  42. const script = buildLogicalBackupShellScript(testUri)
  43. expect(script.split('\n')).toHaveLength(3)
  44. })
  45. it('wraps the connection URI in single quotes to prevent shell expansion', () => {
  46. const script = buildLogicalBackupShellScript(testUri)
  47. for (const line of script.split('\n')) {
  48. expect(line).toContain(`'${testUri}'`)
  49. }
  50. })
  51. it('dumps roles, schema, and data in that order', () => {
  52. const [roles, schema, data] = buildLogicalBackupShellScript(testUri).split('\n')
  53. expect(roles).toContain('--role-only')
  54. expect(roles).toContain('-f roles.sql')
  55. expect(schema).toContain('-f schema.sql')
  56. expect(data).toContain('--data-only')
  57. expect(data).toContain('-f data.sql')
  58. })
  59. it('excludes storage vector tables from the data dump', () => {
  60. const [, , data] = buildLogicalBackupShellScript(testUri).split('\n')
  61. expect(data).toContain('-x "storage.buckets_vectors"')
  62. expect(data).toContain('-x "storage.vector_indexes"')
  63. })
  64. it('does not include npx briven login', () => {
  65. const script = buildLogicalBackupShellScript(testUri)
  66. expect(script).not.toContain('briven login')
  67. })
  68. })