gcsstore: Remove unnecessary typecasts and unused mocks (#313)
This commit is contained in:
parent
321acd1821
commit
898f3fe72a
|
@ -3,7 +3,7 @@
|
||||||
// GCSStore is a storage backend that uses the GCSAPI interface in order to store uploads
|
// GCSStore is a storage backend that uses the GCSAPI interface in order to store uploads
|
||||||
// on GCS. Uploads will be represented by two files in GCS; the data file will be stored
|
// on GCS. Uploads will be represented by two files in GCS; the data file will be stored
|
||||||
// as an extensionless object [uid] and the JSON info file will stored as [uid].info.
|
// as an extensionless object [uid] and the JSON info file will stored as [uid].info.
|
||||||
// In order to store uploads on GCS, make sure to specifiy the appropriate Google service
|
// In order to store uploads on GCS, make sure to specify the appropriate Google service
|
||||||
// account file path in the GCS_SERVICE_ACCOUNT_FILE environment variable. Also make sure that
|
// account file path in the GCS_SERVICE_ACCOUNT_FILE environment variable. Also make sure that
|
||||||
// this service account file has the "https://www.googleapis.com/auth/devstorage.read_write"
|
// this service account file has the "https://www.googleapis.com/auth/devstorage.read_write"
|
||||||
// scope enabled so you can read and write data to the storage buckets associated with the
|
// scope enabled so you can read and write data to the storage buckets associated with the
|
||||||
|
@ -163,7 +163,7 @@ func (upload gcsUpload) GetInfo(ctx context.Context) (handler.FileInfo, error) {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%s", store.keyWithPrefix(id))
|
prefix := store.keyWithPrefix(id)
|
||||||
filterParams := GCSFilterParams{
|
filterParams := GCSFilterParams{
|
||||||
Bucket: store.Bucket,
|
Bucket: store.Bucket,
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
|
|
|
@ -146,7 +146,7 @@ func TestGetInfo(t *testing.T) {
|
||||||
|
|
||||||
filterParams := gcsstore.GCSFilterParams{
|
filterParams := gcsstore.GCSFilterParams{
|
||||||
Bucket: store.Bucket,
|
Bucket: store.Bucket,
|
||||||
Prefix: fmt.Sprintf("%s", mockID),
|
Prefix: mockID,
|
||||||
}
|
}
|
||||||
|
|
||||||
mockObjectParams0 := gcsstore.GCSObjectParams{
|
mockObjectParams0 := gcsstore.GCSObjectParams{
|
||||||
|
@ -319,7 +319,7 @@ func TestFinishUpload(t *testing.T) {
|
||||||
|
|
||||||
filterParams2 := gcsstore.GCSFilterParams{
|
filterParams2 := gcsstore.GCSFilterParams{
|
||||||
Bucket: store.Bucket,
|
Bucket: store.Bucket,
|
||||||
Prefix: fmt.Sprintf("%s", mockID),
|
Prefix: mockID,
|
||||||
}
|
}
|
||||||
|
|
||||||
composeParams := gcsstore.GCSComposeParams{
|
composeParams := gcsstore.GCSComposeParams{
|
||||||
|
@ -360,7 +360,7 @@ func TestFinishUpload(t *testing.T) {
|
||||||
|
|
||||||
objectParams := gcsstore.GCSObjectParams{
|
objectParams := gcsstore.GCSObjectParams{
|
||||||
Bucket: store.Bucket,
|
Bucket: store.Bucket,
|
||||||
ID: fmt.Sprintf("%s", mockID),
|
ID: mockID,
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata := map[string]string{
|
metadata := map[string]string{
|
||||||
|
@ -394,39 +394,6 @@ func TestFinishUpload(t *testing.T) {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
var mockTusdChunk0InfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"Offset":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize, mockSize/3)
|
|
||||||
var mockTusdChunk1Info = handler.FileInfo{
|
|
||||||
ID: mockID,
|
|
||||||
Size: mockSize,
|
|
||||||
Offset: 455,
|
|
||||||
MetaData: map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
type MockWriteChunkReader struct{}
|
|
||||||
|
|
||||||
func (r MockWriteChunkReader) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r MockWriteChunkReader) ContentType() string {
|
|
||||||
return "text/plain; charset=utf-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r MockWriteChunkReader) Read(p []byte) (int, error) {
|
|
||||||
copy(p, mockTusdChunk0InfoJson)
|
|
||||||
return len(p), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r MockWriteChunkReader) Remain() int64 {
|
|
||||||
return int64(len(mockTusdChunk0InfoJson))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r MockWriteChunkReader) Size() int64 {
|
|
||||||
return int64(len(mockTusdChunk0InfoJson))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWriteChunk(t *testing.T) {
|
func TestWriteChunk(t *testing.T) {
|
||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
defer mockCtrl.Finish()
|
defer mockCtrl.Finish()
|
||||||
|
@ -459,14 +426,12 @@ func TestWriteChunk(t *testing.T) {
|
||||||
service.EXPECT().WriteObject(ctx, writeObjectParams, rGet).Return(int64(len(mockReaderData)), nil),
|
service.EXPECT().WriteObject(ctx, writeObjectParams, rGet).Return(int64(len(mockReaderData)), nil),
|
||||||
)
|
)
|
||||||
|
|
||||||
reader := bytes.NewReader([]byte(mockReaderData))
|
|
||||||
var offset int64
|
|
||||||
offset = mockSize / 3
|
|
||||||
|
|
||||||
upload, err := store.GetUpload(context.Background(), mockID)
|
upload, err := store.GetUpload(context.Background(), mockID)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
reader := bytes.NewReader([]byte(mockReaderData))
|
||||||
|
var offset int64 = mockSize / 3
|
||||||
|
|
||||||
_, err = upload.WriteChunk(context.Background(), offset, reader)
|
_, err = upload.WriteChunk(context.Background(), offset, reader)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ func TestHead(t *testing.T) {
|
||||||
},
|
},
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
|
|
||||||
if string(res.Body.Bytes()) != "" {
|
if res.Body.String() != "" {
|
||||||
t.Errorf("Expected empty body for failed HEAD request")
|
t.Errorf("Expected empty body for failed HEAD request")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -82,8 +82,8 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) *httptest.Response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.ResBody != "" && string(w.Body.Bytes()) != test.ResBody {
|
if test.ResBody != "" && w.Body.String() != test.ResBody {
|
||||||
t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes()))
|
t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
|
Loading…
Reference in New Issue