Skip to content

Commit b7c699a

Browse files
seanzatzdev-amazonseanzatzdev
authored andcommitted
Add unit test for subpath pattern w repeated elements
1 parent 5e44f89 commit b7c699a

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

pkg/driver/controller_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,78 @@ func TestCreateVolume(t *testing.T) {
12471247
mockCtl.Finish()
12481248
},
12491249
},
1250+
{
1251+
name: "Success: Normal flow with a valid directory structure set, using repeated elements (uses PVC Name in subpath pattern multiple times)",
1252+
testFunc: func(t *testing.T) {
1253+
mockCtl := gomock.NewController(t)
1254+
mockCloud := mocks.NewMockCloud(mockCtl)
1255+
1256+
driver := &Driver{
1257+
endpoint: endpoint,
1258+
cloud: mockCloud,
1259+
gidAllocator: NewGidAllocator(mockCloud),
1260+
tags: parseTagsFromStr(""),
1261+
}
1262+
1263+
pvcName := "foo"
1264+
directoryCreated := fmt.Sprintf("/%s/%s", pvcName, pvcName)
1265+
1266+
req := &csi.CreateVolumeRequest{
1267+
Name: volumeName,
1268+
VolumeCapabilities: []*csi.VolumeCapability{
1269+
stdVolCap,
1270+
},
1271+
CapacityRange: &csi.CapacityRange{
1272+
RequiredBytes: capacityRange,
1273+
},
1274+
Parameters: map[string]string{
1275+
ProvisioningMode: "efs-ap",
1276+
FsId: fsId,
1277+
GidMin: "1000",
1278+
GidMax: "2000",
1279+
DirectoryPerms: "777",
1280+
SubPathPattern: "${.PVC.name}/${.PVC.name}",
1281+
PvcName: pvcName,
1282+
},
1283+
}
1284+
1285+
ctx := context.Background()
1286+
fileSystem := &cloud.FileSystem{
1287+
FileSystemId: fsId,
1288+
}
1289+
accessPoint := &cloud.AccessPoint{
1290+
AccessPointId: apId,
1291+
FileSystemId: fsId,
1292+
}
1293+
mockCloud.EXPECT().DescribeFileSystem(gomock.Eq(ctx), gomock.Any()).Return(fileSystem, nil)
1294+
mockCloud.EXPECT().ListAccessPoints(gomock.Eq(ctx), gomock.Any()).Return(nil, nil)
1295+
1296+
mockCloud.EXPECT().CreateAccessPoint(gomock.Eq(ctx), gomock.Any(), gomock.Any()).Return(accessPoint, nil).
1297+
Do(func(ctx context.Context, volumeName string, accessPointOpts *cloud.AccessPointOptions) {
1298+
if !verifyPathWhenUUIDIncluded(accessPointOpts.DirectoryPath, directoryCreated) {
1299+
t.Fatalf("Root directory mismatch. Expected: %v (with UID appended), actual: %v",
1300+
directoryCreated,
1301+
accessPointOpts.DirectoryPath)
1302+
}
1303+
})
1304+
1305+
res, err := driver.CreateVolume(ctx, req)
1306+
1307+
if err != nil {
1308+
t.Fatalf("CreateVolume failed: %v", err)
1309+
}
1310+
1311+
if res.Volume == nil {
1312+
t.Fatal("Volume is nil")
1313+
}
1314+
1315+
if res.Volume.VolumeId != volumeId {
1316+
t.Fatalf("Volume Id mismatched. Expected: %v, Actual: %v", volumeId, res.Volume.VolumeId)
1317+
}
1318+
1319+
mockCtl.Finish()
1320+
},
1321+
},
12501322
{
12511323
name: "Fail: Volume name missing",
12521324
testFunc: func(t *testing.T) {

0 commit comments

Comments
 (0)