blob: 08c2f528f9c56fed5031bf5b307fb03ecee06401 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
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
17/*
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 core provides the utility for olt devices, flows and statistics
23package core
24
25import (
26 "context"
27 "errors"
28 "reflect"
29 "testing"
30
31 com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
32 fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
34 "github.com/opencord/voltha-lib-go/v3/pkg/log"
35 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
36 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
37 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
38 "github.com/opencord/voltha-protos/v3/go/openflow_13"
39 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
40 "github.com/opencord/voltha-protos/v3/go/voltha"
41)
42
43// mocks the OpenOLT struct.
44type fields struct {
45 deviceHandlers map[string]*DeviceHandler
46 coreProxy *com.CoreProxy
47 adapterProxy *com.AdapterProxy
48 eventProxy *com.EventProxy
49 kafkaICProxy kafka.InterContainerProxy
50 numOnus int
51 KVStoreAddress string
52 KVStoreType string
53 exitChannel chan int
54 ctx context.Context
55}
56
57// mockOlt mocks OpenOLT struct.
58func mockOlt() *fields {
59 dh := newMockDeviceHandler()
60 newOlt := &fields{}
61 newOlt.deviceHandlers = map[string]*DeviceHandler{}
62 newOlt.deviceHandlers[dh.device.Id] = dh
63 return newOlt
64}
65
66// testOltObject maps fields type to OpenOLt type.
67func testOltObject(testOlt *fields) *OpenOLT {
68 return &OpenOLT{
69 deviceHandlers: testOlt.deviceHandlers,
70 coreProxy: testOlt.coreProxy,
71 adapterProxy: testOlt.adapterProxy,
72 eventProxy: testOlt.eventProxy,
73 kafkaICProxy: testOlt.kafkaICProxy,
74 numOnus: testOlt.numOnus,
75 KVStoreAddress: testOlt.KVStoreAddress,
76 KVStoreType: testOlt.KVStoreType,
77 exitChannel: testOlt.exitChannel,
78 }
79}
80
81// mockDevice mocks Device.
82func mockDevice() *voltha.Device {
83 return &voltha.Device{
84 Id: "olt",
85 Root: true,
86 ParentId: "logical_device",
87 ProxyAddress: &voltha.Device_ProxyAddress{
88 DeviceId: "olt",
89 DeviceType: "onu",
90 ChannelId: 1,
91 ChannelGroupId: 1,
92 },
93 ConnectStatus: 1,
94 }
95}
96
97func TestNewOpenOLT(t *testing.T) {
98 tests := []struct {
99 name string
100 fields *fields
101 configFlags *config.AdapterFlags
102 want *OpenOLT
103 }{
104 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"},
105 &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}},
106 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"},
107 &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}},
108 {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"},
109 &OpenOLT{numOnus: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}},
110 }
111 for _, tt := range tests {
112 t.Run(tt.name, func(t *testing.T) {
113 if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy,
114 tt.fields.eventProxy, tt.configFlags); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
115 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
116 }
117 })
118 }
119}
120
121func TestOpenOLT_Abandon_device(t *testing.T) {
122 type args struct {
123 device *voltha.Device
124 }
125 tests := []struct {
126 name string
127 fields *fields
128 args args
129 wantErr error
130 }{
131 {"abandon_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
132 {"abandon_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
133 {"abandon_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
134 }
135 for _, tt := range tests {
136 t.Run(tt.name, func(t *testing.T) {
137 oo := testOltObject(tt.fields)
138 if err := oo.Abandon_device(context.Background(), tt.args.device); err != tt.wantErr {
139 t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr)
140 }
141 })
142 }
143}
144
145func TestOpenOLT_Activate_image_update(t *testing.T) {
146 type args struct {
147 device *voltha.Device
148 request *voltha.ImageDownload
149 }
150 tests := []struct {
151 name string
152 fields *fields
153 args args
154 want *voltha.ImageDownload
155 wantErr error
156 }{
157 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
158 olterrors.ErrNotImplemented},
159 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
160 olterrors.ErrNotImplemented},
161 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
162 olterrors.ErrNotImplemented},
163 }
164 for _, tt := range tests {
165 t.Run(tt.name, func(t *testing.T) {
166 oo := testOltObject(tt.fields)
167 got, err := oo.Activate_image_update(context.Background(), tt.args.device, tt.args.request)
168 if err != tt.wantErr && got == nil {
169 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
170 }
171 })
172 }
173}
174
175func TestOpenOLT_Adapter_descriptor(t *testing.T) {
176 tests := []struct {
177 name string
178 fields *fields
179 wantErr error
180 }{
181 {"adapter_descriptor-1", &fields{}, olterrors.ErrNotImplemented},
182 {"adapter_descriptor-2", &fields{}, olterrors.ErrNotImplemented},
183 {"adapter_descriptor-3", &fields{}, olterrors.ErrNotImplemented},
184 }
185 for _, tt := range tests {
186 t.Run(tt.name, func(t *testing.T) {
187 oo := testOltObject(tt.fields)
188 if err := oo.Adapter_descriptor(context.Background()); err != tt.wantErr {
189 t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr)
190 }
191 })
192 }
193}
194
195func TestOpenOLT_Adopt_device(t *testing.T) {
196 type args struct {
197 device *voltha.Device
198 }
199 var device = mockDevice()
200 device.Id = "olt"
201 nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
202 tests := []struct {
203 name string
204 fields *fields
205 args args
206 wantErr error
207 }{
208 {"adopt_device-1", mockOlt(), args{}, nilDevice},
209 {"adopt_device-2", mockOlt(), args{device}, nilDevice},
210 {"adopt_device-3", mockOlt(), args{mockDevice()}, nil},
211 }
212 for _, tt := range tests {
213 t.Run(tt.name, func(t *testing.T) {
214 oo := testOltObject(tt.fields)
215 err := oo.Adopt_device(context.Background(), tt.args.device)
216 if (err != nil) && (reflect.TypeOf(err) !=
217 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
218 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
219 }
220 if err == nil {
221 t.Log("return'd nil")
222 }
223 })
224 }
225}
226
227func TestOpenOLT_Cancel_image_download(t *testing.T) {
228 type args struct {
229 device *voltha.Device
230 request *voltha.ImageDownload
231 }
232 tests := []struct {
233 name string
234 fields *fields
235 args args
236 want *voltha.ImageDownload
237 wantErr error
238 }{
239 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
240 olterrors.ErrNotImplemented},
241 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
242 olterrors.ErrNotImplemented},
243 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
244 olterrors.ErrNotImplemented},
245 }
246 for _, tt := range tests {
247 t.Run(tt.name, func(t *testing.T) {
248 oo := testOltObject(tt.fields)
249 got, err := oo.Cancel_image_download(context.Background(), tt.args.device, tt.args.request)
250 if err != tt.wantErr && got == nil {
251 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
252 }
253 })
254 }
255}
256
257func TestOpenOLT_Delete_device(t *testing.T) {
258 type args struct {
259 device *voltha.Device
260 }
261 tests := []struct {
262 name string
263 fields *fields
264 args args
265 wantErr error
266 }{
267 {"delete_device-1", &fields{}, args{mockDevice()},
268 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
269 }
270 for _, tt := range tests {
271 t.Run(tt.name, func(t *testing.T) {
272 oo := testOltObject(tt.fields)
273 if err := oo.Delete_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
274 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
275 }
276 })
277 }
278}
279
280func TestOpenOLT_Device_types(t *testing.T) {
281 tests := []struct {
282 name string
283 fields *fields
284 want *voltha.DeviceTypes
285 wantErr error
286 }{
287 {"device_types-1", &fields{}, &voltha.DeviceTypes{},
288 olterrors.ErrNotImplemented},
289 {"device_types-2", &fields{}, &voltha.DeviceTypes{},
290 olterrors.ErrNotImplemented},
291 {"device_types-3", &fields{}, &voltha.DeviceTypes{},
292 olterrors.ErrNotImplemented},
293 }
294 for _, tt := range tests {
295 t.Run(tt.name, func(t *testing.T) {
296 oo := testOltObject(tt.fields)
297 got, err := oo.Device_types(context.Background())
298 if err != tt.wantErr && got == nil {
299 t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr)
300 }
301 })
302 }
303}
304
305func TestOpenOLT_Disable_device(t *testing.T) {
306 type args struct {
307 device *voltha.Device
308 }
309 tests := []struct {
310 name string
311 fields *fields
312 args args
313 wantErr error
314 }{
315 {"disable_device-1", mockOlt(), args{mockDevice()}, nil},
316 {"disable_device-2", &fields{}, args{mockDevice()},
317 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
318 }
319 for _, tt := range tests {
320 t.Run(tt.name, func(t *testing.T) {
321 oo := testOltObject(tt.fields)
322 if err := oo.Disable_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
323 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
324 }
325 })
326 }
327}
328
329func TestOpenOLT_Download_image(t *testing.T) {
330 type args struct {
331 device *voltha.Device
332 request *voltha.ImageDownload
333 }
334 tests := []struct {
335 name string
336 fields *fields
337 args args
338 want *voltha.ImageDownload
339 wantErr error
340 }{
341 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
342 olterrors.ErrNotImplemented},
343 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
344 olterrors.ErrNotImplemented},
345 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
346 olterrors.ErrNotImplemented},
347 }
348 for _, tt := range tests {
349 t.Run(tt.name, func(t *testing.T) {
350 oo := testOltObject(tt.fields)
351 got, err := oo.Download_image(context.Background(), tt.args.device, tt.args.request)
352 if err != tt.wantErr && got == nil {
353 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
354 }
355 })
356 }
357}
358
359func TestOpenOLT_Get_device_details(t *testing.T) {
360 type args struct {
361 device *voltha.Device
362 }
363 tests := []struct {
364 name string
365 fields *fields
366 args args
367 wantErr error
368 }{
369 {"get_device_details-1", &fields{}, args{}, olterrors.ErrNotImplemented},
370 {"get_device_details-2", &fields{}, args{}, olterrors.ErrNotImplemented},
371 {"get_device_details-3", &fields{}, args{}, olterrors.ErrNotImplemented},
372 }
373 for _, tt := range tests {
374 t.Run(tt.name, func(t *testing.T) {
375 oo := testOltObject(tt.fields)
376 if err := oo.Get_device_details(context.Background(), tt.args.device); err != tt.wantErr {
377 t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr)
378 }
379 })
380 }
381}
382
383func TestOpenOLT_Get_image_download_status(t *testing.T) {
384 type args struct {
385 device *voltha.Device
386 request *voltha.ImageDownload
387 }
388 tests := []struct {
389 name string
390 fields *fields
391 args args
392 want *voltha.ImageDownload
393 wantErr error
394 }{
395 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
396 olterrors.ErrNotImplemented},
397 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
398 olterrors.ErrNotImplemented},
399 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
400 olterrors.ErrNotImplemented},
401 }
402 for _, tt := range tests {
403 t.Run(tt.name, func(t *testing.T) {
404 oo := testOltObject(tt.fields)
405 got, err := oo.Get_image_download_status(context.Background(), tt.args.device, tt.args.request)
406 if err != tt.wantErr && got == nil {
407 t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v",
408 got, tt.want, err, tt.wantErr)
409 }
410 })
411 }
412}
413
414func TestOpenOLT_Get_ofp_device_info(t *testing.T) {
415 type args struct {
416 device *voltha.Device
417 }
418 tests := []struct {
419 name string
420 fields *fields
421 args args
422 want *ic.SwitchCapability
423 wantErr error
424 }{
425 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{
426 Desc: &openflow_13.OfpDesc{
427 MfrDesc: "VOLTHA Project",
428 HwDesc: "open_pon",
429 SwDesc: "open_pon",
430 },
431 SwitchFeatures: &openflow_13.OfpSwitchFeatures{
432 NBuffers: uint32(256),
433 NTables: uint32(2),
434 Capabilities: uint32(15),
435 },
436 }, nil},
437 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil,
438 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
439 }
440 for _, tt := range tests {
441 t.Run(tt.name, func(t *testing.T) {
442 oo := testOltObject(tt.fields)
443 got, err := oo.Get_ofp_device_info(context.Background(), tt.args.device)
444 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
445 t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v",
446 got, tt.want, err, tt.wantErr)
447 }
448 })
449 }
450}
451
452func TestOpenOLT_Health(t *testing.T) {
453 tests := []struct {
454 name string
455 fields *fields
456 want *voltha.HealthStatus
457 wantErr error
458 }{
459 {"health-1", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
460 {"health-2", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
461 {"health-3", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
462 }
463 for _, tt := range tests {
464 t.Run(tt.name, func(t *testing.T) {
465 oo := testOltObject(tt.fields)
466 got, err := oo.Health(context.Background())
467 if err != tt.wantErr && got == nil {
468 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
469 }
470 })
471 }
472}
473
474func TestOpenOLT_Process_inter_adapter_message(t *testing.T) {
475 type args struct {
476 msg *ic.InterAdapterMessage
477 }
478 var message1 = args{
479 msg: &ic.InterAdapterMessage{
480 Header: &ic.InterAdapterHeader{
481 Id: "olt",
482 ProxyDeviceId: "",
483 ToDeviceId: "onu1",
484 },
485 },
486 }
487 var message2 = args{
488 msg: &ic.InterAdapterMessage{
489 Header: &ic.InterAdapterHeader{
490 Id: "olt",
491 ProxyDeviceId: "olt",
492 ToDeviceId: "olt",
493 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
494 },
495 },
496 }
497 var message3 = args{
498 msg: &ic.InterAdapterMessage{
499 Header: &ic.InterAdapterHeader{
500 Id: "olt",
501 ProxyDeviceId: "olt",
502 ToDeviceId: "olt",
503 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
504 },
505 },
506 }
507 tests := []struct {
508 name string
509 fields *fields
510 args args
511 wantErrType reflect.Type
512 }{
513 {"process_inter_adaptor_messgae-1", mockOlt(), message1,
514 reflect.TypeOf(&olterrors.ErrNotFound{})},
515 {"process_inter_adaptor_messgae-2", mockOlt(), message2,
516 reflect.TypeOf(&olterrors.ErrAdapter{})},
517 {"process_inter_adaptor_messgae-3", mockOlt(), message3,
518 reflect.TypeOf(&olterrors.ErrInvalidValue{})},
519 }
520 for _, tt := range tests {
521 t.Run(tt.name, func(t *testing.T) {
522 oo := testOltObject(tt.fields)
523 if err := oo.Process_inter_adapter_message(context.Background(), tt.args.msg); reflect.TypeOf(err) != tt.wantErrType {
524 t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v",
525 reflect.TypeOf(err), tt.wantErrType)
526 }
527 })
528 }
529}
530
531func TestOpenOLT_Reboot_device(t *testing.T) {
532 type args struct {
533 device *voltha.Device
534 }
535 tests := []struct {
536 name string
537 fields *fields
538 args args
539 wantErr error
540 }{
541 {"reboot_device-1", mockOlt(), args{mockDevice()}, nil},
542 {"reboot_device-2", &fields{}, args{mockDevice()},
543 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
544 }
545 for _, tt := range tests {
546 t.Run(tt.name, func(t *testing.T) {
547 oo := testOltObject(tt.fields)
548 if err := oo.Reboot_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
549 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
550 }
551 })
552 }
553}
554
555func TestOpenOLT_Receive_packet_out(t *testing.T) {
556 acts := []*ofp.OfpAction{
557 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
558 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
559 fu.Output(1),
560 }
561 type args struct {
562 deviceID string
563 egressPortNo int
564 packet *openflow_13.OfpPacketOut
565 }
566 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
567 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
568 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
569 tests := []struct {
570 name string
571 fields *fields
572 args args
573 wantErr error
574 }{
575 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil},
576 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
577 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)},
578 }
579 for _, tt := range tests {
580 t.Run(tt.name, func(t *testing.T) {
581 oo := testOltObject(tt.fields)
582 if err := oo.Receive_packet_out(context.Background(), tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); !reflect.DeepEqual(err, tt.wantErr) {
583 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
584 }
585 })
586 }
587}
588
589func TestOpenOLT_Reconcile_device(t *testing.T) {
590 type args struct {
591 device *voltha.Device
592 }
593 expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
594 tests := []struct {
595 name string
596 fields *fields
597 args args
598 wantErr error
599 }{
600 {"reconcile_device-1", &fields{}, args{}, expectedError},
601 {"reconcile_device-2", &fields{}, args{}, expectedError},
602 {"reconcile_device-3", &fields{}, args{}, expectedError},
603 }
604 for _, tt := range tests {
605 t.Run(tt.name, func(t *testing.T) {
606 oo := testOltObject(tt.fields)
607 if err := oo.Reconcile_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
608 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
609 }
610 })
611 }
612}
613
614func TestOpenOLT_Reenable_device(t *testing.T) {
615 type args struct {
616 device *voltha.Device
617 }
618 tests := []struct {
619 name string
620 fields *fields
621 args args
622 wantErr error
623 }{
624 {"reenable_device-1", mockOlt(), args{mockDevice()}, nil},
625 {"reenable_device-2", &fields{}, args{mockDevice()},
626 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
627 }
628 for _, tt := range tests {
629 t.Run(tt.name, func(t *testing.T) {
630 oo := testOltObject(tt.fields)
631 if err := oo.Reenable_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
632 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
633 }
634 })
635 }
636}
637
638func TestOpenOLT_Revert_image_update(t *testing.T) {
639 type args struct {
640 device *voltha.Device
641 request *voltha.ImageDownload
642 }
643 tests := []struct {
644 name string
645 fields *fields
646 args args
647 want *voltha.ImageDownload
648 wantErr error
649 }{
650 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
651 olterrors.ErrNotImplemented},
652 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
653 olterrors.ErrNotImplemented},
654 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
655 olterrors.ErrNotImplemented},
656 }
657 for _, tt := range tests {
658 t.Run(tt.name, func(t *testing.T) {
659 oo := testOltObject(tt.fields)
660 got, err := oo.Revert_image_update(context.Background(), tt.args.device, tt.args.request)
661 if err != tt.wantErr && got == nil {
662 t.Log("error :", err)
663 }
664 })
665 }
666}
667
668func TestOpenOLT_Self_test_device(t *testing.T) {
669 type args struct {
670 device *voltha.Device
671 }
672 tests := []struct {
673 name string
674 fields *fields
675 args args
676 wantErr error
677 }{
678 {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
679 {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
680 {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
681 }
682 for _, tt := range tests {
683 t.Run(tt.name, func(t *testing.T) {
684 oo := testOltObject(tt.fields)
685 if err := oo.Self_test_device(context.Background(), tt.args.device); err != tt.wantErr {
686 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
687 }
688 })
689 }
690}
691
692func TestOpenOLT_Start(t *testing.T) {
693 type args struct {
694 ctx context.Context
695 }
696 tests := []struct {
697 name string
698 fields *fields
699 args args
700 wantErr error
701 }{
702 {"start-1", &fields{}, args{}, errors.New("start error")},
703 }
704 for _, tt := range tests {
705 t.Run(tt.name, func(t *testing.T) {
706 oo := testOltObject(tt.fields)
707 if err := oo.Start(tt.args.ctx); err != nil {
708 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
709 }
710 })
711 }
712}
713
714func TestOpenOLT_Stop(t *testing.T) {
715 type args struct {
716 ctx context.Context
717 }
718 tests := []struct {
719 name string
720 fields *fields
721 args args
722 wantErr error
723 }{
724 {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")},
725 }
726 for _, tt := range tests {
727 t.Run(tt.name, func(t *testing.T) {
728 oo := testOltObject(tt.fields)
729 if err := oo.Start(tt.args.ctx); err != nil {
730 t.Error(err)
731 }
732 if err := oo.Stop(tt.args.ctx); err != nil {
733 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
734 }
735 })
736 }
737}
738
739func TestOpenOLT_Suppress_event(t *testing.T) {
740 type args struct {
741 filter *voltha.EventFilter
742 }
743 tests := []struct {
744 name string
745 fields *fields
746 args args
747 wantErr error
748 }{
749 {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
750 {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
751 {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
752 }
753 for _, tt := range tests {
754 t.Run(tt.name, func(t *testing.T) {
755 oo := testOltObject(tt.fields)
756 if err := oo.Suppress_event(context.Background(), tt.args.filter); err != tt.wantErr {
757 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
758 }
759 })
760 }
761}
762
763func TestOpenOLT_Unsuppress_event(t *testing.T) {
764 type args struct {
765 filter *voltha.EventFilter
766 }
767 tests := []struct {
768 name string
769 fields *fields
770 args args
771 wantErr error
772 }{
773 {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
774 {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
775 {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
776 }
777 for _, tt := range tests {
778 t.Run(tt.name, func(t *testing.T) {
779 oo := testOltObject(tt.fields)
780 if err := oo.Unsuppress_event(context.Background(), tt.args.filter); err != tt.wantErr {
781 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
782 }
783 })
784 }
785}
786
787func TestOpenOLT_Update_flows_bulk(t *testing.T) {
788 type args struct {
789 device *voltha.Device
790 flows *voltha.Flows
791 groups *voltha.FlowGroups
792 flowMetadata *voltha.FlowMetadata
793 }
794 tests := []struct {
795 name string
796 fields *fields
797 args args
798 wantErr error
799 }{
800 {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented},
801 {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented},
802 {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented},
803 }
804 for _, tt := range tests {
805 t.Run(tt.name, func(t *testing.T) {
806 oo := testOltObject(tt.fields)
807 if err := oo.Update_flows_bulk(context.Background(), tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); err != tt.wantErr {
808 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
809 }
810 })
811 }
812}
813
814func TestOpenOLT_Update_flows_incrementally(t *testing.T) {
815 type args struct {
816 device *voltha.Device
817 flows *openflow_13.FlowChanges
818 groups *openflow_13.FlowGroupChanges
819 flowMetadata *voltha.FlowMetadata
820 }
821
822 tests := []struct {
823 name string
824 fields *fields
825 args args
826 wantErr error
827 }{
828 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
829 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
830 {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil},
831 }
832 for _, tt := range tests {
833 t.Run(tt.name, func(t *testing.T) {
834 oo := testOltObject(tt.fields)
835 if err := oo.Update_flows_incrementally(context.Background(), tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); !reflect.DeepEqual(err, tt.wantErr) {
836 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
837 }
838 })
839 }
840}
841
842func TestOpenOLT_Update_pm_config(t *testing.T) {
843 type args struct {
844 device *voltha.Device
845 pmConfigs *voltha.PmConfigs
846 }
847 tests := []struct {
848 name string
849 fields *fields
850 args args
851 wantErr error
852 }{
853 {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil},
854 {"update_pm_config-2", &fields{}, args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
855 }
856 for _, tt := range tests {
857 t.Run(tt.name, func(t *testing.T) {
858 oo := testOltObject(tt.fields)
859
860 if err := oo.Update_pm_config(context.Background(), tt.args.device, tt.args.pmConfigs); !reflect.DeepEqual(err, tt.wantErr) {
861 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
862 }
863
864 })
865 }
866}
867
868func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
869 type args struct {
870 agent *DeviceHandler
871 }
872 tests := []struct {
873 name string
874 fields *fields
875 args args
876 }{
877 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
878 }
879 for _, tt := range tests {
880 t.Run(tt.name, func(t *testing.T) {
881 oo := testOltObject(tt.fields)
882 oo.deleteDeviceHandlerToMap(tt.args.agent)
883 if len(oo.deviceHandlers) > 0 {
884 t.Errorf("delete device manager failed")
885 }
886 })
887 }
888}
889
890func TestOpenOLT_Enable_port(t *testing.T) {
891 type args struct {
892 deviceID string
893 port *voltha.Port
894 }
895 tests := []struct {
896 name string
897 fields *fields
898 args args
899 wantErr bool
900 }{
901 // TODO: Add test cases.
902 {"Enable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
903 {"Enable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
904 }
905 for _, tt := range tests {
906 t.Run(tt.name, func(t *testing.T) {
907 oo := testOltObject(tt.fields)
908 if err := oo.Enable_port(context.Background(), tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
909 t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr)
910 }
911 })
912 }
913}
914
915func TestOpenOLT_Disable_port(t *testing.T) {
916 type args struct {
917 deviceID string
918 port *voltha.Port
919 }
920 tests := []struct {
921 name string
922 fields *fields
923 args args
924 wantErr bool
925 }{
926 // TODO: Add test cases.
927 {"Disable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
928 {"Disable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
929 }
930 for _, tt := range tests {
931 t.Run(tt.name, func(t *testing.T) {
932 oo := testOltObject(tt.fields)
933 if err := oo.Disable_port(context.Background(), tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
934 t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr)
935 }
936 })
937 }
938}