Skip to content

Commit

Permalink
Merge pull request #1117 from seanzatzdev-amazon/UNIT-TESTS
Browse files Browse the repository at this point in the history
Add unit test - subpath pattern, repeated elements
  • Loading branch information
k8s-ci-robot authored Sep 1, 2023
2 parents 5e44f89 + b7c699a commit 00ba084
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,78 @@ func TestCreateVolume(t *testing.T) {
mockCtl.Finish()
},
},
{
name: "Success: Normal flow with a valid directory structure set, using repeated elements (uses PVC Name in subpath pattern multiple times)",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)

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

pvcName := "foo"
directoryCreated := fmt.Sprintf("/%s/%s", pvcName, pvcName)

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: "${.PVC.name}/${.PVC.name}",
PvcName: pvcName,
},
}

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().ListAccessPoints(gomock.Eq(ctx), gomock.Any()).Return(nil, 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 !verifyPathWhenUUIDIncluded(accessPointOpts.DirectoryPath, directoryCreated) {
t.Fatalf("Root directory mismatch. Expected: %v (with UID appended), actual: %v",
directoryCreated,
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 00ba084

Please sign in to comment.