mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Adding test for partial objects
This commit is contained in:
@@ -80,8 +80,16 @@ func (memory memoryDriver) GetObject(w io.Writer, bucket string, object string)
|
||||
}
|
||||
|
||||
// GetPartialObject - GET object from memory buffer range
|
||||
func (memory memoryDriver) GetPartialObject(w io.Writer, bucket, object string, start, end int64) (int64, error) {
|
||||
return 0, drivers.APINotImplemented{API: "GetPartialObject"}
|
||||
func (memory memoryDriver) GetPartialObject(w io.Writer, bucket, object string, start, length int64) (int64, error) {
|
||||
var sourceBuffer bytes.Buffer
|
||||
if _, err := memory.GetObject(&sourceBuffer, bucket, object); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var nilBuffer bytes.Buffer
|
||||
if _, err := io.CopyN(&nilBuffer, &sourceBuffer, start); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return io.CopyN(w, &sourceBuffer, length)
|
||||
}
|
||||
|
||||
// CreateBucketPolicy - Not implemented
|
||||
|
||||
@@ -6,6 +6,8 @@ import "github.com/stretchr/testify/mock"
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/minio-io/iodine"
|
||||
)
|
||||
|
||||
// Driver is a mock
|
||||
@@ -56,7 +58,7 @@ func (m *Driver) GetBucketPolicy(bucket string) (drivers.BucketPolicy, error) {
|
||||
// SetGetObjectWriter is a mock
|
||||
func (m *Driver) SetGetObjectWriter(bucket, object string, data []byte) {
|
||||
m.ObjectWriterData[bucket+":"+object] = data
|
||||
println(string(m.ObjectWriterData["bucket:object"]))
|
||||
// println(string(m.ObjectWriterData["bucket:object"]))
|
||||
}
|
||||
|
||||
// GetObject is a mock
|
||||
@@ -81,6 +83,17 @@ func (m *Driver) GetPartialObject(w io.Writer, bucket string, object string, sta
|
||||
r0 := ret.Get(0).(int64)
|
||||
r1 := ret.Error(1)
|
||||
|
||||
if r1 == nil {
|
||||
if obj, ok := m.ObjectWriterData[bucket+":"+object]; ok {
|
||||
source := bytes.NewBuffer(obj)
|
||||
var nilSink bytes.Buffer
|
||||
io.CopyN(&nilSink, source, start)
|
||||
n, _ := io.CopyN(w, source, length)
|
||||
r0 = n
|
||||
}
|
||||
}
|
||||
r1 = iodine.New(r1, nil)
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user