beyondstorage / go-storage

A vendor-neutral storage library for Golang: Write once, run on every storage service.

Home Page:https://beyondstorage.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

services/obs: Service test failed for content mismatch

Xuanwo opened this issue · comments

     When Read a file with offset or size 
      When Read with offset 
        The error should be nil ✔✔
        The content should be match ✔✘✔
      When Read with size 
        The error should be nil ✔✔
        The content should be match ✔✘✔
      When Read with offset and size 
        The error should be nil ✔✔
        The content should be match ✔✘✔

 Failures:

  * /data/actions/beta/go-storage/go-storage/services/obs/tests/storage_test.go 
  Line 14:
  Expected: '138112'
  Actual:   '451281'
  (Should be equal)

  * /data/actions/beta/go-storage/go-storage/services/obs/tests/storage_test.go 
  Line 14:
  Expected: '1288953'
  Actual:   '2688928'
  (Should be equal)

  * /data/actions/beta/go-storage/go-storage/services/obs/tests/storage_test.go 
  Line 14:
  Expected: '49793'
  Actual:   '291284'
  (Should be equal)

Obs implementation must be buggy, let's fix it before release.

obs doesn't support offset and size now:

func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairStorageRead) (n int64, err error) {
rp := s.getAbsPath(path)
input := &obs.GetObjectInput{}
input.Bucket = s.bucket
input.Key = rp
output, err := s.client.GetObject(input)
if err != nil {
return 0, err
}
rc := output.Body
if opt.HasIoCallback {
rc = iowrap.CallbackReadCloser(rc, opt.IoCallback)
}
return io.Copy(w, rc)

this can be fixed by like:

func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairStorageRead) (n int64, err error) {
rp := s.getAbsPath(path)
output := &api.GetObjectResult{}
if opt.HasOffset && !opt.HasSize {
output, err = s.client.GetObject(s.bucket, rp, nil, opt.Offset)
} else if !opt.HasOffset && opt.HasSize {
output, err = s.client.GetObject(s.bucket, rp, nil, 0, opt.Size-1)
} else if opt.HasSize && opt.HasOffset {
output, err = s.client.GetObject(s.bucket, rp, nil, opt.Offset, opt.Offset+opt.Size-1)
} else {
output, err = s.client.GetObject(s.bucket, rp, nil)
}