-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
76 lines (72 loc) · 2.03 KB
/
main_test.go
File metadata and controls
76 lines (72 loc) · 2.03 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
package main
import (
"testing"
"time"
)
func TestCompare(t *testing.T) {
tests := []struct {
local *FileStat
remote *FileStat
shouldSync bool
}{
{
local: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
shouldSync: false,
},
{
local: &FileStat{Name: "lol.html", Size: 1, ModTime: time.Time{}},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
shouldSync: true,
},
{
local: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
remote: &FileStat{Name: "file.html", Size: 2, ModTime: time.Time{}},
shouldSync: true,
},
{
local: &FileStat{Name: "file.html", Size: 2, ModTime: time.Time{}},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
shouldSync: true,
},
{
local: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Now()},
shouldSync: false,
},
{
local: &FileStat{Name: "file.html", Size: 1, ModTime: time.Now()},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Time{}},
shouldSync: true,
},
{
local: &FileStat{Name: "file.html", Size: 1, ModTime: time.Now()},
remote: &FileStat{Name: "file.html", Size: 1, ModTime: time.Now().Add(-time.Minute)},
shouldSync: true,
},
}
for _, test := range tests {
logger, buf := getTestLogger()
localFiles := make(chan *FileStat)
remoteFiles := make(chan *FileStat)
go func() {
localFiles <- test.local
close(localFiles)
}()
go func() {
remoteFiles <- test.remote
close(remoteFiles)
}()
files := compare(localFiles, remoteFiles, logger)
var updates []*FileStat
for f := range files {
updates = append(updates, f)
}
actual := len(updates) > 0
if actual != test.shouldSync {
t.Errorf("Expected sync %t, but got %t\n", test.shouldSync, actual)
t.Errorf("%s\n", updates[0])
t.Errorf("%s\n", buf)
}
}
}