forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_fetch_handler_test.go
90 lines (76 loc) · 2.69 KB
/
backup_fetch_handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package test
import (
"github.com/stretchr/testify/assert"
"github.com/wal-g/wal-g/internal"
"testing"
)
func TestGetRestoredBackupFilesToUnwrap_SimpleFile(t *testing.T) {
sentinelDto := internal.BackupSentinelDto{
Files: NewBackupFileListBuilder().WithSimple().Build(),
}
files := internal.GetRestoredBackupFilesToUnwrap(sentinelDto)
assert.Contains(t, files, SimplePath)
}
func TestGetRestoredBackupFilesToUnwrap_IncrementedFile(t *testing.T) {
sentinelDto := internal.BackupSentinelDto{
Files: NewBackupFileListBuilder().WithIncremented().Build(),
}
files := internal.GetRestoredBackupFilesToUnwrap(sentinelDto)
assert.Contains(t, files, IncrementedPath)
}
func TestGetRestoredBackupFilesToUnwrap_SkippedFile(t *testing.T) {
sentinelDto := internal.BackupSentinelDto{
Files: NewBackupFileListBuilder().WithSkipped().Build(),
}
files := internal.GetRestoredBackupFilesToUnwrap(sentinelDto)
assert.Contains(t, files, SkippedPath)
}
func TestGetRestoredBackupFilesToUnwrap_UtilityFiles(t *testing.T) {
sentinelDto := internal.BackupSentinelDto{
Files: NewBackupFileListBuilder().Build(),
}
files := internal.GetRestoredBackupFilesToUnwrap(sentinelDto)
assert.Equal(t, internal.UtilityFilePaths, files)
}
func TestGetRestoredBackupFilesToUnwrap_NoMoreFiles(t *testing.T) {
sentinelDto := internal.BackupSentinelDto{
Files: NewBackupFileListBuilder().WithSimple().WithIncremented().WithSkipped().Build(),
}
files := internal.GetRestoredBackupFilesToUnwrap(sentinelDto)
expected := map[string]bool{
SimplePath: true,
IncrementedPath: true,
SkippedPath: true,
}
for utilityPath := range internal.UtilityFilePaths {
expected[utilityPath] = true
}
assert.Equal(t, expected, files)
}
func TestGetBaseFilesToUnwrap_SimpleFile(t *testing.T) {
fileStates := NewBackupFileListBuilder().WithSimple().Build()
currentToUnwrap := map[string]bool{
SimplePath: true,
}
baseToUnwrap, err := internal.GetBaseFilesToUnwrap(fileStates, currentToUnwrap)
assert.NoError(t, err)
assert.Empty(t, baseToUnwrap)
}
func TestGetBaseFilesToUnwrap_IncrementedFile(t *testing.T) {
fileStates := NewBackupFileListBuilder().WithIncremented().Build()
currentToUnwrap := map[string]bool{
IncrementedPath: true,
}
baseToUnwrap, err := internal.GetBaseFilesToUnwrap(fileStates, currentToUnwrap)
assert.NoError(t, err)
assert.Equal(t, currentToUnwrap, baseToUnwrap)
}
func TestGetBaseFilesToUnwrap_SkippedFile(t *testing.T) {
fileStates := NewBackupFileListBuilder().WithSkipped().Build()
currentToUnwrap := map[string]bool{
SkippedPath: true,
}
baseToUnwrap, err := internal.GetBaseFilesToUnwrap(fileStates, currentToUnwrap)
assert.NoError(t, err)
assert.Equal(t, currentToUnwrap, baseToUnwrap)
}