Skip to content

Commit

Permalink
Adding extra test case to cover the basePath = '/' case
Browse files Browse the repository at this point in the history
This has come up in several issues on the repo where people set
basePath to `/` and this leads to problems. This proves this PR
resolves that issue and doesn't lead to the problems of a path like
`//`
  • Loading branch information
jonathanrainer committed Sep 30, 2022
1 parent 78eb773 commit 0617278
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"context"
"errors"
"fmt"
"regexp"
"testing"

"github.com/google/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"regexp"
"testing"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/mock/gomock"

"github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/driver/mocks"
)
Expand Down Expand Up @@ -829,6 +831,75 @@ func TestCreateVolume(t *testing.T) {
mockCtl.Finish()
},
},
{
name: "Success: Normal flow with an empty subPath Pattern, and basePath set to /",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)

driver := &Driver{
endpoint: endpoint,
cloud: mockCloud,
gidAllocator: NewGidAllocator(),
tags: parseTagsFromStr(""),
}

req := &csi.CreateVolumeRequest{
Name: volumeName,
VolumeCapabilities: []*csi.VolumeCapability{
stdVolCap,
},
CapacityRange: &csi.CapacityRange{
RequiredBytes: capacityRange,
},
Parameters: map[string]string{
ProvisioningMode: "efs-ap",
FsId: fsId,
GidMin: "1000",
GidMax: "2000",
DirectoryPerms: "777",
SubPathPattern: "",
BasePath: "/",
EnsureUniqueDirectory: "false",
},
}

ctx := context.Background()
fileSystem := &cloud.FileSystem{
FileSystemId: fsId,
}
accessPoint := &cloud.AccessPoint{
AccessPointId: apId,
FileSystemId: fsId,
}
mockCloud.EXPECT().DescribeFileSystem(gomock.Eq(ctx), gomock.Any()).Return(fileSystem, nil)

mockCloud.EXPECT().CreateAccessPoint(gomock.Eq(ctx), gomock.Any(), gomock.Any()).Return(accessPoint, nil).
Do(func(ctx context.Context, volumeName string, accessPointOpts *cloud.AccessPointOptions) {
if accessPointOpts.DirectoryPath != "/" {
t.Fatalf("Root directory mismatch. Expected: %v, actual: %v",
"/",
accessPointOpts.DirectoryPath)
}
})

res, err := driver.CreateVolume(ctx, req)

if err != nil {
t.Fatalf("CreateVolume failed: %v", err)
}

if res.Volume == nil {
t.Fatal("Volume is nil")
}

if res.Volume.VolumeId != volumeId {
t.Fatalf("Volume Id mismatched. Expected: %v, Actual: %v", volumeId, res.Volume.VolumeId)
}

mockCtl.Finish()
},
},
{
name: "Fail: Volume name missing",
testFunc: func(t *testing.T) {
Expand Down

0 comments on commit 0617278

Please sign in to comment.