-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsync_test.go
68 lines (63 loc) · 1.93 KB
/
rsync_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
/* See the file "LICENSE.txt" for the full license governing this code. */
package main
import (
"os"
"path/filepath"
"reflect"
"testing"
"time"
)
func TestCreateRsyncCommand(t *testing.T) {
var testSnapshots = snapshotList{
{time.Unix(1400337531, 0), time.Unix(1400338693, 0), stateComplete},
{time.Unix(1400534523, 0), time.Unix(0, 0), stateIncomplete},
}
// shadow global config
var config = config
config.repository = "testdata"
config.ReadCache()
cmd := createRsyncCommand(testSnapshots[1], testSnapshots[0])
got := cmd.Args
wanted := []string{"/usr/bin/rsync", "--delete", "-a", "--stats",
"--link-dest=testdata/.data/1400337531-1400338693-complete",
"/tmp/snaprd_test/",
"testdata/.data/1400534523-0-incomplete"}
if !reflect.DeepEqual(got, wanted) {
t.Errorf("wanted %v, got %v", wanted, got)
}
}
func TestFakeRsyncOk(t *testing.T) {
var testSnapshots = snapshotList{
{time.Unix(1400337531, 0), time.Unix(1400338693, 0), stateComplete},
{time.Unix(1400534523, 0), time.Unix(0, 0), stateIncomplete},
}
var config = config
config.repository = "/tmp/snaprd_dest"
mockRepository()
config.ReadCache()
dir, _ := os.Getwd()
config.RsyncPath = filepath.Join(dir, "fake_rsync")
config.RsyncOpts.Set("--fake_exit=24")
_, err := createSnapshot(testSnapshots[0])
got := err
if got != nil {
t.Errorf("createSnapshot() returned an error, but it shouldn't: %v", got)
}
}
func TestFakeRsyncFail(t *testing.T) {
var testSnapshots = snapshotList{
{time.Unix(1400337531, 0), time.Unix(1400338693, 0), stateComplete},
{time.Unix(1400534523, 0), time.Unix(0, 0), stateIncomplete},
}
var config = config
config.repository = "/tmp/snaprd_dest"
config.ReadCache()
dir, _ := os.Getwd()
config.RsyncPath = filepath.Join(dir, "fake_rsync")
config.RsyncOpts.Set("--fake_exit=3")
_, err := createSnapshot(testSnapshots[0])
got := err
if got == nil {
t.Errorf("createSnapshot() succeeded, but it should have failed: %v", got)
}
}