diff --git a/gcsstore/gcsservice.go b/gcsstore/gcsservice.go index f8dd626..a5c34e8 100644 --- a/gcsstore/gcsservice.go +++ b/gcsstore/gcsservice.go @@ -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 { diff --git a/gcsstore/gcsstore.go b/gcsstore/gcsstore.go index b60a73d..a52bba6 100644 --- a/gcsstore/gcsstore.go +++ b/gcsstore/gcsstore.go @@ -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 } diff --git a/gcsstore/gcsstore_test.go b/gcsstore/gcsstore_test.go index aed4ff8..45c0545 100644 --- a/gcsstore/gcsstore_test.go +++ b/gcsstore/gcsstore_test.go @@ -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 {