Skip to content

Commit 5e026e3

Browse files
committed
refactor(test): enhance safe command replacements for export syntax verification
- Replace dump commands (pg_dump, mysqldump, tar cf -) with echo 'dummy data' to simulate output - Replace compression tools (zstd, gzip) with cat to consume input without actual compression - Improves test reliability and coverage for various database export scenarios
1 parent dda5829 commit 5e026e3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

backend/db/commands_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ func TestBuildExportCommand_Syntax(t *testing.T) {
2626
// The command is roughly: bash -c 'set -o pipefail; PGPASSWORD='pass'word' ...'
2727
// This is definitely broken if not escaped.
2828

29-
// Try to execute it with "echo" replaced for pg_dump/zstd to verify syntax
30-
// We replace the actual heavy commands with "true" or "echo"
31-
safeCmd := strings.ReplaceAll(cmd, "pg_dump", "echo pg_dump")
32-
safeCmd = strings.ReplaceAll(safeCmd, "zstd", "echo zstd")
33-
safeCmd = strings.ReplaceAll(safeCmd, "gzip", "echo gzip")
29+
// Try to execute it with safe replacements to verify syntax
30+
// Replace dump commands with echo to produce output, compression with cat to consume input
31+
safeCmd := strings.ReplaceAll(cmd, "pg_dump", "echo 'dummy data'")
32+
safeCmd = strings.ReplaceAll(safeCmd, "mysqldump", "echo 'dummy data'")
33+
safeCmd = strings.ReplaceAll(safeCmd, "tar cf -", "echo 'dummy data'")
34+
safeCmd = strings.ReplaceAll(safeCmd, "zstd", "cat")
35+
safeCmd = strings.ReplaceAll(safeCmd, "gzip", "cat")
3436

3537
// We wrap it in bash -c because that's how SSH executes it (roughly sh -c)
3638
// exec.Command("bash", "-c", safeCmd)

0 commit comments

Comments
 (0)