| 1 | package receiver_test |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "runtime" |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/gokrazy/rsync/internal/rsynctest" |
| 11 | "github.com/google/go-cmp/cmp" |
| 12 | ) |
| 13 | |
| 14 | func init() { |
| 15 | // Run this test in UTC so that the printed timestamp matches our expected |
| 16 | // output. |
| 17 | time.Local = time.UTC |
| 18 | } |
| 19 | |
| 20 | func TestReceiverListing(t *testing.T) { |
| 21 | t.Parallel() |
| 22 | |
| 23 | tmp := t.TempDir() |
| 24 | source := filepath.Join(tmp, "source") |
| 25 | |
| 26 | if err := os.MkdirAll(source, 0755); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | // This explicit chmod might seem redundant at first, |
| 30 | // but is required to make the test pass with umask 027. |
| 31 | if err := os.Chmod(source, 0755); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | hello := filepath.Join(source, "hello") |
| 35 | if err := os.WriteFile(hello, []byte("world"), 0644); err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | // This explicit chmod might seem redundant at first, |
| 39 | // but is required to make the test pass with umask 027. |
| 40 | if err := os.Chmod(hello, 0644); err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | mtime, err := time.Parse(time.RFC3339, "2009-11-10T23:00:00Z") |
| 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | if err := os.Chtimes(hello, mtime, mtime); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | if err := os.Chtimes(source, mtime, mtime); err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | |
| 54 | // start a server to sync from |
| 55 | srv := rsynctest.New(t, rsynctest.InteropModule(source)) |
| 56 | |
| 57 | stdout, _ := rsynctest.Output(t, "gokr-rsync", |
| 58 | "-aH", |
| 59 | "rsync://localhost:"+srv.Port+"/interop/") |
| 60 | want := `drwxr-xr-x 4096 2009/11/10 23:00:00 . |
| 61 | -rw-r--r-- 5 2009/11/10 23:00:00 hello |
| 62 | ` |
| 63 | if runtime.GOOS == "windows" { |
| 64 | want = `drwxrwxrwx 4096 2009/11/10 23:00:00 . |
| 65 | -rw-rw-rw- 5 2009/11/10 23:00:00 hello |
| 66 | ` |
| 67 | } |
| 68 | if diff := cmp.Diff(want, string(stdout)); diff != "" { |
| 69 | t.Fatalf("unexpected listing: diff (-want +got):\n%s", diff) |
| 70 | } |
| 71 | } |