tusd/s3store/s3store_util_test.go

58 lines
1.0 KiB
Go
Raw Normal View History

2016-01-05 17:21:53 +00:00
package s3store_test
import (
"fmt"
"io/ioutil"
"reflect"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/golang/mock/gomock"
)
type UploadPartInputMatcher struct {
expect *s3.UploadPartInput
}
func NewUploadPartInputMatcher(expect *s3.UploadPartInput) gomock.Matcher {
return UploadPartInputMatcher{
expect: expect,
}
}
func (m UploadPartInputMatcher) Matches(x interface{}) bool {
input, ok := x.(*s3.UploadPartInput)
if !ok {
return false
}
inputBody := input.Body
expectBody := m.expect.Body
i, err := ioutil.ReadAll(inputBody)
if err != nil {
panic(err)
}
inputBody.Seek(0, 0)
e, err := ioutil.ReadAll(expectBody)
if err != nil {
panic(err)
}
m.expect.Body.Seek(0, 0)
if !reflect.DeepEqual(e, i) {
return false
}
input.Body = nil
m.expect.Body = nil
return reflect.DeepEqual(m.expect, input)
}
func (m UploadPartInputMatcher) String() string {
body, _ := ioutil.ReadAll(m.expect.Body)
m.expect.Body.Seek(0, 0)
return fmt.Sprintf("UploadPartInput(%d: %s)", *m.expect.PartNumber, body)
}