Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrainer committed Jul 15, 2023
1 parent 28ae905 commit d7adf3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ func TestCreateVolume(t *testing.T) {
name: "Success: Normal flow, Directory Provisioning",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(nil)
mockMounter.EXPECT().Unmount(gomock.Any()).Return(nil)

driver := buildDriver(endpoint, nil, "", mockMounter, false, false)
driver := buildDriver(endpoint, mockCloud, "", mockMounter, false, false)

req := &csi.CreateVolumeRequest{
Name: volumeName,
Expand Down
30 changes: 24 additions & 6 deletions pkg/driver/directory_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Success: Check path created is sensible",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(nil)
Expand All @@ -65,7 +68,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &FakeOsClient{},
}
Expand Down Expand Up @@ -170,6 +173,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Fail: Mounter cannot create target directory on node",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(
io.ErrUnexpectedEOF)
Expand All @@ -194,7 +200,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
}

Expand All @@ -212,6 +218,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Fail: Mounter cannot mount into target directory",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(
Expand All @@ -237,7 +246,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
}

Expand All @@ -255,6 +264,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Fail: Could not create directory after mounting root",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(nil)
Expand All @@ -280,7 +292,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &BrokenOsClient{},
}
Expand All @@ -299,6 +311,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Fail: Could not unmount root directory post creation",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(nil)
Expand All @@ -325,7 +340,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &FakeOsClient{},
}
Expand All @@ -344,6 +359,9 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
name: "Fail: Could not delete target directory once unmounted",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockCloud.EXPECT().DescribeFileSystem(gomock.Any(), fsId)

mockMounter := mocks.NewMockMounter(mockCtl)
mockMounter.EXPECT().MakeDir(gomock.Any()).Return(nil)
mockMounter.EXPECT().Mount(fsId, gomock.Any(), "efs", gomock.Any()).Return(nil)
Expand All @@ -369,7 +387,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &BrokenOsClient{},
}
Expand Down

0 comments on commit d7adf3a

Please sign in to comment.