@@ -13,6 +13,8 @@ BeforeAll {
1313 ' scripts/pwsh/devops/postgresql/core/formats.ps1'
1414 ' scripts/pwsh/devops/postgresql/core/validation.ps1'
1515 ' scripts/pwsh/devops/postgresql/commands/help.ps1'
16+ ' scripts/pwsh/devops/postgresql/commands/backup.ps1'
17+ ' scripts/pwsh/devops/postgresql/commands/restore.ps1'
1618 ' scripts/pwsh/devops/postgresql/main.ps1'
1719 )) {
1820 . (Join-Path $script :RepoRoot $relativePath )
@@ -39,3 +41,64 @@ Describe 'Invoke-PostgresToolkitCommand' {
3941 $result.Output | Should -Match ' Usage'
4042 }
4143}
44+
45+ Describe ' New-PgBackupCommandSpec' {
46+ It ' 默认生成 custom 格式 pg_dump 命令' {
47+ $spec = New-PgBackupCommandSpec - CliOptions @ {
48+ database = ' app'
49+ output = ' ./app.dump'
50+ } - Context ([PSCustomObject ]@ {
51+ Host = ' 127.0.0.1'
52+ Port = 5432
53+ User = ' postgres'
54+ Password = ' secret'
55+ Database = ' app'
56+ })
57+
58+ $spec.FilePath | Should - Be ' pg_dump'
59+ ($spec.ArgumentList -join ' ' ) | Should -Match ' -Fc'
60+ ($spec.ArgumentList -join ' ' ) | Should -Match ' app.dump'
61+ }
62+ }
63+
64+ Describe ' New-PgRestoreCommandSpec' {
65+ It ' sql 文件切换到 psql 恢复路径' {
66+ $inputPath = Join-Path $TestDrive ' sample.sql'
67+ Set-Content - Path $inputPath - Value ' -- sql'
68+
69+ $spec = New-PgRestoreCommandSpec - CliOptions @ {
70+ input = $inputPath
71+ target_database = ' restore_db'
72+ } - Context ([PSCustomObject ]@ {
73+ Host = ' 127.0.0.1'
74+ Port = 5432
75+ User = ' postgres'
76+ Password = ' secret'
77+ Database = ' postgres'
78+ })
79+
80+ $spec.FilePath | Should - Be ' psql'
81+ ($spec.ArgumentList -join ' ' ) | Should -Match ' restore_db'
82+ ($spec.ArgumentList -join ' ' ) | Should -Match ' -f'
83+ }
84+
85+ It ' archive 文件走 pg_restore 并支持 --clean' {
86+ $inputPath = Join-Path $TestDrive ' sample.dump'
87+ Set-Content - Path $inputPath - Value ' archive'
88+
89+ $spec = New-PgRestoreCommandSpec - CliOptions @ {
90+ input = $inputPath
91+ target_database = ' restore_db'
92+ clean = $true
93+ } - Context ([PSCustomObject ]@ {
94+ Host = ' 127.0.0.1'
95+ Port = 5432
96+ User = ' postgres'
97+ Password = ' secret'
98+ Database = ' postgres'
99+ })
100+
101+ $spec.FilePath | Should - Be ' pg_restore'
102+ $spec.ArgumentList | Should - Contain ' --clean'
103+ }
104+ }
0 commit comments