Skip to content

Commit

Permalink
Merge pull request #9 from vimeo/gcs-rm-get-info-write
Browse files Browse the repository at this point in the history
Remove writing of info file in GCS in GetInfo method
  • Loading branch information
tab1293 authored Oct 2, 2020
2 parents 84d83df + 84afc53 commit e100660
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
5 changes: 0 additions & 5 deletions pkg/gcsstore/gcsstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ func (upload gcsUpload) GetInfo(ctx context.Context) (handler.FileInfo, error) {
}

info.Offset = offset
err = store.writeInfo(ctx, store.keyWithPrefix(id), info)
if err != nil {
return info, err
}

return info, nil
}

Expand Down
32 changes: 9 additions & 23 deletions pkg/gcsstore/gcsstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,27 @@ func TestGetInfo(t *testing.T) {
ID: mockPartial2,
}

var size int64 = 100

mockTusdInfo.Offset = 300
offsetInfoData, err := json.Marshal(mockTusdInfo)
assert.Nil(err)

infoR := bytes.NewReader(offsetInfoData)

ctx := context.Background()
gomock.InOrder(
service.EXPECT().ReadObject(ctx, params).Return(r, nil),
service.EXPECT().FilterObjects(ctx, filterParams).Return(mockPartials, nil),
)

var size int64 = 100
ctxCancel, cancel := context.WithCancel(ctx)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams0).Return(size, nil)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams1).Return(size, nil)
lastGetObjectSize := service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams2).Return(size, nil)

service.EXPECT().WriteObject(ctx, params, infoR).Return(int64(len(offsetInfoData)), nil).After(lastGetObjectSize)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams2).Return(size, nil)

upload, err := store.GetUpload(context.Background(), mockID)
assert.Nil(err)

info, err := upload.GetInfo(context.Background())
assert.Nil(err)
assert.Equal(mockTusdInfo, info)

expectedTusInfo := mockTusdInfo
expectedTusInfo.Offset = 300
assert.Equal(expectedTusInfo, info)

// Cancel the context to avoid getting an error from `go vet`
cancel()
Expand Down Expand Up @@ -350,14 +344,6 @@ func TestFinishUpload(t *testing.T) {
ID: mockPartial2,
}

var size int64 = 100

mockTusdInfo.Offset = 300
offsetInfoData, err := json.Marshal(mockTusdInfo)
assert.Nil(err)

infoR := bytes.NewReader(offsetInfoData)

objectParams := gcsstore.GCSObjectParams{
Bucket: store.Bucket,
ID: mockID,
Expand All @@ -376,13 +362,13 @@ func TestFinishUpload(t *testing.T) {
service.EXPECT().FilterObjects(ctx, filterParams2).Return(mockPartials, nil),
)

var size int64 = 100
ctxCancel, cancel := context.WithCancel(ctx)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams0).Return(size, nil)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams1).Return(size, nil)
lastGetObjectSize := service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams2).Return(size, nil)
service.EXPECT().GetObjectSize(ctxCancel, mockObjectParams2).Return(size, nil)

writeObject := service.EXPECT().WriteObject(ctx, infoParams, infoR).Return(int64(len(offsetInfoData)), nil).After(lastGetObjectSize)
service.EXPECT().SetObjectMetadata(ctx, objectParams, metadata).Return(nil).After(writeObject)
service.EXPECT().SetObjectMetadata(ctx, objectParams, metadata).Return(nil)

upload, err := store.GetUpload(context.Background(), mockID)
assert.Nil(err)
Expand Down

0 comments on commit e100660

Please sign in to comment.