Skip to content

Commit 9954d50

Browse files
committed
Adding unit test
1 parent cbbdfa0 commit 9954d50

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

pkg/controller/controller_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,64 @@ func createMockServer(t *testing.T) (*gomock.Controller,
7070
return mockController, drv, identityServer, controllerServer, csiConn, nil
7171
}
7272

73+
func TestGetPluginName(t *testing.T) {
74+
test := struct {
75+
name string
76+
output []*csi.GetPluginInfoResponse
77+
}{
78+
name: "success",
79+
output: []*csi.GetPluginInfoResponse{
80+
{
81+
Name: "csi/example-1",
82+
VendorVersion: "0.2.0",
83+
Manifest: map[string]string{
84+
"hello": "world",
85+
},
86+
},
87+
{
88+
Name: "csi/example-2",
89+
VendorVersion: "0.2.0",
90+
Manifest: map[string]string{
91+
"hello": "world",
92+
},
93+
},
94+
},
95+
}
96+
97+
mockController, driver, identityServer, _, csiConn, err := createMockServer(t)
98+
if err != nil {
99+
t.Fatal(err)
100+
}
101+
defer mockController.Finish()
102+
defer driver.Stop()
103+
104+
in := &csi.GetPluginInfoRequest{}
105+
out := test.output[0]
106+
107+
identityServer.EXPECT().GetPluginInfo(gomock.Any(), in).Return(out, nil).Times(1)
108+
oldName, err := getDriverName(csiConn.conn, timeout)
109+
if err != nil {
110+
t.Errorf("test %q: Failed to get driver's name", test.name)
111+
}
112+
if oldName != test.output[0].Name {
113+
t.Errorf("test %s: failed, expected %s got %s", test.name, test.output[0].Name, oldName)
114+
}
115+
116+
out = test.output[1]
117+
identityServer.EXPECT().GetPluginInfo(gomock.Any(), in).Return(out, nil).Times(1)
118+
newName, err := getDriverName(csiConn.conn, timeout)
119+
if err != nil {
120+
t.Errorf("test %s: Failed to get driver's name", test.name)
121+
}
122+
if newName != test.output[1].Name {
123+
t.Errorf("test %q: failed, expected %s got %s", test.name, test.output[1].Name, newName)
124+
}
125+
126+
if oldName == newName {
127+
t.Errorf("test: %s failed, driver's names should not match", test.name)
128+
}
129+
}
130+
73131
func TestSupportsControllerCreateVolume(t *testing.T) {
74132

75133
tests := []struct {

0 commit comments

Comments
 (0)