Update to latest internal module (#21872)

* Update to latest internal module

Used NonRetriableError from internal.

* update perf test
This commit is contained in:
Joel Hendrix 2023-11-03 07:12:14 -07:00 коммит произвёл GitHub
Родитель f0b1058603
Коммит 637c5ed84d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 45 добавлений и 66 удалений

Просмотреть файл

@ -14,8 +14,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
)
// TokenCredential is a fake credential that implements the azcore.TokenCredential interface.
@ -26,13 +26,13 @@ type TokenCredential struct {
// SetError sets the specified error to be returned from GetToken().
// Use this to simulate an error during authentication.
func (t *TokenCredential) SetError(err error) {
t.err = shared.NonRetriableError(err)
t.err = errorinfo.NonRetriableError(err)
}
// GetToken implements the azcore.TokenCredential for the TokenCredential type.
func (t *TokenCredential) GetToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
if t.err != nil {
return azcore.AccessToken{}, shared.NonRetriableError(t.err)
return azcore.AccessToken{}, errorinfo.NonRetriableError(t.err)
}
return azcore.AccessToken{Token: "fake_token", ExpiresOn: time.Now().Add(24 * time.Hour)}, nil
}

Просмотреть файл

@ -19,6 +19,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
)
// Responder represents a scalar response.
@ -68,14 +69,14 @@ type ErrorResponder struct {
// SetError sets the specified error to be returned.
// Use SetResponseError for returning an *azcore.ResponseError.
func (e *ErrorResponder) SetError(err error) {
e.err = shared.NonRetriableError(err)
e.err = errorinfo.NonRetriableError(err)
}
// SetResponseError sets an *azcore.ResponseError with the specified values to be returned.
// - errorCode is the value to be used in the ResponseError.Code field
// - httpStatus is the HTTP status code
func (e *ErrorResponder) SetResponseError(httpStatus int, errorCode string) {
e.err = shared.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus})
e.err = errorinfo.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus})
}
// GetError returns the error for this responder.
@ -90,11 +91,11 @@ func (e ErrorResponder) GetError(req *http.Request) error {
// fix up the raw response
rawResp, err := newErrorResponse(respErr.StatusCode, respErr.ErrorCode, req)
if err != nil {
return shared.NonRetriableError(err)
return errorinfo.NonRetriableError(err)
}
respErr.RawResponse = rawResp
}
return shared.NonRetriableError(e.err)
return errorinfo.NonRetriableError(e.err)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -115,13 +116,13 @@ func (p *PagerResponder[T]) AddPage(httpStatus int, page T, o *AddPageOptions) {
// AddError adds an error to the sequence of responses.
// The error is returned from the call to runtime.Pager[T].NextPage().
func (p *PagerResponder[T]) AddError(err error) {
p.pages = append(p.pages, shared.NonRetriableError(err))
p.pages = append(p.pages, errorinfo.NonRetriableError(err))
}
// AddResponseError adds an *azcore.ResponseError to the sequence of responses.
// The error is returned from the call to runtime.Pager[T].NextPage().
func (p *PagerResponder[T]) AddResponseError(httpStatus int, errorCode string) {
p.pages = append(p.pages, shared.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus}))
p.pages = append(p.pages, errorinfo.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus}))
}
// AddPageOptions contains the optional values for PagerResponder[T].AddPage.
@ -133,7 +134,7 @@ type AddPageOptions struct {
// This function is called by the fake server internals.
func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
if len(p.pages) == 0 {
return nil, shared.NonRetriableError(errors.New("fake paged response is empty"))
return nil, errorinfo.NonRetriableError(errors.New("fake paged response is empty"))
}
page := p.pages[0]
@ -143,7 +144,7 @@ func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
if ok {
body, err := json.Marshal(pageT.entry)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
content := ResponseContent{
HTTPStatus: pageT.httpStatus,
@ -151,7 +152,7 @@ func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
}
resp, err := NewResponse(content, req)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
return SetResponseBody(resp, body, shared.ContentTypeAppJSON), nil
}
@ -162,11 +163,11 @@ func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
// fix up the raw response
rawResp, err := newErrorResponse(respErr.StatusCode, respErr.ErrorCode, req)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
respErr.RawResponse = rawResp
}
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
// More returns true if there are more responses for consumption.
@ -273,7 +274,7 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
p.nonTermResps = p.nonTermResps[1:]
if resp.err != nil {
return nil, shared.NonRetriableError(resp.err)
return nil, errorinfo.NonRetriableError(resp.err)
}
content := ResponseContent{
@ -282,7 +283,7 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
}
httpResp, err := NewResponse(content, req)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
httpResp.Header.Set(shared.HeaderFakePollerStatus, resp.status)
@ -297,15 +298,15 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
respErr := p.err
rawResp, err := newErrorResponse(p.err.StatusCode, p.err.ErrorCode, req)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
respErr.RawResponse = rawResp
p.err = nil
return nil, shared.NonRetriableError(respErr)
return nil, errorinfo.NonRetriableError(respErr)
} else if p.res != nil {
body, err := json.Marshal(*p.res)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
p.res = nil
content := ResponseContent{
@ -314,13 +315,13 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
}
resp, err := NewResponse(content, req)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
httpResp := SetResponseBody(resp, body, shared.ContentTypeAppJSON)
httpResp.Header.Set(shared.HeaderFakePollerStatus, "Succeeded")
return httpResp, nil
} else {
return nil, shared.NonRetriableError(errors.New("fake poller response is emtpy"))
return nil, errorinfo.NonRetriableError(errors.New("fake poller response is emtpy"))
}
}

