Merge pull request #190 from vially/fix-gcs-info-not-found

Handle GCS object not found error
This commit is contained in:
Marius 2018-05-25 12:29:54 +02:00 committed by GitHub
commit 3a4f216d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -13,8 +13,9 @@ import (
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"github.com/vimeo/go-util/crc32combine"
"hash/crc32"
"github.com/vimeo/go-util/crc32combine"
)
type GCSObjectParams struct {
@ -260,7 +261,7 @@ func (service *GCSService) GetObjectAttrs(params GCSObjectParams) (*storage.Obje
}
// ReadObject reaads a GCSObjectParams, returning a GCSReader object if successful, and an error otherwise
// ReadObject reads a GCSObjectParams, returning a GCSReader object if successful, and an error otherwise
func (service *GCSService) ReadObject(params GCSObjectParams) (GCSReader, error) {
r, err := service.Client.Bucket(params.Bucket).Object(params.ID).NewReader(service.Ctx)
if err != nil {

View File

@ -18,6 +18,7 @@ import (
"strconv"
"strings"
"cloud.google.com/go/storage"
"github.com/tus/tusd"
"github.com/tus/tusd/uid"
)
@ -113,6 +114,9 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
r, err := store.Service.ReadObject(params)
if err != nil {
if err == storage.ErrObjectNotExist {
return info, tusd.ErrNotFound
}
return info, err
}

View File

@ -6,6 +6,7 @@ import (
"fmt"
"testing"
"cloud.google.com/go/storage"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
@ -143,6 +144,27 @@ func TestGetInfo(t *testing.T) {
assert.Equal(mockTusdInfo, info)
}
func TestGetInfoNotFound(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
assert := assert.New(t)
service := NewMockGCSAPI(mockCtrl)
store := gcsstore.New(mockBucket, service)
params := gcsstore.GCSObjectParams{
Bucket: store.Bucket,
ID: fmt.Sprintf("%s.info", mockID),
}
gomock.InOrder(
service.EXPECT().ReadObject(params).Return(nil, storage.ErrObjectNotExist),
)
_, err := store.GetInfo(mockID)
assert.Equal(tusd.ErrNotFound, err)
}
type MockGetReader struct{}
func (r MockGetReader) Close() error {