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