Skip to content

Commit 16e8571

Browse files
author
Levent Koch
committed
Add test cases for: Add directory handling for restore backup
1 parent ba31a8e commit 16e8571

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/pkg/source/postgrestest/postgres_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
const pgPort = "5432/tcp"
2727
const backupPath = "/tmp/postgres.dump.tar"
2828
const backupPathPlain = "/tmp/postgres.dump"
29+
const backupPathDir = "/tmp/postgres-dir"
2930
const backupPathZip = "/tmp/postgres.dump.tar.gz"
3031
const backupPathPlainZip = "/tmp/postgres.dump.gz"
3132
const 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
126192
func (pgDumpAndRestoreTestSuite *PGDumpAndRestoreTestSuite) TestBasicPGDumpAndRestoreGzip() {
127193
ctx := context.Background()

0 commit comments

Comments
 (0)