core, gcsstore: Update deprecated methods (#312)

This commit is contained in:
Ankit Pokhrel 2019-10-08 10:30:19 +02:00 committed by Marius
parent 5414e88fbb
commit 321acd1821
3 changed files with 12 additions and 12 deletions

View File

@ -77,10 +77,10 @@ type GCSService struct {
Client *storage.Client Client *storage.Client
} }
// NewGCSService returns a GCSSerivce object given a GCloud service account file path. // NewGCSService returns a GCSService object given a GCloud service account file path.
func NewGCSService(filename string) (*GCSService, error) { func NewGCSService(filename string) (*GCSService, error) {
ctx := context.Background() ctx := context.Background()
client, err := storage.NewClient(ctx, option.WithServiceAccountFile(filename)) client, err := storage.NewClient(ctx, option.WithCredentialsFile(filename))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -269,7 +269,7 @@ func (service *GCSService) ReadObject(ctx context.Context, params GCSObjectParam
return r, nil return r, nil
} }
// SetObjectMetadata reads a GCSObjectParams and a map of metedata, returning a nil on sucess and an error otherwise // SetObjectMetadata reads a GCSObjectParams and a map of metadata, returning a nil on success and an error otherwise
func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error { func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error {
attrs := storage.ObjectAttrsToUpdate{ attrs := storage.ObjectAttrsToUpdate{
Metadata: metadata, Metadata: metadata,
@ -324,11 +324,11 @@ func (service *GCSService) ComposeFrom(ctx context.Context, objSrcs []*storage.O
return dstAttrs.CRC32C, nil return dstAttrs.CRC32C, nil
} }
// FilterObjects retuns a list of GCS object IDs that match the passed GCSFilterParams. // FilterObjects returns a list of GCS object IDs that match the passed GCSFilterParams.
// It expects GCS objects to be of the format [uid]_[chunk_idx] where chunk_idx // It expects GCS objects to be of the format [uid]_[chunk_idx] where chunk_idx
// is zero based. The format [uid]_tmp_[recursion_lvl]_[chunk_idx] can also be used to // is zero based. The format [uid]_tmp_[recursion_lvl]_[chunk_idx] can also be used to
// specify objects that have been composed in a recursive fashion. These different formats // specify objects that have been composed in a recursive fashion. These different formats
// are usedd to ensure that objects are composed in the correct order. // are used to ensure that objects are composed in the correct order.
func (service *GCSService) FilterObjects(ctx context.Context, params GCSFilterParams) ([]string, error) { func (service *GCSService) FilterObjects(ctx context.Context, params GCSFilterParams) ([]string, error) {
bkt := service.Client.Bucket(params.Bucket) bkt := service.Client.Bucket(params.Bucket)
q := storage.Query{ q := storage.Query{
@ -384,6 +384,6 @@ loop:
names[idx] = objAttrs.Name names[idx] = objAttrs.Name
} }
return names, nil
return names, nil
} }

View File

@ -59,19 +59,19 @@ func TestCORS(t *testing.T) {
req.Host = "tus.io" req.Host = "tus.io"
res := httptest.NewRecorder() res := httptest.NewRecorder()
res.HeaderMap.Set("Access-Control-Allow-Headers", "HEADER") res.Header().Set("Access-Control-Allow-Headers", "HEADER")
res.HeaderMap.Set("Access-Control-Allow-Methods", "METHOD") res.Header().Set("Access-Control-Allow-Methods", "METHOD")
handler.ServeHTTP(res, req) handler.ServeHTTP(res, req)
headers := res.HeaderMap["Access-Control-Allow-Headers"] headers := res.Header()["Access-Control-Allow-Headers"]
methods := res.HeaderMap["Access-Control-Allow-Methods"] methods := res.Header()["Access-Control-Allow-Methods"]
if headers[0] != "HEADER" { if headers[0] != "HEADER" {
t.Errorf("expected header to contain HEADER but got: %#v", headers) t.Errorf("expected header to contain HEADER but got: %#v", headers)
} }
if methods[0] != "METHOD" { if methods[0] != "METHOD" {
t.Errorf("expected header to contain HEADER but got: %#v", methods) t.Errorf("expected header to contain METHOD but got: %#v", methods)
} }
}) })
} }

View File

@ -75,7 +75,7 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) *httptest.Response
} }
for key, value := range test.ResHeader { for key, value := range test.ResHeader {
header := w.HeaderMap.Get(key) header := w.Header().Get(key)
if value != header { if value != header {
t.Errorf("Expected '%s' as '%s' (got '%s')", value, key, header) t.Errorf("Expected '%s' as '%s' (got '%s')", value, key, header)