You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

read.go 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package vfstest
  2. import (
  3. "io"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. // TestReadByByte reads by byte including don't read any bytes
  8. func TestReadByByte(t *testing.T) {
  9. run.skipIfNoFUSE(t)
  10. var data = []byte("hellohello")
  11. run.createFile(t, "testfile", string(data))
  12. run.checkDir(t, "testfile 10")
  13. for i := 0; i < len(data); i++ {
  14. fd, err := run.os.Open(run.path("testfile"))
  15. assert.NoError(t, err)
  16. for j := 0; j < i; j++ {
  17. buf := make([]byte, 1)
  18. n, err := io.ReadFull(fd, buf)
  19. assert.NoError(t, err)
  20. assert.Equal(t, 1, n)
  21. assert.Equal(t, buf[0], data[j])
  22. }
  23. err = fd.Close()
  24. assert.NoError(t, err)
  25. }
  26. run.rm(t, "testfile")
  27. }
  28. // TestReadChecksum checks the checksum reading is working
  29. func TestReadChecksum(t *testing.T) {
  30. run.skipIfNoFUSE(t)
  31. // create file big enough so we exceed any single FUSE read
  32. // request
  33. b := make([]rune, 3*128*1024)
  34. for i := range b {
  35. b[i] = 'r'
  36. }
  37. run.createFile(t, "bigfile", string(b))
  38. // The hash comparison would fail in Flush, if we did not
  39. // ensure we read the whole file
  40. fd, err := run.os.Open(run.path("bigfile"))
  41. assert.NoError(t, err)
  42. buf := make([]byte, 10)
  43. _, err = io.ReadFull(fd, buf)
  44. assert.NoError(t, err)
  45. err = fd.Close()
  46. assert.NoError(t, err)
  47. // The hash comparison would fail, because we only read parts
  48. // of the file
  49. fd, err = run.os.Open(run.path("bigfile"))
  50. assert.NoError(t, err)
  51. // read at start
  52. _, err = io.ReadFull(fd, buf)
  53. assert.NoError(t, err)
  54. // read at end
  55. _, err = fd.Seek(int64(len(b)-len(buf)), io.SeekStart)
  56. assert.NoError(t, err)
  57. _, err = io.ReadFull(fd, buf)
  58. assert.NoError(t, err)
  59. // ensure we don't compare hashes
  60. err = fd.Close()
  61. assert.NoError(t, err)
  62. run.rm(t, "bigfile")
  63. }
  64. // TestReadSeek test seeking
  65. func TestReadSeek(t *testing.T) {
  66. run.skipIfNoFUSE(t)
  67. var data = []byte("helloHELLO")
  68. run.createFile(t, "testfile", string(data))
  69. run.checkDir(t, "testfile 10")
  70. fd, err := run.os.Open(run.path("testfile"))
  71. assert.NoError(t, err)
  72. // Seek to half way
  73. _, err = fd.Seek(5, io.SeekStart)
  74. assert.NoError(t, err)
  75. buf, err := io.ReadAll(fd)
  76. assert.NoError(t, err)
  77. assert.Equal(t, buf, []byte("HELLO"))
  78. // Test seeking to the end
  79. _, err = fd.Seek(10, io.SeekStart)
  80. assert.NoError(t, err)
  81. buf, err = io.ReadAll(fd)
  82. assert.NoError(t, err)
  83. assert.Equal(t, buf, []byte(""))
  84. // Test seeking beyond the end
  85. _, err = fd.Seek(1000000, io.SeekStart)
  86. assert.NoError(t, err)
  87. buf, err = io.ReadAll(fd)
  88. assert.NoError(t, err)
  89. assert.Equal(t, buf, []byte(""))
  90. // Now back to the start
  91. _, err = fd.Seek(0, io.SeekStart)
  92. assert.NoError(t, err)
  93. buf, err = io.ReadAll(fd)
  94. assert.NoError(t, err)
  95. assert.Equal(t, buf, []byte("helloHELLO"))
  96. err = fd.Close()
  97. assert.NoError(t, err)
  98. run.rm(t, "testfile")
  99. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。