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 3a3e2c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 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
33 changes: 24 additions & 9 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 @@ -120,9 +123,6 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
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)
}

mockCtl.Finish()
},
Expand Down Expand Up @@ -170,6 +170,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 +197,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

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

Expand All @@ -212,6 +215,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 +243,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

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

Expand All @@ -255,6 +261,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 +289,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &BrokenOsClient{},
}
Expand All @@ -299,6 +308,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 +337,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

dProv := DirectoryProvisioner{
cloud: nil,
cloud: mockCloud,
mounter: mockMounter,
osClient: &FakeOsClient{},
}
Expand All @@ -344,6 +356,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 +384,7 @@ func TestDirectoryProvisioner_Provision(t *testing.T) {
}

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