@@ -15,6 +15,7 @@ import (
15
15
"github.com/stretchr/testify/require"
16
16
"google.golang.org/grpc"
17
17
"google.golang.org/protobuf/proto"
18
+ "google.golang.org/protobuf/types/known/emptypb"
18
19
)
19
20
20
21
func TestCreateNvmeController (t * testing.T ) {
@@ -102,3 +103,73 @@ func TestCreateNvmeController(t *testing.T) {
102
103
})
103
104
}
104
105
}
106
+
107
+ func TestDeleteNvmeController (t * testing.T ) {
108
+ testControllerName := "remotenvme0"
109
+ testRequest := & pb.DeleteNvmeRemoteControllerRequest {
110
+ Name : testControllerName ,
111
+ AllowMissing : true ,
112
+ }
113
+ tests := map [string ]struct {
114
+ giveClientErr error
115
+ giveConnectorErr error
116
+ wantErr error
117
+ wantRequest * pb.DeleteNvmeRemoteControllerRequest
118
+ wantConnClosed bool
119
+ }{
120
+ "successful call" : {
121
+ giveConnectorErr : nil ,
122
+ giveClientErr : nil ,
123
+ wantErr : nil ,
124
+ wantRequest : proto .Clone (testRequest ).(* pb.DeleteNvmeRemoteControllerRequest ),
125
+ wantConnClosed : true ,
126
+ },
127
+ "client err" : {
128
+ giveConnectorErr : nil ,
129
+ giveClientErr : errors .New ("Some client error" ),
130
+ wantErr : errors .New ("Some client error" ),
131
+ wantRequest : proto .Clone (testRequest ).(* pb.DeleteNvmeRemoteControllerRequest ),
132
+ wantConnClosed : true ,
133
+ },
134
+ "connector err" : {
135
+ giveConnectorErr : errors .New ("Some conn error" ),
136
+ giveClientErr : nil ,
137
+ wantErr : errors .New ("Some conn error" ),
138
+ wantRequest : nil ,
139
+ wantConnClosed : false ,
140
+ },
141
+ }
142
+
143
+ for testName , tt := range tests {
144
+ t .Run (testName , func (t * testing.T ) {
145
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
146
+ defer cancel ()
147
+
148
+ mockClient := mocks .NewNvmeRemoteControllerServiceClient (t )
149
+ if tt .wantRequest != nil {
150
+ mockClient .EXPECT ().DeleteNvmeRemoteController (ctx , tt .wantRequest ).
151
+ Return (& emptypb.Empty {}, tt .giveClientErr )
152
+ }
153
+
154
+ connClosed := false
155
+ mockConn := mocks .NewConnector (t )
156
+ mockConn .EXPECT ().NewConn ().Return (
157
+ & grpc.ClientConn {},
158
+ func () { connClosed = true },
159
+ tt .giveConnectorErr ,
160
+ )
161
+
162
+ c , _ := NewWithArgs (
163
+ mockConn ,
164
+ func (grpc.ClientConnInterface ) pb.NvmeRemoteControllerServiceClient {
165
+ return mockClient
166
+ },
167
+ )
168
+
169
+ err := c .DeleteNvmeController (ctx , testControllerName , true )
170
+
171
+ require .Equal (t , tt .wantErr , err )
172
+ require .Equal (t , tt .wantConnClosed , connClosed )
173
+ })
174
+ }
175
+ }
0 commit comments