Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update azblob with the latest azcore #16784

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Release History

## 0.2.1 (Unreleased)
## 0.3.0 (Unreleased)

### Features Added

### Breaking Changes
* Updated to latest `azcore`. Public surface area is unchanged.

### Bugs Fixed

Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azblob/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/Azure/azure-sdk-for-go/sdk/storage/azblob
go 1.16

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dnaeon/go-vcr v1.2.0 // indirect
github.com/stretchr/testify v1.7.0
Expand Down
8 changes: 4 additions & 4 deletions sdk/storage/azblob/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0 h1:8wVJL0HUP5yDFXvotdewORTw7Yu88JbreWN/mobSvsQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm2CYY3CK4spn5OmUIiQtk=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azblob/zc_blob_lease_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package azblob
import (
"context"
"errors"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/internal/uuid"
)
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/azblob/zc_block_blob_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package azblob

import (
"context"
"io"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"io"
)

const (
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azblob/zc_container_lease_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package azblob
import (
"context"
"errors"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/internal/uuid"
)
Expand Down
5 changes: 3 additions & 2 deletions sdk/storage/azblob/zc_page_blob_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package azblob

import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"io"
"net/url"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
)

const (
Expand Down
40 changes: 25 additions & 15 deletions sdk/storage/azblob/zc_storage_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"sort"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
)

// InternalError is an internal error type that all errors get wrapped in.
Expand Down Expand Up @@ -50,7 +52,6 @@ func (e *InternalError) As(target interface{}) bool {
// TL;DR: This implements xml.Unmarshaler, and when the original StorageError is substituted, this unmarshaler kicks in.
// This handles the description and details. defunkifyStorageError handles the response, cause, and service code.
type StorageError struct {
raw string
response *http.Response
description string

Expand All @@ -59,8 +60,9 @@ type StorageError struct {
}

func handleError(err error) error {
if err, ok := err.(ResponseError); ok {
return &InternalError{defunkifyStorageError(err)}
var respErr *azcore.ResponseError
if errors.As(err, &respErr) {
return &InternalError{responseErrorToStorageError(respErr)}
}

if err != nil {
Expand All @@ -70,23 +72,31 @@ func handleError(err error) error {
return nil
}

// defunkifyStorageError is a function that takes the "funky" ResponseError and reduces it to a storageError.
func defunkifyStorageError(responseError ResponseError) error {
if err, ok := responseError.Unwrap().(*StorageError); ok {
// errors.Unwrap(responseError.Unwrap())

err.response = responseError.RawResponse()
// converts an *azcore.ResponseError to a *StorageError, or if that fails, a *InternalError
func responseErrorToStorageError(responseError *azcore.ResponseError) error {
var storageError StorageError
body, err := runtime.Payload(responseError.RawResponse)
if err != nil {
goto Default
}
if len(body) > 0 {
if err := xml.Unmarshal(body, &storageError); err != nil {
goto Default
}
}

err.ErrorCode = StorageErrorCode(responseError.RawResponse().Header.Get("x-ms-error-code"))
storageError.response = responseError.RawResponse

if code, ok := err.details["Code"]; ok {
err.ErrorCode = StorageErrorCode(code)
delete(err.details, "Code")
}
storageError.ErrorCode = StorageErrorCode(responseError.RawResponse.Header.Get("x-ms-error-code"))

return err
if code, ok := storageError.details["Code"]; ok {
storageError.ErrorCode = StorageErrorCode(code)
delete(storageError.details, "Code")
}

return &storageError

Default:
return &InternalError{
cause: responseError,
}
Expand Down
9 changes: 5 additions & 4 deletions sdk/storage/azblob/zt_blob_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"bytes"
"crypto/md5"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"net/url"
"strconv"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal"
"github.com/stretchr/testify/assert"
)

//nolint
Expand Down Expand Up @@ -2099,7 +2100,7 @@ func validateBlobDeleted(_assert *assert.Assertions, bbClient BlobClient) {
_assert.NotNil(err)

var storageError *StorageError
_assert.Equal(errors.As(err, &storageError), true)
_assert.Equal(true, errors.As(err, &storageError))
_assert.Equal(storageError.ErrorCode, StorageErrorCodeBlobNotFound)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/zt_service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package azblob

import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/assert"
"time"
)

func (s *azblobTestSuite) TestGetAccountInfo() {
Expand Down
13 changes: 7 additions & 6 deletions sdk/storage/azblob/zt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
testframework "github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"io"
"io/ioutil"
"log"
Expand All @@ -26,7 +21,12 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
testframework "github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

type azblobTestSuite struct {
Expand Down Expand Up @@ -533,7 +533,8 @@ func blockIDIntToBase64(blockID int) string {
func validateStorageError(_assert *assert.Assertions, err error, code StorageErrorCode) {
_assert.NotNil(err)
var storageError *StorageError
_assert.Equal(errors.As(err, &storageError), true)
// TOOD: this should really be require.Equal so that if it fails we don't try the next line which will panic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, I change these to require (which you're correct we should be using over assert) in my PR to move to the new test proxy

_assert.Equal(true, errors.As(err, &storageError))

_assert.Equal(storageError.ErrorCode, code)
}
Expand Down
66 changes: 7 additions & 59 deletions sdk/storage/azblob/zz_generated_appendblob_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading