MCPcopy
hub / github.com/rclone/rclone / TestOpen

Function TestOpen

backend/http/http_internal_test.go:255–315  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func TestOpen(t *testing.T) {
256 m := prepareServer(t)
257
258 for _, head := range []bool{false, true} {
259 if !head {
260 m.Set("no_head", "true")
261 }
262 f, err := NewFs(context.Background(), remoteName, "", m)
263 require.NoError(t, err)
264
265 for _, rangeRead := range []bool{false, true} {
266 o, err := f.NewObject(context.Background(), "four/under four.txt")
267 require.NoError(t, err)
268
269 if !head {
270 // Test mod time is still indeterminate
271 tObj := o.ModTime(context.Background())
272 assert.Equal(t, time.Duration(0), time.Unix(0, 0).Sub(tObj))
273
274 // Test file size is still indeterminate
275 assert.Equal(t, int64(-1), o.Size())
276 }
277
278 var data []byte
279 if !rangeRead {
280 // Test normal read
281 fd, err := o.Open(context.Background())
282 require.NoError(t, err)
283 data, err = io.ReadAll(fd)
284 require.NoError(t, err)
285 require.NoError(t, fd.Close())
286 if lineEndSize == 2 {
287 assert.Equal(t, "beetroot\r\n", string(data))
288 } else {
289 assert.Equal(t, "beetroot\n", string(data))
290 }
291 } else {
292 // Test with range request
293 fd, err := o.Open(context.Background(), &fs.RangeOption{Start: 1, End: 5})
294 require.NoError(t, err)
295 data, err = io.ReadAll(fd)
296 require.NoError(t, err)
297 require.NoError(t, fd.Close())
298 assert.Equal(t, "eetro", string(data))
299 }
300
301 fi, err := os.Stat(filepath.Join(filesPath, "four", "under four.txt"))
302 require.NoError(t, err)
303 tFile := fi.ModTime()
304
305 // Test the time is always correct on the object after file open
306 tObj := o.ModTime(context.Background())
307 fstest.AssertTimeEqualWithPrecision(t, o.Remote(), tFile, tObj, time.Second)
308
309 if !rangeRead {
310 // Test the file size
311 assert.Equal(t, int64(len(data)), o.Size())
312 }

Callers

nothing calls this directly

Calls 14

NewObjectMethod · 0.95
ModTimeMethod · 0.95
SizeMethod · 0.95
OpenMethod · 0.95
RemoteMethod · 0.95
JoinMethod · 0.80
prepareServerFunction · 0.70
NewFsFunction · 0.70
SetMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…