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