Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Sep 18, 2024
1 parent f09bc3d commit 0a2a185
Show file tree
Hide file tree
Showing 8 changed files with 1,213 additions and 1,213 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ require (
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.55.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
k8s.io/api v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
golang.org/x/sync v0.7.0
sigs.k8s.io/controller-runtime v0.18.4
)

Expand Down
322 changes: 161 additions & 161 deletions pkg/common/azureerrors/azureerrors_test.go
Original file line number Diff line number Diff line change
@@ -1,161 +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)
}
})
}
}
/*
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)
}
})
}
}
Loading

0 comments on commit 0a2a185

Please sign in to comment.