@@ -28,11 +28,12 @@ func TestRestoreCommandBuilding(t *testing.T) {
28
28
}
29
29
30
30
testCases := []struct {
31
- CopyOptions RestoreOptions
32
- Command []string
31
+ copyOptions RestoreOptions
32
+ command []string
33
+ isDumpLocationDir bool
33
34
}{
34
35
{
35
- CopyOptions : RestoreOptions {
36
+ copyOptions : RestoreOptions {
36
37
ParallelJobs : 1 ,
37
38
ForceInit : false ,
38
39
Databases : map [string ]DumpDefinition {
@@ -42,26 +43,26 @@ func TestRestoreCommandBuilding(t *testing.T) {
42
43
},
43
44
DumpLocation : "/tmp/db.dump" ,
44
45
},
45
- Command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "1" , "/tmp/db.dump" },
46
+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "1" , "/tmp/db.dump" },
46
47
},
47
48
{
48
- CopyOptions : RestoreOptions {
49
+ copyOptions : RestoreOptions {
49
50
ParallelJobs : 4 ,
50
51
ForceInit : true ,
51
52
},
52
- Command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--clean" , "--if-exists" , "--jobs" , "4" , "" },
53
+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--clean" , "--if-exists" , "--jobs" , "4" , "" },
53
54
},
54
55
{
55
- CopyOptions : RestoreOptions {
56
+ copyOptions : RestoreOptions {
56
57
ParallelJobs : 2 ,
57
58
ForceInit : false ,
58
59
Databases : map [string ]DumpDefinition {"testDB" : {}},
59
60
DumpLocation : "/tmp/db.dump" ,
60
61
},
61
- Command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "2" , "/tmp/db.dump/testDB" },
62
+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "2" , "/tmp/db.dump/testDB" },
62
63
},
63
64
{
64
- CopyOptions : RestoreOptions {
65
+ copyOptions : RestoreOptions {
65
66
ParallelJobs : 1 ,
66
67
Databases : map [string ]DumpDefinition {
67
68
"testDB" : {
@@ -71,10 +72,10 @@ func TestRestoreCommandBuilding(t *testing.T) {
71
72
},
72
73
DumpLocation : "/tmp/db.dump" ,
73
74
},
74
- Command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "1" , "--table" , "test" , "--table" , "users" , "/tmp/db.dump/testDB" },
75
+ command : []string {"pg_restore" , "--username" , "john" , "--dbname" , "postgres" , "--no-privileges" , "--no-owner" , "--create" , "--jobs" , "1" , "--table" , "test" , "--table" , "users" , "/tmp/db.dump/testDB" },
75
76
},
76
77
{
77
- CopyOptions : RestoreOptions {
78
+ copyOptions : RestoreOptions {
78
79
Databases : map [string ]DumpDefinition {
79
80
"testDB.dump" : {
80
81
Format : plainFormat ,
@@ -83,26 +84,41 @@ func TestRestoreCommandBuilding(t *testing.T) {
83
84
},
84
85
DumpLocation : "/tmp/db.dump" ,
85
86
},
86
- Command : []string {"sh" , "-c" , "cat /tmp/db.dump/testDB.dump | psql --username john --dbname postgres" },
87
+ isDumpLocationDir : true ,
88
+ command : []string {"sh" , "-c" , "cat /tmp/db.dump/testDB.dump | psql --username john --dbname postgres" },
87
89
},
88
90
{
89
- CopyOptions : RestoreOptions {
91
+ copyOptions : RestoreOptions {
90
92
Databases : map [string ]DumpDefinition {
91
93
"testDB.dump" : {
92
94
Format : plainFormat ,
93
95
},
94
96
},
95
97
DumpLocation : "/tmp/db.dump" ,
96
98
},
97
- Command : []string {"sh" , "-c" , "cat /tmp/db.dump/testDB.dump | psql --username john --dbname testDB" },
99
+ isDumpLocationDir : true ,
100
+ command : []string {"sh" , "-c" , "cat /tmp/db.dump/testDB.dump | psql --username john --dbname testDB" },
101
+ },
102
+ {
103
+ copyOptions : RestoreOptions {
104
+ Databases : map [string ]DumpDefinition {
105
+ "testDB.dump" : {
106
+ Format : plainFormat ,
107
+ },
108
+ },
109
+ DumpLocation : "/tmp/db.dump" ,
110
+ },
111
+ isDumpLocationDir : false ,
112
+ command : []string {"sh" , "-c" , "cat /tmp/db.dump | psql --username john --dbname testDB" },
98
113
},
99
114
}
100
115
101
116
for _ , tc := range testCases {
102
- logicalJob .RestoreOptions = tc .CopyOptions
103
- for dbName , definition := range tc .CopyOptions .Databases {
117
+ logicalJob .RestoreOptions = tc .copyOptions
118
+ logicalJob .isDumpLocationDir = tc .isDumpLocationDir
119
+ for dbName , definition := range tc .copyOptions .Databases {
104
120
restoreCommand := logicalJob .buildLogicalRestoreCommand (dbName , definition )
105
- assert .Equal (t , restoreCommand , tc .Command )
121
+ assert .Equal (t , restoreCommand , tc .command )
106
122
}
107
123
}
108
124
}
@@ -163,20 +179,23 @@ func TestDiscoverDumpDirectories(t *testing.T) {
163
179
}
164
180
165
181
func TestDumpLocation (t * testing.T ) {
166
- r := & RestoreJob {}
167
- r .RestoreOptions .DumpLocation = "/tmp/dblab_test"
168
-
169
182
testCases := []struct {
170
- format string
171
- dbname string
172
- expectedLocation string
183
+ format string
184
+ isDumpLocationDir bool
185
+ dbname string
186
+ expectedLocation string
173
187
}{
174
- {format : directoryFormat , dbname : "postgres" , expectedLocation : "/tmp/dblab_test/postgres" },
175
- {format : customFormat , dbname : "postgres" , expectedLocation : "/tmp/dblab_test" },
176
- {format : plainFormat , dbname : "postgres" , expectedLocation : "/tmp/dblab_test/postgres" },
188
+ {format : directoryFormat , dbname : "postgresDir" , expectedLocation : "/tmp/dblab_test/postgresDir" },
189
+ {format : customFormat , dbname : "postgresCustom" , isDumpLocationDir : true , expectedLocation : "/tmp/dblab_test/postgresCustom" },
190
+ {format : customFormat , dbname : "postgresCustom" , expectedLocation : "/tmp/dblab_test" },
191
+ {format : plainFormat , dbname : "postgresPlain" , isDumpLocationDir : true , expectedLocation : "/tmp/dblab_test/postgresPlain" },
192
+ {format : plainFormat , dbname : "postgresPlain" , expectedLocation : "/tmp/dblab_test" },
177
193
}
178
194
179
195
for _ , tc := range testCases {
196
+ r := & RestoreJob {}
197
+ r .RestoreOptions .DumpLocation = "/tmp/dblab_test"
198
+ r .isDumpLocationDir = tc .isDumpLocationDir
180
199
dumpLocation := r .getDumpLocation (tc .format , tc .dbname )
181
200
assert .Equal (t , tc .expectedLocation , dumpLocation )
182
201
}
0 commit comments