-
Notifications
You must be signed in to change notification settings - Fork 32
/
receiver_listing_test.go
62 lines (55 loc) · 1.42 KB
/
receiver_listing_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
package rsync_test
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/gokrazy/rsync/internal/receivermaincmd"
"github.com/gokrazy/rsync/internal/rsynctest"
"github.com/google/go-cmp/cmp"
)
func init() {
// Run this test in UTC so that the printed timestamp matches our expected
// output.
time.Local = time.UTC
}
func TestReceiverListing(t *testing.T) {
tmp := t.TempDir()
source := filepath.Join(tmp, "source")
if err := os.MkdirAll(source, 0755); err != nil {
t.Fatal(err)
}
hello := filepath.Join(source, "hello")
if err := ioutil.WriteFile(hello, []byte("world"), 0644); err != nil {
t.Fatal(err)
}
mtime, err := time.Parse(time.RFC3339, "2009-11-10T23:00:00Z")
if err != nil {
t.Fatal(err)
}
if err := os.Chtimes(hello, mtime, mtime); err != nil {
t.Fatal(err)
}
if err := os.Chtimes(source, mtime, mtime); err != nil {
t.Fatal(err)
}
// start a server to sync from
srv := rsynctest.New(t, rsynctest.InteropModule(source))
args := []string{
"gokr-rsync",
"-aH",
"rsync://localhost:" + srv.Port + "/interop/",
}
var stdout bytes.Buffer
if _, err := receivermaincmd.Main(args, os.Stdin, &stdout, &stdout); err != nil {
t.Fatal(err)
}
want := `drwxr-xr-x 4096 2009/11/10 23:00:00 .
-rw-r--r-- 5 2009/11/10 23:00:00 hello
`
if diff := cmp.Diff(want, stdout.String()); diff != "" {
t.Fatalf("unexpected listing: diff (-want +got):\n%s", diff)
}
}