Просмотреть файл

@ -19,6 +19,7 @@ import (
azexported "github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
fakepoller "github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/pollers/fake"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
)
// ResponseContent is used when building the *http.Response.
@ -64,7 +65,7 @@ func MarshalResponseAsByteArray(content ResponseContent, body []byte, format aze
func MarshalResponseAsJSON(content ResponseContent, v any, req *http.Request) (*http.Response, error) {
body, err := json.Marshal(v)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
resp, err := exported.NewResponse(content, req)
if err != nil {
@ -94,7 +95,7 @@ func MarshalResponseAsText(content ResponseContent, body *string, req *http.Requ
func MarshalResponseAsXML(content ResponseContent, v any, req *http.Request) (*http.Response, error) {
body, err := xml.Marshal(v)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
resp, err := exported.NewResponse(content, req)
if err != nil {
@ -112,12 +113,12 @@ func UnmarshalRequestAsByteArray(req *http.Request, format azexported.Base64Enco
}
body, err := io.ReadAll(req.Body)
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
req.Body.Close()
var val []byte
if err := azexported.DecodeByteArray(string(body), &val, format); err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
return val, nil
}
@ -131,11 +132,11 @@ func UnmarshalRequestAsJSON[T any](req *http.Request) (T, error) {
}
body, err := io.ReadAll(req.Body)
if err != nil {
return tt, shared.NonRetriableError(err)
return tt, errorinfo.NonRetriableError(err)
}
req.Body.Close()
if err = json.Unmarshal(body, &tt); err != nil {
err = shared.NonRetriableError(err)
err = errorinfo.NonRetriableError(err)
}
return tt, err
}
@ -148,7 +149,7 @@ func UnmarshalRequestAsText(req *http.Request) (string, error) {
}
body, err := io.ReadAll(req.Body)
if err != nil {
return "", shared.NonRetriableError(err)
return "", errorinfo.NonRetriableError(err)
}
req.Body.Close()
return string(body), nil
@ -163,11 +164,11 @@ func UnmarshalRequestAsXML[T any](req *http.Request) (T, error) {
}
body, err := io.ReadAll(req.Body)
if err != nil {
return tt, shared.NonRetriableError(err)
return tt, errorinfo.NonRetriableError(err)
}
req.Body.Close()
if err = xml.Unmarshal(body, &tt); err != nil {
err = shared.NonRetriableError(err)
err = errorinfo.NonRetriableError(err)
}
return tt, err
}

Просмотреть файл

@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/azcore
go 1.18
require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.17.0
)

Просмотреть файл

@ -1,5 +1,5 @@
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0 h1:TuEMD+E+1aTjjLICGQOW6vLe8UWES7kopac9mUXL56Y=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
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=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

Просмотреть файл

@ -14,8 +14,6 @@ import (
"regexp"
"strconv"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
)
// NOTE: when adding a new context key type, it likely needs to be
@ -131,26 +129,3 @@ func (c *ContextWithDeniedValues) Value(key any) any {
return c.Context.Value(key)
}
}
// NonRetriableError marks the specified error as non-retriable.
func NonRetriableError(err error) error {
return &nonRetriableError{err}
}
type nonRetriableError struct {
error
}
func (p *nonRetriableError) Error() string {
return p.error.Error()
}
func (*nonRetriableError) NonRetriable() {
// marker method
}
func (p *nonRetriableError) Unwrap() error {
return p.error
}
var _ errorinfo.NonRetriable = (*nonRetriableError)(nil)

Просмотреть файл

@ -12,6 +12,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
"github.com/Azure/azure-sdk-for-go/sdk/internal/temporal"
)
@ -90,7 +91,7 @@ func (b *BearerTokenPolicy) Do(req *policy.Request) (*http.Response, error) {
err = b.authenticateAndAuthorize(req)(policy.TokenRequestOptions{Scopes: b.scopes})
}
if err != nil {
return nil, shared.NonRetriableError(err)
return nil, errorinfo.NonRetriableError(err)
}
res, err := req.Next()
@ -107,14 +108,14 @@ func (b *BearerTokenPolicy) Do(req *policy.Request) (*http.Response, error) {
}
}
if err != nil {
err = shared.NonRetriableError(err)
err = errorinfo.NonRetriableError(err)
}
return res, err
}
func checkHTTPSForAuth(req *policy.Request) error {
if strings.ToLower(req.Raw().URL.Scheme) != "https" {
return shared.NonRetriableError(errors.New("authenticated requests are not permitted for non TLS protected (https) endpoints"))
return errorinfo.NonRetriableError(errors.New("authenticated requests are not permitted for non TLS protected (https) endpoints"))
}
return nil
}

