Skip to content

Commit afcbb68

Browse files
committed
Fix unit test to fail with proper final gRPC code
Plain "errors.New" is interpreted as transient error.
1 parent 8536787 commit afcbb68

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pkg/volume/csi/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ go_test(
8888
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
8989
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
9090
"//vendor/github.com/stretchr/testify/assert:go_default_library",
91+
"//vendor/google.golang.org/grpc/codes:go_default_library",
92+
"//vendor/google.golang.org/grpc/status:go_default_library",
9193
"//vendor/k8s.io/klog:go_default_library",
9294
],
9395
)

pkg/volume/csi/csi_block_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ package csi
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
2322
"os"
2423
"path/filepath"
2524
"testing"
2625

26+
"google.golang.org/grpc/codes"
27+
"google.golang.org/grpc/status"
28+
2729
api "k8s.io/api/core/v1"
2830
"k8s.io/api/storage/v1beta1"
2931
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -299,7 +301,7 @@ func TestBlockMapperSetupDeviceError(t *testing.T) {
299301

300302
csiMapper.csiClient = setupClient(t, true)
301303
fClient := csiMapper.csiClient.(*fakeCsiDriverClient)
302-
fClient.nodeClient.SetNextError(errors.New("mock final error"))
304+
fClient.nodeClient.SetNextError(status.Error(codes.InvalidArgument, "mock final error"))
303305

304306
attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), string(nodeName))
305307
attachment := makeTestAttachment(attachID, nodeName, pvName)

0 commit comments

Comments
 (0)