@@ -40,25 +40,27 @@ func TestRestoreCommandBuilding(t *testing.T) {
4040 Format : customFormat ,
4141 },
4242 },
43- DumpLocation : "/tmp/db.dump" ,
43+ DumpLocation : "/tmp/db.dump" ,
44+ CustomOptions : []string {"--no-privileges" , "--no-owner" , "--exit-on-error" },
4445 },
45- command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges " , "--no-owner " , "--exit-on-error " , "--create " , "--jobs " , "1 " , "/tmp/db.dump " },
46+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--create " , "--jobs " , "1 " , "/tmp/db.dump " , "--no-privileges " , "--no-owner " , "--exit-on-error " },
4647 },
4748 {
4849 copyOptions : RestoreOptions {
4950 ParallelJobs : 4 ,
5051 ForceInit : true ,
5152 },
52- command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--exit-on-error" , "-- create" , "--clean" , "--if-exists" , "--jobs" , "4" , " " },
53+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--create" , "--clean" , "--if-exists" , "--jobs" , "4" },
5354 },
5455 {
5556 copyOptions : RestoreOptions {
56- ParallelJobs : 2 ,
57- ForceInit : false ,
58- Databases : map [string ]DumpDefinition {"testDB" : {}},
59- DumpLocation : "/tmp/db.dump" ,
57+ ParallelJobs : 2 ,
58+ ForceInit : false ,
59+ Databases : map [string ]DumpDefinition {"testDB" : {}},
60+ DumpLocation : "/tmp/db.dump" ,
61+ CustomOptions : []string {"--no-privileges" , "--no-owner" , "--exit-on-error" },
6062 },
61- command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges " , "--no-owner " , "--exit-on-error " , "--create " , "--jobs " , "2 " , "/tmp/db.dump/testDB " },
63+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--create " , "--jobs " , "2 " , "/tmp/db.dump/testDB " , "--no-privileges " , "--no-owner " , "--exit-on-error " },
6264 },
6365 {
6466 copyOptions : RestoreOptions {
@@ -69,9 +71,10 @@ func TestRestoreCommandBuilding(t *testing.T) {
6971 Format : directoryFormat ,
7072 },
7173 },
72- DumpLocation : "/tmp/db.dump" ,
74+ DumpLocation : "/tmp/db.dump" ,
75+ CustomOptions : []string {"--no-privileges" , "--no-owner" , "--exit-on-error" },
7376 },
74- command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--exit-on-error" , "-- create" , "--jobs" , "1" , "--table" , "test" , "--table" , "users" , "/tmp/db.dump/testDB" },
77+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--create" , "--jobs" , "1" , "--table" , "test" , "--table" , "users" , "/tmp/db.dump/testDB" , "--no-privileges" , "--no-owner" , "--exit-on-error " },
7578 },
7679 {
7780 copyOptions : RestoreOptions {
@@ -133,6 +136,11 @@ func TestDumpCommandBuilding(t *testing.T) {
133136 Password : "secret" ,
134137 },
135138 },
139+ globalCfg : & global.Config {
140+ Database : global.Database {
141+ Username : "postgres" ,
142+ },
143+ },
136144 }
137145
138146 testCases := []struct {
@@ -152,8 +160,31 @@ func TestDumpCommandBuilding(t *testing.T) {
152160 },
153161 },
154162 },
163+ CustomOptions : []string {"--exclude-scheme=test-scheme" },
164+ },
165+ command : []string {"pg_dump" , "--create" , "--host" , "localhost" , "--port" , "5432" , "--username" , "john" , "--dbname" , "testDB" , "--jobs" , "1" , "--table" , "test" , "--table" , "users" , "--exclude-table" , "test2" , "--exclude-table" , "users2" , "--exclude-scheme=test-scheme" , "--format" , "directory" , "--file" , "/tmp/db.dump/testDB" },
166+ },
167+ {
168+ copyOptions : DumpOptions {
169+
170+ ParallelJobs : 1 ,
171+ DumpLocation : "/tmp/db.dump" ,
172+ Databases : map [string ]DumpDefinition {
173+ "testDB" : {
174+ Tables : []string {"test" , "users" },
175+ ExcludeTables : []string {
176+ "test2" ,
177+ "users2" ,
178+ },
179+ },
180+ },
181+ Restore : ImmediateRestore {
182+ Enabled : true ,
183+ CustomOptions : []string {"--no-privileges" , "--no-owner" , "--exit-on-error" },
184+ },
185+ CustomOptions : []string {"--exclude-scheme=test-scheme" },
155186 },
156- command : []string {"pg_dump " , "--create " , "-- host" , " localhost" , " --port" , " 5432" , " --username" , " john" , " --dbname" , " testDB" , " --jobs" , "1" , " --table" , " test" , " --table" , " users" , " --exclude-table" , " test2" , " --exclude-table" , " users2" , "-- format" , "directory" , "--file" , "/tmp/db.dump/testDB " },
187+ command : []string {"sh " , "-c " , "pg_dump --create -- host localhost --port 5432 --username john --dbname testDB --jobs 1 --table test --table users --exclude-table test2 --exclude-table users2 --exclude-scheme=test-scheme -- format custom | pg_restore --username postgres --dbname postgres --create --no-privileges --no-owner --exit-on-error " },
157188 },
158189 }
159190
0 commit comments