Skip to content

Commit

Permalink
fix(storage): return the appropriate error for method not supported (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennaEpp authored Jan 8, 2025
1 parent d851c5d commit 56d704e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion storage/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ func (c *httpStorageClient) RewriteObject(ctx context.Context, req *rewriteObjec

// NewMultiRangeDownloader is not supported by http client.
func (c *httpStorageClient) NewMultiRangeDownloader(ctx context.Context, params *newMultiRangeDownloaderParams, opts ...storageOption) (mr *MultiRangeDownloader, err error) {
return nil, errMethodNotValid
return nil, errMethodNotSupported
}

func (c *httpStorageClient) NewRangeReader(ctx context.Context, params *newRangeReaderParams, opts ...storageOption) (r *Reader, err error) {
Expand Down
6 changes: 3 additions & 3 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ var (
// errMethodNotSupported indicates that the method called is not currently supported by the client.
// TODO: Export this error when launching the transport-agnostic client.
errMethodNotSupported = errors.New("storage: method is not currently supported")
// errMethodNotValid indicates that given HTTP method is not valid.
errMethodNotValid = fmt.Errorf("storage: HTTP method should be one of %v", reflect.ValueOf(signedURLMethods).MapKeys())
// errSignedURLMethodNotValid indicates that given HTTP method is not valid.
errSignedURLMethodNotValid = fmt.Errorf("storage: HTTP method should be one of %v", reflect.ValueOf(signedURLMethods).MapKeys())
)

var userAgent = fmt.Sprintf("gcloud-golang-storage/%s", internal.Version)
Expand Down Expand Up @@ -689,7 +689,7 @@ func validateOptions(opts *SignedURLOptions, now time.Time) error {
}
opts.Method = strings.ToUpper(opts.Method)
if _, ok := signedURLMethods[opts.Method]; !ok {
return errMethodNotValid
return errSignedURLMethodNotValid
}
if opts.Expires.IsZero() {
return errors.New("storage: missing required expires option")
Expand Down
8 changes: 4 additions & 4 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ func TestSignedURL_MissingOptions(t *testing.T) {
GoogleAccessID: "access_id",
PrivateKey: pk,
},
errMethodNotValid.Error(),
errSignedURLMethodNotValid.Error(),
},
{
&SignedURLOptions{
GoogleAccessID: "access_id",
PrivateKey: pk,
Method: "getMethod", // wrong method name
},
errMethodNotValid.Error(),
errSignedURLMethodNotValid.Error(),
},
{
&SignedURLOptions{
Expand All @@ -563,7 +563,7 @@ func TestSignedURL_MissingOptions(t *testing.T) {
GoogleAccessID: "access_id",
SignBytes: func(b []byte) ([]byte, error) { return b, nil },
},
errMethodNotValid.Error(),
errSignedURLMethodNotValid.Error(),
},
{
&SignedURLOptions{
Expand Down Expand Up @@ -611,7 +611,7 @@ func TestSignedURL_MissingOptions(t *testing.T) {
Expires: expires,
Scheme: SigningSchemeV4,
},
errMethodNotValid.Error(),
errSignedURLMethodNotValid.Error(),
},
{
&SignedURLOptions{
Expand Down

0 comments on commit 56d704e

Please sign in to comment.