Handle GCS object-not-found error
This commit is contained in:
parent
b1b51b8688
commit
368a3672f9
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue