-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_test.go
More file actions
122 lines (115 loc) · 2.67 KB
/
Copy pathbackup_test.go
File metadata and controls
122 lines (115 loc) · 2.67 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package zcmd
import (
"os"
"reflect"
"testing"
"time"
)
func TestBackup(t *testing.T) {
t.Parallel()
now := time.Now().Format(time.RFC3339)
hostname, err := os.Hostname()
if err != nil {
t.Fatal(err)
}
cases := []struct {
name string
cfg BackupConfig
rsyncFlags string
expected []rsyncClient
}{
{
name: "1-destination-3-sources",
cfg: BackupConfig{
Destinations: []string{"/backup"},
Includes: []string{"/", "/boot", "/home"},
},
rsyncFlags: "",
expected: []rsyncClient{
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "/", "/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "/boot", "/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "/home", "/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
},
},
{
name: "1-destination-3-sources-rsync-flags",
cfg: BackupConfig{
Destinations: []string{"/backup"},
Includes: []string{"/", "/boot", "/home"},
},
rsyncFlags: "-n",
expected: []rsyncClient{
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "-n", "/", "/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "-n", "/boot", "/backup/" + hostname + "/" + now,
},
},
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "-n", "/home", "/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
},
},
{
name: "1-rsync-destination-1-source",
cfg: BackupConfig{
Destinations: []string{"rsync://localhost/backup"},
Includes: []string{"/"},
},
rsyncFlags: "",
expected: []rsyncClient{
{
command: []string{
"/usr/bin/sudo", "-E", "/usr/bin/rsync",
"-avxRP", "--stats", "--delete", "/", "rsync://localhost/backup/" + hostname + "/" + now,
},
excludeFile: nil,
},
},
},
}
for _, c := range cases {
cfg := c.cfg
rsyncFlags := c.rsyncFlags
expected := c.expected
t.Run(c.name, func(t *testing.T) {
bk := NewBackup(&cfg, rsyncFlags)
rcs, err := bk.generateCmd(now)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(rcs, expected) {
t.Errorf("%#v != %#v", rcs, expected)
}
})
}
}