blob: bf4aa9a544d25ad79dfd82fd7e80cedd2055a03e [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
Scott Bakerdbd960e2020-02-28 08:57:51 -080022//Package core provides the utility for olt devices, flows and statistics
23package core
cbabua9e04cc2019-10-03 12:35:45 +053024
25import (
26 "context"
27 "errors"
Matteo Scandolodfa7a972020-11-06 13:03:40 -080028 conf "github.com/opencord/voltha-lib-go/v4/pkg/config"
Kent Hagermanf1db18b2020-07-08 13:38:15 -040029 "reflect"
Kent Hagermanf1db18b2020-07-08 13:38:15 -040030 "testing"
31
Girish Gowdraa09aeab2020-09-14 16:30:52 -070032 com "github.com/opencord/voltha-lib-go/v4/pkg/adapters/common"
Himani Chawlacd407802020-12-10 12:08:59 +053033 "github.com/opencord/voltha-lib-go/v4/pkg/events"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070034 fu "github.com/opencord/voltha-lib-go/v4/pkg/flows"
35 "github.com/opencord/voltha-lib-go/v4/pkg/kafka"
36 "github.com/opencord/voltha-lib-go/v4/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080037 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053038 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070039 ic "github.com/opencord/voltha-protos/v4/go/inter_container"
40 "github.com/opencord/voltha-protos/v4/go/openflow_13"
41 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
42 "github.com/opencord/voltha-protos/v4/go/voltha"
cbabua9e04cc2019-10-03 12:35:45 +053043)
44
cbabubef89432019-10-18 11:47:27 +020045// mocks the OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053046type fields struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -040047 deviceHandlers map[string]*DeviceHandler
48 coreProxy *com.CoreProxy
49 adapterProxy *com.AdapterProxy
Himani Chawlacd407802020-12-10 12:08:59 +053050 eventProxy *events.EventProxy
Kent Hagermane6ff1012020-07-14 15:07:53 -040051 kafkaICProxy kafka.InterContainerProxy
52 numOnus int
53 KVStoreAddress string
54 KVStoreType string
55 exitChannel chan int
56 ctx context.Context
cbabua9e04cc2019-10-03 12:35:45 +053057}
58
cbabubef89432019-10-18 11:47:27 +020059// mockOlt mocks OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053060func mockOlt() *fields {
cbabua9e04cc2019-10-03 12:35:45 +053061 dh := newMockDeviceHandler()
62 newOlt := &fields{}
63 newOlt.deviceHandlers = map[string]*DeviceHandler{}
64 newOlt.deviceHandlers[dh.device.Id] = dh
65 return newOlt
66}
67
cbabubef89432019-10-18 11:47:27 +020068// testOltObject maps fields type to OpenOLt type.
cbabua9e04cc2019-10-03 12:35:45 +053069func testOltObject(testOlt *fields) *OpenOLT {
70 return &OpenOLT{
71 deviceHandlers: testOlt.deviceHandlers,
72 coreProxy: testOlt.coreProxy,
73 adapterProxy: testOlt.adapterProxy,
74 eventProxy: testOlt.eventProxy,
75 kafkaICProxy: testOlt.kafkaICProxy,
76 numOnus: testOlt.numOnus,
Neha Sharma3f221ae2020-04-29 19:02:12 +000077 KVStoreAddress: testOlt.KVStoreAddress,
cbabua9e04cc2019-10-03 12:35:45 +053078 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 {
Kent Hagermanf1db18b2020-07-08 13:38:15 -040085 return &voltha.Device{
cbabua9e04cc2019-10-03 12:35:45 +053086 Id: "olt",
87 Root: true,
88 ParentId: "logical_device",
cbabua9e04cc2019-10-03 12:35:45 +053089 ProxyAddress: &voltha.Device_ProxyAddress{
90 DeviceId: "olt",
91 DeviceType: "onu",
92 ChannelId: 1,
93 ChannelGroupId: 1,
94 },
95 ConnectStatus: 1,
96 }
cbabua9e04cc2019-10-03 12:35:45 +053097}
98
99func TestNewOpenOLT(t *testing.T) {
100 tests := []struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530101 name string
102 fields *fields
103 configFlags *config.AdapterFlags
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800104 cm *conf.ConfigManager
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530105 want *OpenOLT
cbabua9e04cc2019-10-03 12:35:45 +0530106 }{
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800107 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}, &conf.ConfigManager{},
Neha Sharma3f221ae2020-04-29 19:02:12 +0000108 &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}},
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800109 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}, &conf.ConfigManager{},
Neha Sharma3f221ae2020-04-29 19:02:12 +0000110 &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}},
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800111 {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}, &conf.ConfigManager{},
Neha Sharma3f221ae2020-04-29 19:02:12 +0000112 &OpenOLT{numOnus: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}},
cbabua9e04cc2019-10-03 12:35:45 +0530113 }
114 for _, tt := range tests {
115 t.Run(tt.name, func(t *testing.T) {
116 if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy,
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800117 tt.fields.eventProxy, tt.configFlags, tt.cm); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
cbabua9e04cc2019-10-03 12:35:45 +0530118 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
119 }
120 })
121 }
122}
123
124func TestOpenOLT_Abandon_device(t *testing.T) {
125 type args struct {
126 device *voltha.Device
127 }
128 tests := []struct {
129 name string
130 fields *fields
131 args args
132 wantErr error
133 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530134 {"abandon_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
135 {"abandon_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
136 {"abandon_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530137 }
138 for _, tt := range tests {
139 t.Run(tt.name, func(t *testing.T) {
140 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000141 if err := oo.Abandon_device(context.Background(), tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530142 t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr)
143 }
144 })
145 }
146}
147
148func TestOpenOLT_Activate_image_update(t *testing.T) {
149 type args struct {
150 device *voltha.Device
151 request *voltha.ImageDownload
152 }
153 tests := []struct {
154 name string
155 fields *fields
156 args args
157 want *voltha.ImageDownload
158 wantErr error
159 }{
160 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530161 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530162 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530163 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530164 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530165 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530166 }
167 for _, tt := range tests {
168 t.Run(tt.name, func(t *testing.T) {
169 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 got, err := oo.Activate_image_update(context.Background(), tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800171 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530172 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
173 }
174 })
175 }
176}
177
178func TestOpenOLT_Adapter_descriptor(t *testing.T) {
179 tests := []struct {
180 name string
181 fields *fields
182 wantErr error
183 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530184 {"adapter_descriptor-1", &fields{}, olterrors.ErrNotImplemented},
185 {"adapter_descriptor-2", &fields{}, olterrors.ErrNotImplemented},
186 {"adapter_descriptor-3", &fields{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530187 }
188 for _, tt := range tests {
189 t.Run(tt.name, func(t *testing.T) {
190 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000191 if err := oo.Adapter_descriptor(context.Background()); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530192 t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr)
193 }
194 })
195 }
196}
197
198func TestOpenOLT_Adopt_device(t *testing.T) {
199 type args struct {
200 device *voltha.Device
201 }
202 var device = mockDevice()
kesavand39e0aa32020-01-28 20:58:50 -0500203 device.Id = "olt"
Thomas Lee S94109f12020-03-03 16:39:29 +0530204 nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530205 tests := []struct {
206 name string
207 fields *fields
208 args args
209 wantErr error
210 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800211 {"adopt_device-1", mockOlt(), args{}, nilDevice},
212 {"adopt_device-2", mockOlt(), args{device}, nilDevice},
213 {"adopt_device-3", mockOlt(), args{mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530214 }
215 for _, tt := range tests {
216 t.Run(tt.name, func(t *testing.T) {
217 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000218 err := oo.Adopt_device(context.Background(), tt.args.device)
cbabua9e04cc2019-10-03 12:35:45 +0530219 if (err != nil) && (reflect.TypeOf(err) !=
220 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
221 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
222 }
223 if err == nil {
224 t.Log("return'd nil")
225 }
226 })
227 }
228}
229
230func TestOpenOLT_Cancel_image_download(t *testing.T) {
231 type args struct {
232 device *voltha.Device
233 request *voltha.ImageDownload
234 }
235 tests := []struct {
236 name string
237 fields *fields
238 args args
239 want *voltha.ImageDownload
240 wantErr error
241 }{
242 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530243 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530244 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530245 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530246 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530247 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530248 }
249 for _, tt := range tests {
250 t.Run(tt.name, func(t *testing.T) {
251 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000252 got, err := oo.Cancel_image_download(context.Background(), tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800253 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530254 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
255 }
256 })
257 }
258}
259
260func TestOpenOLT_Delete_device(t *testing.T) {
261 type args struct {
262 device *voltha.Device
263 }
264 tests := []struct {
265 name string
266 fields *fields
267 args args
268 wantErr error
269 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800270 {"delete_device-1", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530271 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530272 }
273 for _, tt := range tests {
274 t.Run(tt.name, func(t *testing.T) {
275 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000276 if err := oo.Delete_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530277 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
278 }
279 })
280 }
281}
282
283func TestOpenOLT_Device_types(t *testing.T) {
284 tests := []struct {
285 name string
286 fields *fields
287 want *voltha.DeviceTypes
288 wantErr error
289 }{
290 {"device_types-1", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530291 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530292 {"device_types-2", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530293 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530294 {"device_types-3", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530295 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530296 }
297 for _, tt := range tests {
298 t.Run(tt.name, func(t *testing.T) {
299 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000300 got, err := oo.Device_types(context.Background())
David K. Bainbridge794735f2020-02-11 21:01:37 -0800301 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530302 t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr)
303 }
304 })
305 }
306}
307
308func TestOpenOLT_Disable_device(t *testing.T) {
309 type args struct {
310 device *voltha.Device
311 }
312 tests := []struct {
313 name string
314 fields *fields
315 args args
316 wantErr error
317 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800318 {"disable_device-1", mockOlt(), args{mockDevice()}, nil},
319 {"disable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530320 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530321 }
322 for _, tt := range tests {
323 t.Run(tt.name, func(t *testing.T) {
324 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000325 if err := oo.Disable_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530326 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
327 }
328 })
329 }
330}
331
332func TestOpenOLT_Download_image(t *testing.T) {
333 type args struct {
334 device *voltha.Device
335 request *voltha.ImageDownload
336 }
337 tests := []struct {
338 name string
339 fields *fields
340 args args
341 want *voltha.ImageDownload
342 wantErr error
343 }{
344 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530345 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530346 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530347 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530348 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530349 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530350 }
351 for _, tt := range tests {
352 t.Run(tt.name, func(t *testing.T) {
353 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000354 got, err := oo.Download_image(context.Background(), tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800355 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530356 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
357 }
358 })
359 }
360}
361
362func TestOpenOLT_Get_device_details(t *testing.T) {
363 type args struct {
364 device *voltha.Device
365 }
366 tests := []struct {
367 name string
368 fields *fields
369 args args
370 wantErr error
371 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530372 {"get_device_details-1", &fields{}, args{}, olterrors.ErrNotImplemented},
373 {"get_device_details-2", &fields{}, args{}, olterrors.ErrNotImplemented},
374 {"get_device_details-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530375 }
376 for _, tt := range tests {
377 t.Run(tt.name, func(t *testing.T) {
378 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000379 if err := oo.Get_device_details(context.Background(), tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530380 t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr)
381 }
382 })
383 }
384}
385
386func TestOpenOLT_Get_image_download_status(t *testing.T) {
387 type args struct {
388 device *voltha.Device
389 request *voltha.ImageDownload
390 }
391 tests := []struct {
392 name string
393 fields *fields
394 args args
395 want *voltha.ImageDownload
396 wantErr error
397 }{
398 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530399 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530400 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530401 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530402 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530403 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530404 }
405 for _, tt := range tests {
406 t.Run(tt.name, func(t *testing.T) {
407 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000408 got, err := oo.Get_image_download_status(context.Background(), tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800409 if err != tt.wantErr && got == nil {
410 t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v",
411 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530412 }
413 })
414 }
415}
416
417func TestOpenOLT_Get_ofp_device_info(t *testing.T) {
418 type args struct {
419 device *voltha.Device
420 }
421 tests := []struct {
422 name string
423 fields *fields
424 args args
425 want *ic.SwitchCapability
426 wantErr error
427 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800428 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{
429 Desc: &openflow_13.OfpDesc{
430 MfrDesc: "VOLTHA Project",
431 HwDesc: "open_pon",
432 SwDesc: "open_pon",
433 },
434 SwitchFeatures: &openflow_13.OfpSwitchFeatures{
435 NBuffers: uint32(256),
436 NTables: uint32(2),
437 Capabilities: uint32(15),
438 },
439 }, nil},
440 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530441 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530442 }
443 for _, tt := range tests {
444 t.Run(tt.name, func(t *testing.T) {
445 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000446 got, err := oo.Get_ofp_device_info(context.Background(), tt.args.device)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800447 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
448 t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v",
449 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530450 }
451 })
452 }
453}
454
cbabua9e04cc2019-10-03 12:35:45 +0530455func TestOpenOLT_Health(t *testing.T) {
456 tests := []struct {
457 name string
458 fields *fields
459 want *voltha.HealthStatus
460 wantErr error
461 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530462 {"health-1", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
463 {"health-2", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
464 {"health-3", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530465 }
466 for _, tt := range tests {
467 t.Run(tt.name, func(t *testing.T) {
468 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000469 got, err := oo.Health(context.Background())
David K. Bainbridge794735f2020-02-11 21:01:37 -0800470 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530471 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
472 }
473 })
474 }
475}
476
477func TestOpenOLT_Process_inter_adapter_message(t *testing.T) {
478 type args struct {
479 msg *ic.InterAdapterMessage
480 }
481 var message1 = args{
482 msg: &ic.InterAdapterMessage{
483 Header: &ic.InterAdapterHeader{
484 Id: "olt",
485 ProxyDeviceId: "",
486 ToDeviceId: "onu1",
487 },
488 },
489 }
490 var message2 = args{
491 msg: &ic.InterAdapterMessage{
492 Header: &ic.InterAdapterHeader{
493 Id: "olt",
494 ProxyDeviceId: "olt",
495 ToDeviceId: "olt",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800496 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
497 },
498 },
499 }
500 var message3 = args{
501 msg: &ic.InterAdapterMessage{
502 Header: &ic.InterAdapterHeader{
503 Id: "olt",
504 ProxyDeviceId: "olt",
505 ToDeviceId: "olt",
506 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
cbabua9e04cc2019-10-03 12:35:45 +0530507 },
508 },
509 }
510 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800511 name string
512 fields *fields
513 args args
514 wantErrType reflect.Type
cbabua9e04cc2019-10-03 12:35:45 +0530515 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800516 {"process_inter_adaptor_messgae-1", mockOlt(), message1,
Thomas Lee S94109f12020-03-03 16:39:29 +0530517 reflect.TypeOf(&olterrors.ErrNotFound{})},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800518 {"process_inter_adaptor_messgae-2", mockOlt(), message2,
Girish Kumarf26e4882020-03-05 06:49:10 +0000519 reflect.TypeOf(&olterrors.ErrAdapter{})},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800520 {"process_inter_adaptor_messgae-3", mockOlt(), message3,
Thomas Lee S94109f12020-03-03 16:39:29 +0530521 reflect.TypeOf(&olterrors.ErrInvalidValue{})},
cbabua9e04cc2019-10-03 12:35:45 +0530522 }
523 for _, tt := range tests {
524 t.Run(tt.name, func(t *testing.T) {
525 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000526 if err := oo.Process_inter_adapter_message(context.Background(), tt.args.msg); reflect.TypeOf(err) != tt.wantErrType {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800527 t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v",
528 reflect.TypeOf(err), tt.wantErrType)
cbabua9e04cc2019-10-03 12:35:45 +0530529 }
530 })
531 }
532}
533
534func TestOpenOLT_Reboot_device(t *testing.T) {
535 type args struct {
536 device *voltha.Device
537 }
538 tests := []struct {
539 name string
540 fields *fields
541 args args
542 wantErr error
543 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800544 {"reboot_device-1", mockOlt(), args{mockDevice()}, nil},
545 {"reboot_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530546 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530547 }
548 for _, tt := range tests {
549 t.Run(tt.name, func(t *testing.T) {
550 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000551 if err := oo.Reboot_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530552 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
553 }
554 })
555 }
556}
557
558func TestOpenOLT_Receive_packet_out(t *testing.T) {
559 acts := []*ofp.OfpAction{
560 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
561 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
562 fu.Output(1),
563 }
564 type args struct {
565 deviceID string
566 egressPortNo int
567 packet *openflow_13.OfpPacketOut
568 }
569 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
570 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
571 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
572 tests := []struct {
573 name string
574 fields *fields
575 args args
576 wantErr error
577 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800578 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530579 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
Thomas Lee S94109f12020-03-03 16:39:29 +0530580 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530581 }
582 for _, tt := range tests {
583 t.Run(tt.name, func(t *testing.T) {
584 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000585 if err := oo.Receive_packet_out(context.Background(), tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530586 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
587 }
588 })
589 }
590}
591
592func TestOpenOLT_Reconcile_device(t *testing.T) {
593 type args struct {
594 device *voltha.Device
595 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530596 expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530597 tests := []struct {
598 name string
599 fields *fields
600 args args
601 wantErr error
602 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800603 {"reconcile_device-1", &fields{}, args{}, expectedError},
604 {"reconcile_device-2", &fields{}, args{}, expectedError},
605 {"reconcile_device-3", &fields{}, args{}, expectedError},
cbabua9e04cc2019-10-03 12:35:45 +0530606 }
607 for _, tt := range tests {
608 t.Run(tt.name, func(t *testing.T) {
609 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000610 if err := oo.Reconcile_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530611 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
612 }
613 })
614 }
615}
616
617func TestOpenOLT_Reenable_device(t *testing.T) {
618 type args struct {
619 device *voltha.Device
620 }
621 tests := []struct {
622 name string
623 fields *fields
624 args args
625 wantErr error
626 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800627 {"reenable_device-1", mockOlt(), args{mockDevice()}, nil},
628 {"reenable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530629 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530630 }
631 for _, tt := range tests {
632 t.Run(tt.name, func(t *testing.T) {
633 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000634 if err := oo.Reenable_device(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530635 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
636 }
637 })
638 }
639}
640
641func TestOpenOLT_Revert_image_update(t *testing.T) {
642 type args struct {
643 device *voltha.Device
644 request *voltha.ImageDownload
645 }
646 tests := []struct {
647 name string
648 fields *fields
649 args args
650 want *voltha.ImageDownload
651 wantErr error
652 }{
653 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530654 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530655 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530656 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530657 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530658 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530659 }
660 for _, tt := range tests {
661 t.Run(tt.name, func(t *testing.T) {
662 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000663 got, err := oo.Revert_image_update(context.Background(), tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800664 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530665 t.Log("error :", err)
666 }
667 })
668 }
669}
670
671func TestOpenOLT_Self_test_device(t *testing.T) {
672 type args struct {
673 device *voltha.Device
674 }
675 tests := []struct {
676 name string
677 fields *fields
678 args args
679 wantErr error
680 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530681 {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
682 {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
683 {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530684 }
685 for _, tt := range tests {
686 t.Run(tt.name, func(t *testing.T) {
687 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000688 if err := oo.Self_test_device(context.Background(), tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530689 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
690 }
691 })
692 }
693}
694
695func TestOpenOLT_Start(t *testing.T) {
696 type args struct {
697 ctx context.Context
698 }
699 tests := []struct {
700 name string
701 fields *fields
702 args args
703 wantErr error
704 }{
705 {"start-1", &fields{}, args{}, errors.New("start error")},
706 }
707 for _, tt := range tests {
708 t.Run(tt.name, func(t *testing.T) {
709 oo := testOltObject(tt.fields)
710 if err := oo.Start(tt.args.ctx); err != nil {
711 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
712 }
713 })
714 }
715}
716
717func TestOpenOLT_Stop(t *testing.T) {
718 type args struct {
719 ctx context.Context
720 }
721 tests := []struct {
722 name string
723 fields *fields
724 args args
725 wantErr error
726 }{
727 {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")},
728 }
729 for _, tt := range tests {
730 t.Run(tt.name, func(t *testing.T) {
731 oo := testOltObject(tt.fields)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400732 if err := oo.Start(tt.args.ctx); err != nil {
733 t.Error(err)
734 }
cbabua9e04cc2019-10-03 12:35:45 +0530735 if err := oo.Stop(tt.args.ctx); err != nil {
736 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
737 }
738 })
739 }
740}
741
Devmalya Pauldd23a992019-11-14 07:06:31 +0000742func TestOpenOLT_Suppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530743 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000744 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530745 }
746 tests := []struct {
747 name string
748 fields *fields
749 args args
750 wantErr error
751 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530752 {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
753 {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
754 {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530755 }
756 for _, tt := range tests {
757 t.Run(tt.name, func(t *testing.T) {
758 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000759 if err := oo.Suppress_event(context.Background(), tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000760 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530761 }
762 })
763 }
764}
765
Devmalya Pauldd23a992019-11-14 07:06:31 +0000766func TestOpenOLT_Unsuppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530767 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000768 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530769 }
770 tests := []struct {
771 name string
772 fields *fields
773 args args
774 wantErr error
775 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530776 {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
777 {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
778 {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530779 }
780 for _, tt := range tests {
781 t.Run(tt.name, func(t *testing.T) {
782 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000783 if err := oo.Unsuppress_event(context.Background(), tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000784 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530785 }
786 })
787 }
788}
789
790func TestOpenOLT_Update_flows_bulk(t *testing.T) {
791 type args struct {
792 device *voltha.Device
793 flows *voltha.Flows
794 groups *voltha.FlowGroups
795 flowMetadata *voltha.FlowMetadata
796 }
797 tests := []struct {
798 name string
799 fields *fields
800 args args
801 wantErr error
802 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530803 {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented},
804 {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented},
805 {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530806 }
807 for _, tt := range tests {
808 t.Run(tt.name, func(t *testing.T) {
809 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000810 if err := oo.Update_flows_bulk(context.Background(), tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530811 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
812 }
813 })
814 }
815}
816
817func TestOpenOLT_Update_flows_incrementally(t *testing.T) {
818 type args struct {
819 device *voltha.Device
820 flows *openflow_13.FlowChanges
821 groups *openflow_13.FlowGroupChanges
822 flowMetadata *voltha.FlowMetadata
823 }
824
825 tests := []struct {
826 name string
827 fields *fields
828 args args
829 wantErr error
830 }{
831 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530832 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800833 {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530834 }
835 for _, tt := range tests {
836 t.Run(tt.name, func(t *testing.T) {
837 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000838 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) {
cbabua9e04cc2019-10-03 12:35:45 +0530839 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
840 }
841 })
842 }
843}
844
845func TestOpenOLT_Update_pm_config(t *testing.T) {
846 type args struct {
847 device *voltha.Device
848 pmConfigs *voltha.PmConfigs
849 }
850 tests := []struct {
851 name string
852 fields *fields
853 args args
854 wantErr error
855 }{
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000856 {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil},
857 {"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)},
cbabua9e04cc2019-10-03 12:35:45 +0530858 }
859 for _, tt := range tests {
860 t.Run(tt.name, func(t *testing.T) {
861 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000862
863 if err := oo.Update_pm_config(context.Background(), tt.args.device, tt.args.pmConfigs); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530864 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
865 }
866
867 })
868 }
869}
870
871func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
872 type args struct {
873 agent *DeviceHandler
874 }
875 tests := []struct {
876 name string
877 fields *fields
878 args args
879 }{
880 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
881 }
882 for _, tt := range tests {
883 t.Run(tt.name, func(t *testing.T) {
884 oo := testOltObject(tt.fields)
885 oo.deleteDeviceHandlerToMap(tt.args.agent)
886 if len(oo.deviceHandlers) > 0 {
887 t.Errorf("delete device manager failed")
888 }
889 })
890 }
891}
kesavand39e0aa32020-01-28 20:58:50 -0500892
893func TestOpenOLT_Enable_port(t *testing.T) {
894 type args struct {
895 deviceID string
896 port *voltha.Port
897 }
898 tests := []struct {
899 name string
900 fields *fields
901 args args
902 wantErr bool
903 }{
904 // TODO: Add test cases.
905 {"Enable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
906 {"Enable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
907 }
908 for _, tt := range tests {
909 t.Run(tt.name, func(t *testing.T) {
910 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000911 if err := oo.Enable_port(context.Background(), tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
kesavand39e0aa32020-01-28 20:58:50 -0500912 t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr)
913 }
914 })
915 }
916}
917
918func TestOpenOLT_Disable_port(t *testing.T) {
919 type args struct {
920 deviceID string
921 port *voltha.Port
922 }
923 tests := []struct {
924 name string
925 fields *fields
926 args args
927 wantErr bool
928 }{
929 // TODO: Add test cases.
930 {"Disable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
931 {"Disable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
932 }
933 for _, tt := range tests {
934 t.Run(tt.name, func(t *testing.T) {
935 oo := testOltObject(tt.fields)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000936 if err := oo.Disable_port(context.Background(), tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
kesavand39e0aa32020-01-28 20:58:50 -0500937 t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr)
938 }
939 })
940 }
941}