blob: 47e9ce3e8c2b3655e5fdd88eca039ee6f0778688 [file] [log] [blame]
cbabua9e04cc2019-10-03 12:35:45 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
cbabubef89432019-10-18 11:47:27 +020017/*
18This file contains unit test cases for functions in the file openolt.go.
19This file also implements the fields struct to mock the Openolt and few utility functions.
20*/
21
22//Package adaptercore provides the utility for olt devices, flows and statistics
cbabua9e04cc2019-10-03 12:35:45 +053023package adaptercore
24
25import (
26 "context"
27 "errors"
28 "reflect"
29 "sync"
30 "testing"
31
Scott Baker51290152019-10-24 14:23:20 -070032 com "github.com/opencord/voltha-lib-go/v2/pkg/adapters/common"
33 fu "github.com/opencord/voltha-lib-go/v2/pkg/flows"
34 "github.com/opencord/voltha-lib-go/v2/pkg/kafka"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053035 "github.com/opencord/voltha-openolt-adapter/config"
Scott Bakerc6e54cb2019-11-04 09:31:25 -080036 ic "github.com/opencord/voltha-protos/v2/go/inter_container"
37 "github.com/opencord/voltha-protos/v2/go/openflow_13"
38 ofp "github.com/opencord/voltha-protos/v2/go/openflow_13"
39 "github.com/opencord/voltha-protos/v2/go/voltha"
cbabua9e04cc2019-10-03 12:35:45 +053040)
41
cbabubef89432019-10-18 11:47:27 +020042// mocks the OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053043type fields struct {
44 deviceHandlers map[string]*DeviceHandler
45 coreProxy *com.CoreProxy
46 adapterProxy *com.AdapterProxy
47 eventProxy *com.EventProxy
48 kafkaICProxy *kafka.InterContainerProxy
49 numOnus int
50 KVStoreHost string
51 KVStorePort int
52 KVStoreType string
53 exitChannel chan int
54 lockDeviceHandlersMap sync.RWMutex
55 ctx context.Context
56}
57
cbabubef89432019-10-18 11:47:27 +020058// mockOlt mocks OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053059func mockOlt() *fields {
cbabua9e04cc2019-10-03 12:35:45 +053060 dh := newMockDeviceHandler()
61 newOlt := &fields{}
62 newOlt.deviceHandlers = map[string]*DeviceHandler{}
63 newOlt.deviceHandlers[dh.device.Id] = dh
64 return newOlt
65}
66
cbabubef89432019-10-18 11:47:27 +020067// testOltObject maps fields type to OpenOLt type.
cbabua9e04cc2019-10-03 12:35:45 +053068func testOltObject(testOlt *fields) *OpenOLT {
69 return &OpenOLT{
70 deviceHandlers: testOlt.deviceHandlers,
71 coreProxy: testOlt.coreProxy,
72 adapterProxy: testOlt.adapterProxy,
73 eventProxy: testOlt.eventProxy,
74 kafkaICProxy: testOlt.kafkaICProxy,
75 numOnus: testOlt.numOnus,
76 KVStoreHost: testOlt.KVStoreHost,
77 KVStorePort: testOlt.KVStorePort,
78 KVStoreType: testOlt.KVStoreType,
79 exitChannel: testOlt.exitChannel,
80 }
81}
82
cbabubef89432019-10-18 11:47:27 +020083// mockDevice mocks Device.
cbabua9e04cc2019-10-03 12:35:45 +053084func mockDevice() *voltha.Device {
85 device := &voltha.Device{
86 Id: "olt",
87 Root: true,
88 ParentId: "logical_device",
89 Ports: []*voltha.Port{
90 {PortNo: 1, Label: "pon"},
91 {PortNo: 2, Label: "nni"},
92 },
93 ProxyAddress: &voltha.Device_ProxyAddress{
94 DeviceId: "olt",
95 DeviceType: "onu",
96 ChannelId: 1,
97 ChannelGroupId: 1,
98 },
99 ConnectStatus: 1,
100 }
101 return device
102}
103
104func TestNewOpenOLT(t *testing.T) {
105 tests := []struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530106 name string
107 fields *fields
108 configFlags *config.AdapterFlags
109 want *OpenOLT
cbabua9e04cc2019-10-03 12:35:45 +0530110 }{
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530111 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStorePort: 1, KVStoreType: "consul", KVStoreHost: "1.1.1.1"},
cbabua9e04cc2019-10-03 12:35:45 +0530112 &OpenOLT{numOnus: 1, KVStorePort: 1, KVStoreType: "consul", KVStoreHost: "1.1.1.1"}},
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530113 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStorePort: 2, KVStoreType: "etcd", KVStoreHost: "2.2.2.2"},
cbabua9e04cc2019-10-03 12:35:45 +0530114 &OpenOLT{numOnus: 2, KVStorePort: 2, KVStoreType: "etcd", KVStoreHost: "2.2.2.2"}},
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530115 {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStorePort: 3, KVStoreType: "consul", KVStoreHost: "3.3.3.3"},
cbabua9e04cc2019-10-03 12:35:45 +0530116 &OpenOLT{numOnus: 3, KVStorePort: 3, KVStoreType: "consul", KVStoreHost: "3.3.3.3"}},
117 }
118 for _, tt := range tests {
119 t.Run(tt.name, func(t *testing.T) {
120 if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530121 tt.fields.eventProxy, tt.configFlags); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
cbabua9e04cc2019-10-03 12:35:45 +0530122 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
123 }
124 })
125 }
126}
127
128func TestOpenOLT_Abandon_device(t *testing.T) {
129 type args struct {
130 device *voltha.Device
131 }
132 tests := []struct {
133 name string
134 fields *fields
135 args args
136 wantErr error
137 }{
138 {"abandon_device-1", &fields{}, args{}, errors.New("unImplemented")},
139 {"abandon_device-2", &fields{}, args{}, errors.New("unImplemented")},
140 {"abandon_device-3", &fields{}, args{}, errors.New("unImplemented")},
141 }
142 for _, tt := range tests {
143 t.Run(tt.name, func(t *testing.T) {
144 oo := testOltObject(tt.fields)
145 if err := oo.Abandon_device(tt.args.device); (err != nil) && (reflect.TypeOf(err) !=
146 reflect.TypeOf(tt.wantErr)) {
147 t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr)
148 }
149 })
150 }
151}
152
153func TestOpenOLT_Activate_image_update(t *testing.T) {
154 type args struct {
155 device *voltha.Device
156 request *voltha.ImageDownload
157 }
158 tests := []struct {
159 name string
160 fields *fields
161 args args
162 want *voltha.ImageDownload
163 wantErr error
164 }{
165 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
166 errors.New("unImplemented")},
167 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
168 errors.New("unImplemented")},
169 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
170 errors.New("unImplemented")},
171 }
172 for _, tt := range tests {
173 t.Run(tt.name, func(t *testing.T) {
174 oo := testOltObject(tt.fields)
175 got, err := oo.Activate_image_update(tt.args.device, tt.args.request)
176 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && (got == nil) {
177 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
178 }
179 })
180 }
181}
182
183func TestOpenOLT_Adapter_descriptor(t *testing.T) {
184 tests := []struct {
185 name string
186 fields *fields
187 wantErr error
188 }{
189 {"adapter_descriptor-1", &fields{}, errors.New("unImplemented")},
190 {"adapter_descriptor-2", &fields{}, errors.New("unImplemented")},
191 {"adapter_descriptor-3", &fields{}, errors.New("unImplemented")},
192 }
193 for _, tt := range tests {
194 t.Run(tt.name, func(t *testing.T) {
195 oo := testOltObject(tt.fields)
196 if err := oo.Adapter_descriptor(); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
197 t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr)
198 }
199 })
200 }
201}
202
203func TestOpenOLT_Adopt_device(t *testing.T) {
204 type args struct {
205 device *voltha.Device
206 }
207 var device = mockDevice()
208 device.Id = "openolt"
209 tests := []struct {
210 name string
211 fields *fields
212 args args
213 wantErr error
214 }{
215 {"adopt_device-1", mockOlt(), args{}, errors.New("nil-device")},
216 {"adopt_device-2", mockOlt(), args{device}, errors.New("nil-device")},
217 {"adopt_device-3", mockOlt(),
218 args{mockDevice()}, nil},
219 }
220 for _, tt := range tests {
221 t.Run(tt.name, func(t *testing.T) {
222 oo := testOltObject(tt.fields)
223 err := oo.Adopt_device(tt.args.device)
224 if (err != nil) && (reflect.TypeOf(err) !=
225 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
226 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
227 }
228 if err == nil {
229 t.Log("return'd nil")
230 }
231 })
232 }
233}
234
235func TestOpenOLT_Cancel_image_download(t *testing.T) {
236 type args struct {
237 device *voltha.Device
238 request *voltha.ImageDownload
239 }
240 tests := []struct {
241 name string
242 fields *fields
243 args args
244 want *voltha.ImageDownload
245 wantErr error
246 }{
247 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
248 errors.New("unImplemented")},
249 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
250 errors.New("unImplemented")},
251 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
252 errors.New("unImplemented")},
253 }
254 for _, tt := range tests {
255 t.Run(tt.name, func(t *testing.T) {
256 oo := testOltObject(tt.fields)
257 got, err := oo.Cancel_image_download(tt.args.device, tt.args.request)
258 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
259 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
260 }
261 })
262 }
263}
264
265func TestOpenOLT_Delete_device(t *testing.T) {
266 type args struct {
267 device *voltha.Device
268 }
269 tests := []struct {
270 name string
271 fields *fields
272 args args
273 wantErr error
274 }{
275 {"delete_device-1", &fields{}, args{mockDevice()}, errors.New("device-handler-not-found")},
276 }
277 for _, tt := range tests {
278 t.Run(tt.name, func(t *testing.T) {
279 oo := testOltObject(tt.fields)
280 if err := oo.Delete_device(tt.args.device); (err != nil) && (reflect.TypeOf(err) !=
281 reflect.TypeOf(tt.wantErr)) {
282 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
283 }
284 })
285 }
286}
287
288func TestOpenOLT_Device_types(t *testing.T) {
289 tests := []struct {
290 name string
291 fields *fields
292 want *voltha.DeviceTypes
293 wantErr error
294 }{
295 {"device_types-1", &fields{}, &voltha.DeviceTypes{},
296 errors.New("unImplemented")},
297 {"device_types-2", &fields{}, &voltha.DeviceTypes{},
298 errors.New("unImplemented")},
299 {"device_types-3", &fields{}, &voltha.DeviceTypes{},
300 errors.New("unImplemented")},
301 }
302 for _, tt := range tests {
303 t.Run(tt.name, func(t *testing.T) {
304 oo := testOltObject(tt.fields)
305 got, err := oo.Device_types()
306 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
307 t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr)
308 }
309 })
310 }
311}
312
313func TestOpenOLT_Disable_device(t *testing.T) {
314 type args struct {
315 device *voltha.Device
316 }
317 tests := []struct {
318 name string
319 fields *fields
320 args args
321 wantErr error
322 }{
323 {"disable_device-1", mockOlt(), args{mockDevice()}, errors.New("device-handler-not-found")},
324 {"disable_device-2", &fields{}, args{mockDevice()}, errors.New("device-handler-not-found")},
325 }
326 for _, tt := range tests {
327 t.Run(tt.name, func(t *testing.T) {
328 oo := testOltObject(tt.fields)
329 if err := oo.Disable_device(tt.args.device); (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && err != nil {
330 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
331 }
332 })
333 }
334}
335
336func TestOpenOLT_Download_image(t *testing.T) {
337 type args struct {
338 device *voltha.Device
339 request *voltha.ImageDownload
340 }
341 tests := []struct {
342 name string
343 fields *fields
344 args args
345 want *voltha.ImageDownload
346 wantErr error
347 }{
348 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
349 errors.New("unImplemented")},
350 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
351 errors.New("unImplemented")},
352 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
353 errors.New("unImplemented")},
354 }
355 for _, tt := range tests {
356 t.Run(tt.name, func(t *testing.T) {
357 oo := testOltObject(tt.fields)
358 got, err := oo.Download_image(tt.args.device, tt.args.request)
359 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
360 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
361 }
362 })
363 }
364}
365
366func TestOpenOLT_Get_device_details(t *testing.T) {
367 type args struct {
368 device *voltha.Device
369 }
370 tests := []struct {
371 name string
372 fields *fields
373 args args
374 wantErr error
375 }{
376 {"get_device_details-1", &fields{}, args{}, errors.New("unImplemented")},
377 {"get_device_details-2", &fields{}, args{}, errors.New("unImplemented")},
378 {"get_device_details-3", &fields{}, args{}, errors.New("unImplemented")},
379 }
380 for _, tt := range tests {
381 t.Run(tt.name, func(t *testing.T) {
382 oo := testOltObject(tt.fields)
383 if err := oo.Get_device_details(tt.args.device); (err != nil) &&
384 (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
385 t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr)
386 }
387 })
388 }
389}
390
391func TestOpenOLT_Get_image_download_status(t *testing.T) {
392 type args struct {
393 device *voltha.Device
394 request *voltha.ImageDownload
395 }
396 tests := []struct {
397 name string
398 fields *fields
399 args args
400 want *voltha.ImageDownload
401 wantErr error
402 }{
403 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
404 errors.New("unImplemented")},
405 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
406 errors.New("unImplemented")},
407 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
408 errors.New("unImplemented")},
409 }
410 for _, tt := range tests {
411 t.Run(tt.name, func(t *testing.T) {
412 oo := testOltObject(tt.fields)
413 got, err := oo.Get_image_download_status(tt.args.device, tt.args.request)
414 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
415 t.Errorf("Get_image_download_status() error = %v, wantErr %v", err, tt.wantErr)
416 }
417 })
418 }
419}
420
421func TestOpenOLT_Get_ofp_device_info(t *testing.T) {
422 type args struct {
423 device *voltha.Device
424 }
425 tests := []struct {
426 name string
427 fields *fields
428 args args
429 want *ic.SwitchCapability
430 wantErr error
431 }{
432 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{},
433 errors.New("device-handler-not-set")},
434 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, &ic.SwitchCapability{},
435 errors.New("device-handler-not-set")},
436 }
437 for _, tt := range tests {
438 t.Run(tt.name, func(t *testing.T) {
439 oo := testOltObject(tt.fields)
440 got, err := oo.Get_ofp_device_info(tt.args.device)
441 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
442 t.Errorf("Get_ofp_device_info() error = %v, wantErr %v", err, tt.wantErr)
443 }
444 if (err == nil) && got != nil {
445 t.Log("got :", got)
446 }
447 })
448 }
449}
450
451func TestOpenOLT_Get_ofp_port_info(t *testing.T) {
452 type args struct {
453 device *voltha.Device
454 portNo int64
455 }
456 tests := []struct {
457 name string
458 fields *fields
459 args args
460 want *ic.PortCapability
461 wantErr error
462 }{
463 {"get_ofp_port_info-1", mockOlt(), args{mockDevice(), 1}, &ic.PortCapability{},
464 errors.New("device-handler-not-set")},
465 {"get_ofp_port_info-2", &fields{}, args{mockDevice(), 1}, &ic.PortCapability{},
466 errors.New("device-handler-not-set")},
467 }
468 for _, tt := range tests {
469 t.Run(tt.name, func(t *testing.T) {
470 oo := testOltObject(tt.fields)
471 got, err := oo.Get_ofp_port_info(tt.args.device, tt.args.portNo)
472 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
473 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
474 }
475 if (err == nil) && got != nil {
476 t.Log("got :", got)
477 }
478 })
479 }
480}
481
482func TestOpenOLT_Health(t *testing.T) {
483 tests := []struct {
484 name string
485 fields *fields
486 want *voltha.HealthStatus
487 wantErr error
488 }{
489 {"health-1", &fields{}, &voltha.HealthStatus{}, errors.New("unImplemented")},
490 {"health-2", &fields{}, &voltha.HealthStatus{}, errors.New("unImplemented")},
491 {"health-3", &fields{}, &voltha.HealthStatus{}, errors.New("unImplemented")},
492 }
493 for _, tt := range tests {
494 t.Run(tt.name, func(t *testing.T) {
495 oo := testOltObject(tt.fields)
496 got, err := oo.Health()
497 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
498 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
499 }
500 })
501 }
502}
503
504func TestOpenOLT_Process_inter_adapter_message(t *testing.T) {
505 type args struct {
506 msg *ic.InterAdapterMessage
507 }
508 var message1 = args{
509 msg: &ic.InterAdapterMessage{
510 Header: &ic.InterAdapterHeader{
511 Id: "olt",
512 ProxyDeviceId: "",
513 ToDeviceId: "onu1",
514 },
515 },
516 }
517 var message2 = args{
518 msg: &ic.InterAdapterMessage{
519 Header: &ic.InterAdapterHeader{
520 Id: "olt",
521 ProxyDeviceId: "olt",
522 ToDeviceId: "olt",
523 },
524 },
525 }
526 tests := []struct {
527 name string
528 fields *fields
529 args args
530 wantErr error
531 }{
532 {"process_inter_adaptor_messgae-1", mockOlt(), message1, errors.New("handler-not-found")},
533 {"process_inter_adaptor_messgae-2", mockOlt(), message2, errors.New("handler-not-found")},
534 }
535 for _, tt := range tests {
536 t.Run(tt.name, func(t *testing.T) {
537 oo := testOltObject(tt.fields)
538 if err := oo.Process_inter_adapter_message(tt.args.msg); (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && err != nil {
539 t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v", err, tt.wantErr)
540 }
541 })
542 }
543}
544
545func TestOpenOLT_Reboot_device(t *testing.T) {
546 type args struct {
547 device *voltha.Device
548 }
549 tests := []struct {
550 name string
551 fields *fields
552 args args
553 wantErr error
554 }{
555 {"reboot_device-1", mockOlt(), args{mockDevice()}, errors.New("device-handler-not-found")},
556 {"reboot_device-2", &fields{}, args{mockDevice()}, errors.New("device-handler-not-found")},
557 }
558 for _, tt := range tests {
559 t.Run(tt.name, func(t *testing.T) {
560 oo := testOltObject(tt.fields)
561 if err := oo.Reboot_device(tt.args.device); (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && err != nil {
562 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
563 }
564 })
565 }
566}
567
568func TestOpenOLT_Receive_packet_out(t *testing.T) {
569 acts := []*ofp.OfpAction{
570 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
571 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
572 fu.Output(1),
573 }
574 type args struct {
575 deviceID string
576 egressPortNo int
577 packet *openflow_13.OfpPacketOut
578 }
579 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
580 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
581 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
582 tests := []struct {
583 name string
584 fields *fields
585 args args
586 wantErr error
587 }{
588 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout},
589 errors.New("device-handler-not-set")},
590 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
591 errors.New("device-handler-not-set")},
592 }
593 for _, tt := range tests {
594 t.Run(tt.name, func(t *testing.T) {
595 oo := testOltObject(tt.fields)
596 if err := oo.Receive_packet_out(tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
597 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
598 }
599 })
600 }
601}
602
603func TestOpenOLT_Reconcile_device(t *testing.T) {
604 type args struct {
605 device *voltha.Device
606 }
607 tests := []struct {
608 name string
609 fields *fields
610 args args
611 wantErr error
612 }{
613 {"reconcile_device-1", &fields{}, args{}, errors.New("unImplemented")},
614 {"reconcile_device-2", &fields{}, args{}, errors.New("unImplemented")},
615 {"reconcile_device-3", &fields{}, args{}, errors.New("unImplemented")},
616 }
617 for _, tt := range tests {
618 t.Run(tt.name, func(t *testing.T) {
619 oo := testOltObject(tt.fields)
620 if err := oo.Reconcile_device(tt.args.device); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
621 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
622 }
623 })
624 }
625}
626
627func TestOpenOLT_Reenable_device(t *testing.T) {
628 type args struct {
629 device *voltha.Device
630 }
631 tests := []struct {
632 name string
633 fields *fields
634 args args
635 wantErr error
636 }{
637 {"reenable_device-1", mockOlt(), args{mockDevice()}, errors.New("device-handler-not-found")},
638 {"reenable_device-2", &fields{}, args{mockDevice()}, errors.New("device-handler-not-found")},
639 }
640 for _, tt := range tests {
641 t.Run(tt.name, func(t *testing.T) {
642 oo := testOltObject(tt.fields)
643 if err := oo.Reenable_device(tt.args.device); (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && err != nil {
644 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
645 }
646 })
647 }
648}
649
650func TestOpenOLT_Revert_image_update(t *testing.T) {
651 type args struct {
652 device *voltha.Device
653 request *voltha.ImageDownload
654 }
655 tests := []struct {
656 name string
657 fields *fields
658 args args
659 want *voltha.ImageDownload
660 wantErr error
661 }{
662 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
663 errors.New("unImplemented")},
664 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
665 errors.New("unImplemented")},
666 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
667 errors.New("unImplemented")},
668 }
669 for _, tt := range tests {
670 t.Run(tt.name, func(t *testing.T) {
671 oo := testOltObject(tt.fields)
672 got, err := oo.Revert_image_update(tt.args.device, tt.args.request)
673 if (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) && got == nil {
674 t.Log("error :", err)
675 }
676 })
677 }
678}
679
680func TestOpenOLT_Self_test_device(t *testing.T) {
681 type args struct {
682 device *voltha.Device
683 }
684 tests := []struct {
685 name string
686 fields *fields
687 args args
688 wantErr error
689 }{
690 {"self_test_device-1", &fields{}, args{}, errors.New("unImplemented")},
691 {"self_test_device-2", &fields{}, args{}, errors.New("unImplemented")},
692 {"self_test_device-3", &fields{}, args{}, errors.New("unImplemented")},
693 }
694 for _, tt := range tests {
695 t.Run(tt.name, func(t *testing.T) {
696 oo := testOltObject(tt.fields)
697 if err := oo.Self_test_device(tt.args.device); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
698 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
699 }
700 })
701 }
702}
703
704func TestOpenOLT_Start(t *testing.T) {
705 type args struct {
706 ctx context.Context
707 }
708 tests := []struct {
709 name string
710 fields *fields
711 args args
712 wantErr error
713 }{
714 {"start-1", &fields{}, args{}, errors.New("start error")},
715 }
716 for _, tt := range tests {
717 t.Run(tt.name, func(t *testing.T) {
718 oo := testOltObject(tt.fields)
719 if err := oo.Start(tt.args.ctx); err != nil {
720 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
721 }
722 })
723 }
724}
725
726func TestOpenOLT_Stop(t *testing.T) {
727 type args struct {
728 ctx context.Context
729 }
730 tests := []struct {
731 name string
732 fields *fields
733 args args
734 wantErr error
735 }{
736 {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")},
737 }
738 for _, tt := range tests {
739 t.Run(tt.name, func(t *testing.T) {
740 oo := testOltObject(tt.fields)
741 oo.Start(tt.args.ctx)
742 if err := oo.Stop(tt.args.ctx); err != nil {
743 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
744 }
745 })
746 }
747}
748
Devmalya Pauldd23a992019-11-14 07:06:31 +0000749func TestOpenOLT_Suppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530750 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000751 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530752 }
753 tests := []struct {
754 name string
755 fields *fields
756 args args
757 wantErr error
758 }{
Devmalya Pauldd23a992019-11-14 07:06:31 +0000759 {"suppress_event-1", &fields{}, args{}, errors.New("unImplemented")},
760 {"suppress_event-2", &fields{}, args{}, errors.New("unImplemented")},
761 {"suppress_event-3", &fields{}, args{}, errors.New("unImplemented")},
cbabua9e04cc2019-10-03 12:35:45 +0530762 }
763 for _, tt := range tests {
764 t.Run(tt.name, func(t *testing.T) {
765 oo := testOltObject(tt.fields)
Devmalya Pauldd23a992019-11-14 07:06:31 +0000766 if err := oo.Suppress_event(tt.args.filter); (err != nil) &&
cbabua9e04cc2019-10-03 12:35:45 +0530767 (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000768 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530769 }
770 })
771 }
772}
773
Devmalya Pauldd23a992019-11-14 07:06:31 +0000774func TestOpenOLT_Unsuppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530775 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000776 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530777 }
778 tests := []struct {
779 name string
780 fields *fields
781 args args
782 wantErr error
783 }{
Devmalya Pauldd23a992019-11-14 07:06:31 +0000784 {"unsupress_event-1", &fields{}, args{}, errors.New("unImplemented")},
785 {"unsupress_event-2", &fields{}, args{}, errors.New("unImplemented")},
786 {"unsupress_event-3", &fields{}, args{}, errors.New("unImplemented")},
cbabua9e04cc2019-10-03 12:35:45 +0530787 }
788 for _, tt := range tests {
789 t.Run(tt.name, func(t *testing.T) {
790 oo := testOltObject(tt.fields)
Devmalya Pauldd23a992019-11-14 07:06:31 +0000791 if err := oo.Unsuppress_event(tt.args.filter); (err != nil) &&
cbabua9e04cc2019-10-03 12:35:45 +0530792 (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000793 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530794 }
795 })
796 }
797}
798
799func TestOpenOLT_Update_flows_bulk(t *testing.T) {
800 type args struct {
801 device *voltha.Device
802 flows *voltha.Flows
803 groups *voltha.FlowGroups
804 flowMetadata *voltha.FlowMetadata
805 }
806 tests := []struct {
807 name string
808 fields *fields
809 args args
810 wantErr error
811 }{
812 {"update_flows_bulk-1", &fields{}, args{}, errors.New("unImplemented")},
813 {"update_flows_bulk-2", &fields{}, args{}, errors.New("unImplemented")},
814 {"update_flows_bulk-3", &fields{}, args{}, errors.New("unImplemented")},
815 }
816 for _, tt := range tests {
817 t.Run(tt.name, func(t *testing.T) {
818 oo := testOltObject(tt.fields)
819 if err := oo.Update_flows_bulk(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
820 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
821 }
822 })
823 }
824}
825
826func TestOpenOLT_Update_flows_incrementally(t *testing.T) {
827 type args struct {
828 device *voltha.Device
829 flows *openflow_13.FlowChanges
830 groups *openflow_13.FlowGroupChanges
831 flowMetadata *voltha.FlowMetadata
832 }
833
834 tests := []struct {
835 name string
836 fields *fields
837 args args
838 wantErr error
839 }{
840 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
841 errors.New("device-handler-not-set")},
842 {"update_flows_incrementally-1", mockOlt(), args{device: mockDevice()},
843 errors.New("device-handler-not-set")},
844 }
845 for _, tt := range tests {
846 t.Run(tt.name, func(t *testing.T) {
847 oo := testOltObject(tt.fields)
848 if err := oo.Update_flows_incrementally(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); (err != nil) && (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
849 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
850 }
851 })
852 }
853}
854
855func TestOpenOLT_Update_pm_config(t *testing.T) {
856 type args struct {
857 device *voltha.Device
858 pmConfigs *voltha.PmConfigs
859 }
860 tests := []struct {
861 name string
862 fields *fields
863 args args
864 wantErr error
865 }{
866 {"update_pm_config-1", &fields{}, args{}, errors.New("unImplemented")},
867 {"update_pm_config-2", &fields{}, args{}, errors.New("unImplemented")},
868 {"update_pm_config-3", &fields{}, args{}, errors.New("unImplemented")},
869 }
870 for _, tt := range tests {
871 t.Run(tt.name, func(t *testing.T) {
872 oo := testOltObject(tt.fields)
873 if err := oo.Update_pm_config(tt.args.device, tt.args.pmConfigs); (err != nil) &&
874 (reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr)) {
875 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
876 }
877
878 })
879 }
880}
881
882func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
883 type args struct {
884 agent *DeviceHandler
885 }
886 tests := []struct {
887 name string
888 fields *fields
889 args args
890 }{
891 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
892 }
893 for _, tt := range tests {
894 t.Run(tt.name, func(t *testing.T) {
895 oo := testOltObject(tt.fields)
896 oo.deleteDeviceHandlerToMap(tt.args.agent)
897 if len(oo.deviceHandlers) > 0 {
898 t.Errorf("delete device manager failed")
899 }
900 })
901 }
902}