-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add trafficManagerProfile controller (#193)
- Loading branch information
1 parent
5740632
commit b4ff5d7
Showing
15 changed files
with
1,338 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
// Package azureerrors defines shared azure error util functions. | ||
package azureerrors | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
) | ||
|
||
// IsNotFound returns true if the error is a http 404 error returned by the azure server. | ||
func IsNotFound(err error) bool { | ||
var responseError *azcore.ResponseError | ||
return errors.As(err, &responseError) && responseError.StatusCode == http.StatusNotFound | ||
} | ||
|
||
// IsClientError returns true if the error is a client error (400-499) returned by the azure server. | ||
func IsClientError(err error) bool { | ||
var responseError *azcore.ResponseError | ||
return errors.As(err, &responseError) && | ||
responseError.StatusCode >= http.StatusBadRequest && responseError.StatusCode < http.StatusInternalServerError | ||
} | ||
|
||
// IsConflict determines if the error is a http 409 error returned by the azure server. | ||
func IsConflict(err error) bool { | ||
var responseError *azcore.ResponseError | ||
return errors.As(err, &responseError) && responseError.StatusCode == http.StatusConflict | ||
} | ||
|
||
// IsThrottled determines if the error is a http 429 error returned by the azure server. | ||
func IsThrottled(err error) bool { | ||
var responseError *azcore.ResponseError | ||
return errors.As(err, &responseError) && responseError.StatusCode == http.StatusTooManyRequests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package azureerrors | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
) | ||
|
||
func TestIsNotFound(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "not azure error", | ||
err: errors.New("not azure error"), | ||
want: false, | ||
}, | ||
{ | ||
name: "bad request error", | ||
err: &azcore.ResponseError{StatusCode: 400}, | ||
want: false, | ||
}, | ||
{ | ||
name: "not found error", | ||
err: &azcore.ResponseError{StatusCode: 404}, | ||
want: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := IsNotFound(tc.err) | ||
if got != tc.want { | ||
t.Errorf("IsNotFound() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsClientError(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "not azure error", | ||
err: errors.New("not azure error"), | ||
want: false, | ||
}, | ||
{ | ||
name: "bad request error", | ||
err: &azcore.ResponseError{StatusCode: 400}, | ||
want: true, | ||
}, | ||
{ | ||
name: "not found error", | ||
err: &azcore.ResponseError{StatusCode: 404}, | ||
want: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := IsClientError(tc.err) | ||
if got != tc.want { | ||
t.Errorf("IsClientError() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsConflict(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "not azure error", | ||
err: errors.New("not azure error"), | ||
want: false, | ||
}, | ||
{ | ||
name: "bad request error", | ||
err: &azcore.ResponseError{StatusCode: 400}, | ||
want: false, | ||
}, | ||
{ | ||
name: "conflict error", | ||
err: &azcore.ResponseError{StatusCode: 409}, | ||
want: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := IsConflict(tc.err) | ||
if got != tc.want { | ||
t.Errorf("IsConflict() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsThrottled(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
err error | ||
want bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "not azure error", | ||
err: errors.New("not azure error"), | ||
want: false, | ||
}, | ||
{ | ||
name: "bad request error", | ||
err: &azcore.ResponseError{StatusCode: 400}, | ||
want: false, | ||
}, | ||
{ | ||
name: "throttled error", | ||
err: &azcore.ResponseError{StatusCode: 429}, | ||
want: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := IsThrottled(tc.err) | ||
if got != tc.want { | ||
t.Errorf("IsConflict() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.