Просмотреть файл

@ -206,7 +206,7 @@ func TestBearerTokenPolicy_AuthZHandlerErrors(t *testing.T) {
// the policy should propagate the handler's errors, wrapping them to make them nonretriable, if necessary
fatalErr := errors.New("something went wrong")
var nre errorinfo.NonRetriable
for i, e := range []error{fatalErr, shared.NonRetriableError(fatalErr)} {
for i, e := range []error{fatalErr, errorinfo.NonRetriableError(fatalErr)} {
handler.onReqErr = e
_, err = pl.Do(req)
require.ErrorAs(t, err, &nre)

Просмотреть файл

@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/pollers/fake"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
"github.com/Azure/azure-sdk-for-go/sdk/internal/poller"
"github.com/stretchr/testify/require"
@ -399,7 +400,7 @@ func TestOpPollerWithWidgetFinalGetError(t *testing.T) {
srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(`{"status": "Succeeded"}`)))
// PUT and PATCH state that a final GET will happen
// the first attempt at a final GET returns an error
srv.AppendError(shared.NonRetriableError(errors.New("failed attempt")))
srv.AppendError(errorinfo.NonRetriableError(errors.New("failed attempt")))
srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(`{"size": 2}`)))
defer close()

2
sdk/azcore/testdata/perf/go.mod поставляемый
Просмотреть файл

@ -4,7 +4,7 @@ go 1.18
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0
)
require (

4
sdk/azcore/testdata/perf/go.sum поставляемый
Просмотреть файл

@ -1,5 +1,5 @@
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0 h1:TuEMD+E+1aTjjLICGQOW6vLe8UWES7kopac9mUXL56Y=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=