Debian Codegraph @

integration/sync/sync_test.go

raw symbols SCIP
1 package sync_testscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
6 "os/execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/"
7 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
8 "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/"
9 "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/"
10 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
11 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
12
13 "github.com/gokrazy/rsync/internal/rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/"
14 "github.com/gokrazy/rsync/internal/testloggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/"
15 )
16
17 func TestMainscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/TestMain().(m *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Mscip-go gomod github.com/golang/go/src go1.25.0 testing/M#) {
18 rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.CommandMainscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/CommandMain().(m)
19 }
20
21 var statsTransferRescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/statsTransferRe. = regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`^sent ([0-9,]+) bytes received ([0-9,]+) bytes ([0-9,.]+) bytes/sec$`)
22
23 func TestSyncExtendedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/TestSyncExtended().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
24 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
25
26 rsyncBin := rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.TridgeOrGTFOscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/TridgeOrGTFO().(t, "TODO: reason")
27
28 tmp := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().()
29 source := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "source")
30 dest := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "dest")
31 destLarge := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dest, "large-data-file")
32
33 headPattern := []byte{0x11}
34 bodyPattern := []byte{0xbb}
35 endPattern := []byte{0xee}
36 rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.WriteLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/WriteLargeDataFile().(t, source, headPattern, bodyPattern, endPattern)
37
38 // start a server to sync from
39 srv := rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.Newscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/New().(t, rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.InteropModulescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/InteropModule().(source))
40
41 sync := func() int64 {
42 rsync := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(rsyncBin,
43 // "--debug=all4",
44 "--archive",
45 // A verbosity level of 3 is enough, any higher than that and rsync
46 // will start listing individual chunk matches.
47 "-v", "-v", "-v", // "-v",
48 "--checksum",
49 "--port="+srv.Portscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/TestServer#Port.,
50 "rsync://localhost/interop/", // copy contents of source
51 filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(dest))
52 rsync.Dirscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Dir. = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Dir().(dest)
53 rsync.Envscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Env. = append(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Environscip-go gomod github.com/golang/go/src go1.25.0 os/Environ().(),
54 // Ensure rsync does not localize decimal separators and fractional
55 // points based on the current locale:
56 "LANG=C.UTF-8")
57 var buf bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#
58 rsync.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdout. = &buf
59 rsync.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stderr. = testloggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/.Newscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/testlogger`/New().(t)
60 if err := rsync.Runscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Run().(); err != nil {
61 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%v: %v", rsync.Argsscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Args., err)
62 }
63
64 if err := rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.DataFileMatchesscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/DataFileMatches().(destLarge, headPattern, bodyPattern, endPattern); err != nil {
65 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
66 }
67
68 totalRead := int64(-1)
69 for _, line := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(buf.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().(), "\n") {
70 // log.Printf("rsync output line: %q", line)
71 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(line, "sent ") {
72 // e.g.:
73 // sent 1,590 bytes received 18 bytes 3,216.00 bytes/sec
74 // total size is 1,188,046 speedup is 738.83
75 matches := statsTransferRescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/statsTransferRe..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindStringSubmatch().(line)
76 if len(matches) == 0 {
77 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not parse rsync 'sent' line")
78 }
79
80 var err error
81 totalRead, err = strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseInt().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.25.0 strings/ReplaceAll().(matches[2], ",", ""), 0, 64)
82 if err != nil {
83 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
84 }
85 }
86 }
87 return totalRead
88 }
89
90 {
91 // initial sync into dest dir
92 totalRead := sync()
93 if got, want := totalRead, int64(3*1024); got < want {
94 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("rsync unexpectedly did not read the whole file over the network: got %d, want >= %d", got, want)
95 }
96 }
97
98 {
99 // second sync (unmodified) into dest dir
100 totalRead := sync()
101 if got, want := totalRead, int64(512*1024); got >= want {
102 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("rsync unexpectedly transferred more data than needed: got %d, want < %d", got, want)
103 }
104 }
105
106 // Change the middle of the large data file:
107 bodyPattern = []byte{0x66}
108 {
109 // modify the large data file
110 rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.WriteLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/WriteLargeDataFile().(t, source, headPattern, bodyPattern, endPattern)
111
112 // sync modifications into dest dir
113 totalRead := sync()
114
115 // TODO: verify speedup value, compare to rsync and openrsync
116
117 if got, want := totalRead, int64(2*1024*1024); got >= want {
118 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("rsync unexpectedly transferred more data than needed: got %d, want < %d", got, want)
119 }
120 }
121 }
122
123 func TestSyncMultipleSourcesscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/integration/sync_test`/TestSyncMultipleSources().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
124 tmp := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().()
125 src1 := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "src1")
126 src2 := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "src2")
127 dest := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmp, "dest")
128 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(src1, 0755); err != nil {
129 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
130 }
131 const hello = "world"
132 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(src1, "hello"), []byte(hello), 0644); err != nil {
133 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
134 }
135 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(src2, 0755); err != nil {
136 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
137 }
138 const bye = "moon"
139 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(src2, "bye"), []byte(bye), 0644); err != nil {
140 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
141 }
142
143 rsynctestscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/.Runscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynctest`/Run().(t, "gokr-rsync",
144 "-av",
145 src1,
146 src2,
147 dest)
148
149 hellob, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dest, "src1", "hello"))
150 if err != nil {
151 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
152 }
153 if !bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(hellob, []byte(hello)) {
154 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("file 'hello' has unexpected contents: got %q, want %q", string(hellob), hello)
155 }
156
157 byeb, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dest, "src2", "bye"))
158 if err != nil {
159 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
160 }
161 if !bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(byeb, []byte(bye)) {
162 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("file 'bye' has unexpected contents: got %q, want %q", string(byeb), bye)
163 }
164 }