MCPcopy
hub / github.com/git-lfs/git-lfs / TestCloneFile

Function TestCloneFile

tools/util_windows_test.go:19–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestCloneFile(t *testing.T) {
20 testDir := os.Getenv("REFS_TEST_DIR")
21 if testDir == "" {
22 testDir, _ = Getwd()
23 }
24
25 t.Logf("testing on: %s", testDir)
26
27 supported, err := CheckCloneFileSupported(testDir)
28 if err != nil || !supported {
29 t.Skip(err)
30 }
31
32 testCases := []struct {
33 name string
34 size int64
35 }{
36 {"Small", 123},
37 {"Smaller than 4K", 4*1024 - 1},
38 {"Equal to 4K", 4 * 1024},
39 {"Larger than 4K", 4*1024 + 1},
40 {"Smaller than 64K", 64*1024 - 1},
41 {"Equal to 64K", 64 * 1024},
42 {"Larger than 64K", 64*1024 + 1},
43 {"Large", 12345678},
44 }
45
46 for _, tc := range testCases {
47 t.Run(tc.name, func(t *testing.T) {
48 as := assert.New(t)
49
50 src, err := os.CreateTemp(testDir, tc.name+"_src")
51 as.NoError(err)
52 dst, err := os.CreateTemp(testDir, tc.name+"_dst")
53 as.NoError(err)
54
55 srcHash, err := fillFile(src, tc.size)
56 as.NoError(err)
57
58 ok, err := CloneFile(dst, src)
59 as.NoError(err)
60 as.True(ok)
61
62 sha := sha256.New()
63 dst.Seek(0, io.SeekStart)
64 io.Copy(sha, dst)
65 dstHash := hex.EncodeToString(sha.Sum(nil))
66
67 as.Equal(srcHash, dstHash)
68 })
69 }
70}
71
72func fillFile(target *os.File, size int64) (hash string, err error) {
73 str := make([]byte, 1024)

Callers

nothing calls this directly

Calls 9

GetwdFunction · 0.85
fillFileFunction · 0.85
LogfMethod · 0.80
SeekMethod · 0.80
CheckCloneFileSupportedFunction · 0.70
CloneFileFunction · 0.70
SkipMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected