Skip to content

Commit

Permalink
fix unit-tests for dir-mode provsioning
Browse files Browse the repository at this point in the history
  • Loading branch information
mpatlasov committed Nov 12, 2024
1 parent 9f4bdb2 commit 8002947
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 57 deletions.
47 changes: 0 additions & 47 deletions pkg/driver/provisioner_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,53 +89,6 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}
},
},
{
name: "Fail: Return error for failed x-account mount",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockMounter := mocks.NewMockMounter(mockCtl)

ctx := context.Background()

fakeRoleArn := "arn:aws:iam::1234567890:role/EFSCrossAccountRole"
req := &csi.CreateVolumeRequest{
Name: volumeName,
VolumeCapabilities: []*csi.VolumeCapability{
stdVolCap,
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: capacityRange,
},
Parameters: map[string]string{
ProvisioningMode: DirectoryMode,
FsId: fsId,
GidMin: "1000",
GidMax: "2000",
DirectoryPerms: "777",
Uid: "1000",
Gid: "1000",
},
Secrets: map[string]string{
RoleArn: fakeRoleArn,
},
}

dProv := DirectoryProvisioner{
BaseProvisioner: BaseProvisioner{
mounter: mockMounter,
},
}

_, err := dProv.Provision(ctx, req)

if err == nil {
t.Fatal("Expected error but found none")
}
if status.Code(err) != codes.Unauthenticated {
t.Fatalf("Expected unauthenticated error but instead got %v", err)
}
},
},
{
name: "Fail: Return error for empty fsId",
testFunc: func(t *testing.T) {
Expand Down
21 changes: 11 additions & 10 deletions pkg/driver/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"testing"

"github.com/golang/mock/gomock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/driver/mocks"
)
Expand All @@ -14,26 +12,29 @@ func TestProvisioner_GetCloud_NoRoleArnGivesOriginalObjectBack(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)

actualCloud, _, _, _ := getCloud(map[string]string{}, mockCloud)
actualCloud, _, _, err := getCloud(map[string]string{}, mockCloud)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if actualCloud != mockCloud {
t.Fatalf("Expected cloud object to be %v but was %v", mockCloud, actualCloud)
}

mockCtl.Finish()
}

func TestProvisioner_GetCloud_IncorrectRoleArnGivesError(t *testing.T) {
func TestProvisioner_GetCloud_WithRoleArnGivesNewObject(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)

_, _, _, err := getCloud(map[string]string{
RoleArn: "foo",
actualCloud, _, _, err := getCloud(map[string]string{
RoleArn: "arn:aws:iam::1234567890:role/EFSCrossAccountRole",
}, mockCloud)
if err == nil {
t.Fatalf("Expected error but none was returned")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if status.Code(err) != codes.Unauthenticated {
t.Fatalf("Expected 'Unauthenticated' error but found %v", err)
if actualCloud == mockCloud {
t.Fatalf("Unexpected cloud object: %v", actualCloud)
}

mockCtl.Finish()
Expand Down

0 comments on commit 8002947

Please sign in to comment.