@@ -26,6 +26,7 @@ import (
2626const pgPort = "5432/tcp"
2727const backupPath = "/tmp/postgres.dump.tar"
2828const backupPathPlain = "/tmp/postgres.dump"
29+ const backupPathDir = "/tmp/postgres-dir"
2930const backupPathZip = "/tmp/postgres.dump.tar.gz"
3031const backupPathPlainZip = "/tmp/postgres.dump.gz"
3132const postgresPW = "postgresroot"
@@ -122,6 +123,71 @@ func (pgDumpAndRestoreTestSuite *PGDumpAndRestoreTestSuite) TestBasicPGDumpAndRe
122123 assert .DeepEqual (pgDumpAndRestoreTestSuite .T (), testDataPlain , restoreResultPlain )
123124}
124125
126+ // TestBasicPGDumpAndRestoreDirectory führt einen Integrationstest mit Directory-Format (-F d) durch, ohne Restic
127+ func (pgDumpAndRestoreTestSuite * PGDumpAndRestoreTestSuite ) TestBasicPGDumpAndRestoreDirectory () {
128+ ctx := context .Background ()
129+
130+ // Verzeichnis nach dem Test aufräumen
131+ defer func () {
132+ removeErr := os .RemoveAll (backupPathDir )
133+ if removeErr != nil {
134+ log .WithError (removeErr ).Error ("failed to remove pgdump directory backup" )
135+ }
136+ }()
137+
138+ log .Info ("Testing postgres restoration with directory dump via pg_restore" )
139+ // Backup mit Directory-Format erstellen
140+ testData , err := pgDoBackup (
141+ ctx , false , commons.TestContainerSetup {
142+ Port : "" ,
143+ Address : "" ,
144+ },
145+ "d" , backupPathDir ,
146+ )
147+ pgDumpAndRestoreTestSuite .Require ().NoError (err )
148+
149+ // In neuen Container restoren und Daten verifizieren
150+ restoreResult , err := pgDoRestore (
151+ ctx , false , commons.TestContainerSetup {
152+ Port : "" ,
153+ Address : "" ,
154+ },
155+ "d" , backupPathDir ,
156+ )
157+ pgDumpAndRestoreTestSuite .Require ().NoError (err )
158+
159+ assert .DeepEqual (pgDumpAndRestoreTestSuite .T (), testData , restoreResult )
160+ }
161+
162+ // TestPGDumpAndRestoreDirectoryRestic testet Directory-Format (-F d) mit Restic
163+ func (pgDumpAndRestoreTestSuite * PGDumpAndRestoreTestSuite ) TestPGDumpAndRestoreDirectoryRestic () {
164+ ctx := context .Background ()
165+
166+ defer func () {
167+ removeErr := os .RemoveAll (backupPathDir )
168+ if removeErr != nil {
169+ log .WithError (removeErr ).Error ("failed to remove pgdump directory backup (restic)" )
170+ }
171+ }()
172+
173+ resticContainer , err := commons .NewTestContainerSetup (ctx , & commons .ResticReq , commons .ResticPort )
174+ pgDumpAndRestoreTestSuite .Require ().NoError (err )
175+ defer func () {
176+ resticErr := resticContainer .Container .Terminate (ctx )
177+ if resticErr != nil {
178+ log .WithError (resticErr ).Error ("failed to terminate directory restic container" )
179+ }
180+ }()
181+
182+ testData , err := pgDoBackup (ctx , true , resticContainer , "d" , backupPathDir )
183+ pgDumpAndRestoreTestSuite .Require ().NoError (err )
184+
185+ restoreResult , err := pgDoRestore (ctx , true , resticContainer , "d" , backupPathDir )
186+ pgDumpAndRestoreTestSuite .Require ().NoError (err )
187+
188+ assert .DeepEqual (pgDumpAndRestoreTestSuite .T (), testData , restoreResult )
189+ }
190+
125191// TestBasicPGDumpZip performs an integration test for brudi pgdump, with gzip and without use of restic
126192func (pgDumpAndRestoreTestSuite * PGDumpAndRestoreTestSuite ) TestBasicPGDumpAndRestoreGzip () {
127193 ctx := context .Background ()
0 commit comments