fix(storage): return the appropriate error for method not supported (… · googleapis/google-cloud-go@56d704e

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -863,7 +863,7 @@ func (c *httpStorageClient) RewriteObject(ctx context.Context, req *rewriteObjec

863863
864864

// NewMultiRangeDownloader is not supported by http client.

865865

func (c *httpStorageClient) NewMultiRangeDownloader(ctx context.Context, params *newMultiRangeDownloaderParams, opts ...storageOption) (mr *MultiRangeDownloader, err error) {

866-

return nil, errMethodNotValid

866+

return nil, errMethodNotSupported

867867

}

868868
869869

func (c *httpStorageClient) NewRangeReader(ctx context.Context, params *newRangeReaderParams, opts ...storageOption) (r *Reader, err error) {

Original file line numberDiff line numberDiff line change

@@ -72,8 +72,8 @@ var (

7272

// errMethodNotSupported indicates that the method called is not currently supported by the client.

7373

// TODO: Export this error when launching the transport-agnostic client.

7474

errMethodNotSupported = errors.New("storage: method is not currently supported")

75-

// errMethodNotValid indicates that given HTTP method is not valid.

76-

errMethodNotValid = fmt.Errorf("storage: HTTP method should be one of %v", reflect.ValueOf(signedURLMethods).MapKeys())

75+

// errSignedURLMethodNotValid indicates that given HTTP method is not valid.

76+

errSignedURLMethodNotValid = fmt.Errorf("storage: HTTP method should be one of %v", reflect.ValueOf(signedURLMethods).MapKeys())

7777

)

7878
7979

var userAgent = fmt.Sprintf("gcloud-golang-storage/%s", internal.Version)

@@ -689,7 +689,7 @@ func validateOptions(opts *SignedURLOptions, now time.Time) error {

689689

}

690690

opts.Method = strings.ToUpper(opts.Method)

691691

if _, ok := signedURLMethods[opts.Method]; !ok {

692-

return errMethodNotValid

692+

return errSignedURLMethodNotValid

693693

}

694694

if opts.Expires.IsZero() {

695695

return errors.New("storage: missing required expires option")

Original file line numberDiff line numberDiff line change

@@ -540,15 +540,15 @@ func TestSignedURL_MissingOptions(t *testing.T) {

540540

GoogleAccessID: "access_id",

541541

PrivateKey: pk,

542542

},

543-

errMethodNotValid.Error(),

543+

errSignedURLMethodNotValid.Error(),

544544

},

545545

{

546546

&SignedURLOptions{

547547

GoogleAccessID: "access_id",

548548

PrivateKey: pk,

549549

Method: "getMethod", // wrong method name

550550

},

551-

errMethodNotValid.Error(),

551+

errSignedURLMethodNotValid.Error(),

552552

},

553553

{

554554

&SignedURLOptions{

@@ -563,7 +563,7 @@ func TestSignedURL_MissingOptions(t *testing.T) {

563563

GoogleAccessID: "access_id",

564564

SignBytes: func(b []byte) ([]byte, error) { return b, nil },

565565

},

566-

errMethodNotValid.Error(),

566+

errSignedURLMethodNotValid.Error(),

567567

},

568568

{

569569

&SignedURLOptions{

@@ -611,7 +611,7 @@ func TestSignedURL_MissingOptions(t *testing.T) {

611611

Expires: expires,

612612

Scheme: SigningSchemeV4,

613613

},

614-

errMethodNotValid.Error(),

614+

errSignedURLMethodNotValid.Error(),

615615

},

616616

{

617617

&SignedURLOptions{