MCPcopy
hub / github.com/syncthing/syncthing / TestCopyRange

Function TestCopyRange

lib/fs/filesystem_copy_range_test.go:253–409  ·  view source on GitHub ↗
(tttt *testing.T)

Source from the content-addressed store, hash-verified

251)
252
253func TestCopyRange(tttt *testing.T) {
254 randSrc := rand.New(rand.NewSource(rand.Int63()))
255 paths := filepath.SplitList(os.Getenv("STFSTESTPATH"))
256 if len(paths) == 0 {
257 paths = []string{""}
258 }
259 for _, path := range paths {
260 testPath, err := os.MkdirTemp(path, "")
261 if err != nil {
262 tttt.Fatal(err)
263 }
264 defer os.RemoveAll(testPath)
265 name := path
266 if name == "" {
267 name = "tmp"
268 }
269 tttt.Run(name, func(ttt *testing.T) {
270 for copyMethod, impl := range copyRangeMethods {
271 ttt.Run(copyMethod.String(), func(tt *testing.T) {
272 for _, testCase := range testCases {
273 tt.Run(testCase.name, func(t *testing.T) {
274 srcBuf := make([]byte, testCase.srcSize)
275 dstBuf := make([]byte, testCase.dstSize)
276 td, err := os.MkdirTemp(testPath, "")
277 if err != nil {
278 t.Fatal(err)
279 }
280 defer os.RemoveAll(td)
281
282 fs := NewFilesystem(FilesystemTypeBasic, td)
283
284 if _, err := io.ReadFull(randSrc, srcBuf); err != nil {
285 t.Fatal(err)
286 }
287
288 if _, err := io.ReadFull(randSrc, dstBuf); err != nil {
289 t.Fatal(err)
290 }
291
292 src, err := fs.Create("src")
293 if err != nil {
294 t.Fatal(err)
295 }
296 defer func() { _ = src.Close() }()
297
298 dst, err := fs.Create("dst")
299 if err != nil {
300 t.Fatal(err)
301 }
302 defer func() { _ = dst.Close() }()
303
304 // Write some data
305
306 if _, err := src.Write(srcBuf); err != nil {
307 t.Fatal(err)
308 }
309
310 if _, err := dst.Write(dstBuf); err != nil {

Callers

nothing calls this directly

Calls 15

CreateMethod · 0.95
NewFilesystemFunction · 0.85
unwrapFunction · 0.85
Int63Method · 0.80
FatalMethod · 0.80
NewMethod · 0.65
RemoveAllMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected