Debian Codegraph @

internal/rsyncchecksum/checksum_test.go

raw symbols SCIP
1 package rsyncchecksum_testscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_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 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
7 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
8
9 "github.com/gokrazy/rsync/internal/rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/"
10 )
11
12 func constructLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_test`/constructLargeDataFile().(headPattern, bodyPattern, endPattern []byte) []byte {
13 // create large data file in source directory to be copied
14 head := bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().(headPattern, 1*1024*1024)
15 body := bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().(bodyPattern, 1*1024*1024)
16 end := bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().(endPattern, 1*1024*1024)
17 return append(append(head, body...), end...)
18 }
19
20 func writeLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_test`/writeLargeDataFile().(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#, source string, headPattern, bodyPattern, endPattern []byte) {
21 // create large data file in source directory to be copied
22 content := constructLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_test`/constructLargeDataFile().(headPattern, bodyPattern, endPattern)
23 large := 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().(source, "large-data-file")
24 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().(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().(large), 0755); err != nil {
25 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
26 }
27 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().(large, content, 0644); err != nil {
28 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
29 }
30 }
31
32 func TestSyncExtendedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_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#) {
33 tmp := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().()
34 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")
35
36 writeLargeDataFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum_test`/writeLargeDataFile().(t, source, []byte{0x11}, []byte{0xbb}, []byte{0xee})
37
38 // These values are taken from the rsync debug output:
39 const k = 1768
40 want := make([]uint32, 1780)
41 for i := 0; i <= 592; i++ {
42 want[i] = 0xa5d47568
43 }
44 want[593] = 0x23645688
45 for i := 594; i <= 1185; i++ {
46 want[i] = 0x8c1c2378
47 }
48 want[1186] = 0x12504720
49 for i := 1187; i <= 1778; i++ {
50 want[i] = 0x7d9883b0
51 }
52 want[1779] = 0x61b8dff0
53
54 sourceLarge := 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().(source, "large-data-file")
55 f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Openscip-go gomod github.com/golang/go/src go1.25.0 os/Open().(sourceLarge)
56 if err != nil {
57 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
58 }
59 defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().()
60 buf := make([]byte, k)
61 for idx, wantChecksum := range want {
62 n, err := f.Readscip-go gomod github.com/golang/go/src go1.25.0 os/File#Read().(buf)
63 if err != nil {
64 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
65 }
66
67 chunk := buf[:n]
68 sum := rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.Checksum1scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/Checksum1().(chunk)
69 if sum != wantChecksum {
70 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("checksum calculation error: got %08x, want %08x (idx %d), chunk: %#v", sum, wantChecksum, idx, chunk)
71 }
72 }
73 }