Skip to content

Commit 2d3abc1

Browse files
committed
fix ut
1 parent 3bf7460 commit 2d3abc1

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pkg/blob/azure_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"reflect"
2424
"strings"
25+
"syscall"
2526
"testing"
2627

2728
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network"
@@ -82,37 +83,35 @@ users:
8283
nodeID string
8384
userAgent string
8485
allowEmptyCloudConfig bool
85-
expectedErrorMessage string
86-
expectError bool
86+
expectedErr error
8787
}{
8888
{
8989
desc: "[success] out of cluster, no kubeconfig, no credential file",
9090
nodeID: "",
9191
allowEmptyCloudConfig: true,
92-
expectError: false,
92+
expectedErr: nil,
9393
},
9494
{
9595
desc: "[failure][disallowEmptyCloudConfig] out of cluster, no kubeconfig, no credential file",
9696
nodeID: "",
9797
allowEmptyCloudConfig: false,
98-
expectError: true,
99-
expectedErrorMessage: "no cloud config provided, error: open /etc/kubernetes/azure.json: no such file or directory",
98+
expectedErr: syscall.ENOENT,
10099
},
101100
{
102101
desc: "[success] out of cluster & in cluster, specify a fake kubeconfig, no credential file",
103102
createFakeKubeConfig: true,
104103
kubeconfig: fakeKubeConfig,
105104
nodeID: "",
106105
allowEmptyCloudConfig: true,
107-
expectError: false,
106+
expectedErr: nil,
108107
},
109108
{
110109
desc: "[success] out of cluster & in cluster, no kubeconfig, a fake credential file",
111110
createFakeCredFile: true,
112111
nodeID: "",
113112
userAgent: "useragent",
114113
allowEmptyCloudConfig: true,
115-
expectError: false,
114+
expectedErr: nil,
116115
},
117116
}
118117

@@ -159,10 +158,7 @@ users:
159158
}
160159

161160
cloud, err := GetCloudProvider(context.Background(), kubeClient, test.nodeID, "", "", test.userAgent, test.allowEmptyCloudConfig)
162-
assert.Equal(t, test.expectError, err != nil)
163-
if test.expectError {
164-
assert.Equal(t, test.expectedErrorMessage, err.Error())
165-
}
161+
assert.ErrorIs(t, err, test.expectedErr)
166162

167163
if cloud == nil {
168164
t.Errorf("return value of getCloudProvider should not be nil even there is error")

0 commit comments

Comments
 (0)