vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/json" |
| 21 | "net" |
| 22 | "reflect" |
| 23 | "sync" |
| 24 | "testing" |
| 25 | "voltha-go-controller/internal/pkg/controller" |
| 26 | "voltha-go-controller/internal/pkg/intf" |
| 27 | "voltha-go-controller/internal/pkg/of" |
| 28 | "voltha-go-controller/internal/pkg/util" |
| 29 | "voltha-go-controller/internal/test/mocks" |
| 30 | |
| 31 | "github.com/golang/mock/gomock" |
| 32 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 33 | "github.com/stretchr/testify/assert" |
| 34 | "go.uber.org/atomic" |
| 35 | ) |
| 36 | |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 37 | var test_data = "1234" |
| 38 | |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 39 | func TestVoltApplication_RestoreNbDeviceFromDb(t *testing.T) { |
| 40 | type args struct { |
| 41 | cntx context.Context |
| 42 | deviceID string |
| 43 | } |
| 44 | tests := []struct { |
| 45 | name string |
| 46 | args args |
| 47 | }{ |
| 48 | { |
| 49 | name: "VoltApplication_RestoreNbDeviceFromDb", |
| 50 | args: args{ |
| 51 | cntx: context.Background(), |
| 52 | deviceID: "test_device_id", |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type", |
| 57 | args: args{ |
| 58 | cntx: context.Background(), |
| 59 | deviceID: "test_device_id1", |
| 60 | }, |
| 61 | }, |
| 62 | { |
| 63 | name: "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error", |
| 64 | args: args{ |
| 65 | cntx: context.Background(), |
| 66 | deviceID: "test_device_id1", |
| 67 | }, |
| 68 | }, |
| 69 | } |
| 70 | for _, tt := range tests { |
| 71 | t.Run(tt.name, func(t *testing.T) { |
| 72 | va := &VoltApplication{ |
| 73 | NbDevice: sync.Map{}, |
| 74 | } |
| 75 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 76 | db = dbintf |
| 77 | switch tt.name { |
| 78 | case "VoltApplication_RestoreNbDeviceFromDb": |
| 79 | var port PonPortCfg |
| 80 | port = PonPortCfg{ |
| 81 | PortAlarmProfileID: "test", |
| 82 | PortID: 256, |
| 83 | MaxActiveChannels: 256, |
| 84 | ActiveIGMPChannels: 7679, |
| 85 | EnableMulticastKPI: false, |
| 86 | } |
| 87 | b, err := json.Marshal(port) |
| 88 | if err != nil { |
| 89 | panic(err) |
| 90 | } |
| 91 | test := map[string]*kvstore.KVPair{} |
| 92 | test["test_device_id"] = &kvstore.KVPair{ |
| 93 | Key: "test_device_id", |
| 94 | Value: b, |
| 95 | } |
| 96 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 97 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 98 | assert.NotNil(t, got) |
| 99 | case "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type": |
| 100 | test := map[string]*kvstore.KVPair{} |
| 101 | test["test_device_id"] = &kvstore.KVPair{ |
| 102 | Key: "test_device_id", |
| 103 | Value: "invalid_value", |
| 104 | } |
| 105 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 106 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 107 | assert.NotNil(t, got) |
| 108 | case "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error": |
| 109 | b, err := json.Marshal("error") |
| 110 | if err != nil { |
| 111 | panic(err) |
| 112 | } |
| 113 | test := map[string]*kvstore.KVPair{} |
| 114 | test["test_device_id"] = &kvstore.KVPair{ |
| 115 | Key: "test_device_id", |
| 116 | Value: b, |
| 117 | } |
| 118 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 119 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 120 | assert.NotNil(t, got) |
| 121 | } |
| 122 | }) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestVoltApplication_UpdateDeviceConfig(t *testing.T) { |
| 127 | type args struct { |
| 128 | cntx context.Context |
| 129 | deviceConfig *DeviceConfig |
| 130 | } |
| 131 | |
| 132 | dvcConfg := &DeviceConfig{ |
| 133 | SerialNumber: "SDX6320031", |
| 134 | HardwareIdentifier: "0.0.0.0", |
| 135 | IPAddress: "127.26.1.74", |
| 136 | UplinkPort: "43322", |
| 137 | NasID: "12345", |
| 138 | NniDhcpTrapVid: 123, |
| 139 | } |
| 140 | |
| 141 | voltDev := &VoltDevice{ |
| 142 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 143 | SerialNum: "SDX6320031", |
| 144 | NniDhcpTrapVid: 123, |
| 145 | } |
| 146 | tests := []struct { |
| 147 | name string |
| 148 | args args |
| 149 | }{ |
| 150 | { |
| 151 | name: "SDX6320031", |
| 152 | args: args{ |
| 153 | cntx: context.Background(), |
| 154 | deviceConfig: dvcConfg, |
| 155 | }, |
| 156 | }, |
| 157 | } |
| 158 | |
| 159 | for _, tt := range tests { |
| 160 | t.Run(tt.name, func(t *testing.T) { |
| 161 | va := &VoltApplication{ |
| 162 | DevicesDisc: sync.Map{}, |
| 163 | DevicesConfig: sync.Map{}, |
| 164 | } |
| 165 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 166 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 167 | db = dbintf |
| 168 | dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 169 | |
| 170 | va.UpdateDeviceConfig(tt.args.cntx, tt.args.deviceConfig) |
| 171 | }) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func TestVoltApplication_RestoreOltFlowService(t *testing.T) { |
| 176 | type fields struct { |
| 177 | OltFlowServiceConfig OltFlowService |
| 178 | } |
| 179 | type args struct { |
| 180 | cntx context.Context |
| 181 | } |
| 182 | tests := []struct { |
| 183 | name string |
| 184 | fields fields |
| 185 | args args |
| 186 | }{ |
| 187 | { |
| 188 | name: "OltFlowService", |
| 189 | args: args{ |
| 190 | cntx: context.Background(), |
| 191 | }, |
| 192 | fields: fields{ |
| 193 | OltFlowServiceConfig: OltFlowService{ |
| 194 | DefaultTechProfileID: 1233, |
| 195 | EnableDhcpOnNni: true, |
| 196 | EnableIgmpOnNni: false, |
| 197 | RemoveFlowsOnDisable: false, |
| 198 | }, |
| 199 | }, |
| 200 | }, |
| 201 | } |
| 202 | for _, tt := range tests { |
| 203 | t.Run(tt.name, func(t *testing.T) { |
| 204 | va := &VoltApplication{ |
| 205 | OltFlowServiceConfig: tt.fields.OltFlowServiceConfig, |
| 206 | } |
| 207 | |
| 208 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 209 | db = dbintf |
| 210 | dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes() |
| 211 | |
| 212 | va.RestoreOltFlowService(tt.args.cntx) |
| 213 | }) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func TestVoltApplication_UpdateOltFlowService(t *testing.T) { |
| 218 | type fields struct { |
| 219 | OltFlowServiceConfig OltFlowService |
| 220 | } |
| 221 | type args struct { |
| 222 | cntx context.Context |
| 223 | oltFlowService OltFlowService |
| 224 | } |
| 225 | tests := []struct { |
| 226 | name string |
| 227 | fields fields |
| 228 | args args |
| 229 | }{ |
| 230 | { |
| 231 | name: "OltFlowService", |
| 232 | args: args{ |
| 233 | cntx: context.Background(), |
| 234 | oltFlowService: OltFlowService{ |
| 235 | DefaultTechProfileID: 1233, |
| 236 | EnableDhcpOnNni: true, |
| 237 | EnableIgmpOnNni: false, |
| 238 | RemoveFlowsOnDisable: false, |
| 239 | }, |
| 240 | }, |
| 241 | fields: fields{ |
| 242 | OltFlowServiceConfig: OltFlowService{ |
| 243 | DefaultTechProfileID: 1233, |
| 244 | EnableDhcpOnNni: true, |
| 245 | EnableIgmpOnNni: false, |
| 246 | RemoveFlowsOnDisable: false, |
| 247 | }, |
| 248 | }, |
| 249 | }, |
| 250 | } |
| 251 | for _, tt := range tests { |
| 252 | t.Run(tt.name, func(t *testing.T) { |
| 253 | va := &VoltApplication{ |
| 254 | OltFlowServiceConfig: tt.fields.OltFlowServiceConfig, |
| 255 | } |
| 256 | |
| 257 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 258 | db = dbintf |
| 259 | dbintf.EXPECT().PutOltFlowService(gomock.Any(), gomock.Any()).AnyTimes() |
| 260 | va.UpdateOltFlowService(tt.args.cntx, tt.args.oltFlowService) |
| 261 | }) |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | func TestVoltApplication_TriggerPendingVpvDeleteReq(t *testing.T) { |
| 266 | type args struct { |
| 267 | cntx context.Context |
| 268 | device string |
| 269 | } |
| 270 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 271 | test := map[*VoltPortVnet]bool{} |
| 272 | test[&VoltPortVnet{Device: "SDX6320031", Port: "16777472", MacAddr: macAdd}] = true |
| 273 | tests := []struct { |
| 274 | name string |
| 275 | args args |
| 276 | }{ |
| 277 | { |
| 278 | name: "SDX6320031", |
| 279 | args: args{ |
| 280 | cntx: context.Background(), |
| 281 | device: "SDX6320031", |
| 282 | }, |
| 283 | }, |
| 284 | } |
| 285 | for _, tt := range tests { |
| 286 | t.Run(tt.name, func(t *testing.T) { |
| 287 | va := &VoltApplication{ |
| 288 | VoltPortVnetsToDelete: test, |
| 289 | } |
| 290 | va.TriggerPendingVpvDeleteReq(tt.args.cntx, tt.args.device) |
| 291 | }) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestVoltApplication_TriggerPendingProfileDeleteReq(t *testing.T) { |
| 296 | type args struct { |
| 297 | cntx context.Context |
| 298 | device string |
| 299 | } |
| 300 | tests := []struct { |
| 301 | name string |
| 302 | args args |
| 303 | }{ |
| 304 | { |
| 305 | name: "SDX6320031", |
| 306 | args: args{ |
| 307 | cntx: context.Background(), |
| 308 | device: "SDX6320031", |
| 309 | }, |
| 310 | }, |
| 311 | } |
| 312 | for _, tt := range tests { |
| 313 | t.Run(tt.name, func(t *testing.T) { |
| 314 | va := &VoltApplication{ |
| 315 | DevicesDisc: sync.Map{}, |
| 316 | } |
| 317 | va.TriggerPendingProfileDeleteReq(tt.args.cntx, tt.args.device) |
| 318 | }) |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | func TestVoltApplication_TriggerPendingServiceDeleteReq(t *testing.T) { |
| 323 | type args struct { |
| 324 | cntx context.Context |
| 325 | device string |
| 326 | } |
| 327 | voltServ := &VoltService{ |
| 328 | VoltServiceOper: VoltServiceOper{ |
| 329 | Device: "SDX6320031", |
| 330 | ForceDelete: true, |
| 331 | }, |
| 332 | } |
| 333 | |
| 334 | servicesToDel := map[string]bool{} |
| 335 | servicesToDel["SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65"] = true |
| 336 | |
| 337 | tests := []struct { |
| 338 | name string |
| 339 | args args |
| 340 | }{ |
| 341 | { |
| 342 | name: "Positive_Case_TriggerPendingServiceDeleteReq", |
| 343 | args: args{ |
| 344 | cntx: context.Background(), |
| 345 | device: "SDX6320031", |
| 346 | }, |
| 347 | }, |
| 348 | } |
| 349 | for _, tt := range tests { |
| 350 | t.Run(tt.name, func(t *testing.T) { |
| 351 | va := &VoltApplication{ |
| 352 | ServicesToDelete: servicesToDel, |
| 353 | ServiceByName: sync.Map{}, |
| 354 | DevicesDisc: sync.Map{}, |
| 355 | } |
| 356 | |
| 357 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 358 | |
| 359 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 360 | db = dbintf |
| 361 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 362 | dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes() |
| 363 | va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device) |
| 364 | }) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) { |
| 369 | type args struct { |
| 370 | cntx context.Context |
| 371 | device string |
| 372 | } |
| 373 | |
| 374 | vnetToDel := map[string]bool{} |
| 375 | vnetToDel["2310-4096-4096"] = true |
| 376 | |
| 377 | voltVnet := &VoltVnet{ |
| 378 | Version: "v3", |
| 379 | VnetConfig: VnetConfig{ |
| 380 | Name: "2310-4096-4096", |
| 381 | VnetType: "Encapsulation", |
| 382 | SVlan: 2310, |
| 383 | CVlan: 4096, |
| 384 | UniVlan: 4096, |
| 385 | SVlanTpid: 33024, |
| 386 | }, |
| 387 | VnetOper: VnetOper{ |
| 388 | PendingDeviceToDelete: "SDX63200313", |
| 389 | }, |
| 390 | } |
| 391 | voltDev := &VoltDevice{ |
| 392 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 393 | SerialNum: "SDX6320031", |
| 394 | NniDhcpTrapVid: 123, |
| 395 | } |
| 396 | |
| 397 | tests := []struct { |
| 398 | name string |
| 399 | args args |
| 400 | }{ |
| 401 | { |
| 402 | name: "Negative_Case_TriggerPendingVnetDeleteReq", |
| 403 | args: args{ |
| 404 | cntx: context.Background(), |
| 405 | device: "SDX6320031", |
| 406 | }, |
| 407 | }, |
| 408 | } |
| 409 | for _, tt := range tests { |
| 410 | t.Run(tt.name, func(t *testing.T) { |
| 411 | va := &VoltApplication{ |
| 412 | VnetsToDelete: vnetToDel, |
| 413 | DevicesDisc: sync.Map{}, |
| 414 | } |
| 415 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 416 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 417 | va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device) |
| 418 | }) |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | func TestVoltApplication_UpdateMacInPortMap(t *testing.T) { |
| 423 | type args struct { |
| 424 | macAddr net.HardwareAddr |
| 425 | port string |
| 426 | } |
| 427 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 428 | macPort := map[string]string{} |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 429 | macPort[macAdd.String()] = test_data |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 430 | tests := []struct { |
| 431 | name string |
| 432 | args args |
| 433 | }{ |
| 434 | { |
| 435 | name: "Positive_Case_UpdateMacInPortMap", |
| 436 | args: args{ |
| 437 | macAddr: macAdd, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 438 | port: test_data, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 439 | }, |
| 440 | }, |
| 441 | } |
| 442 | for _, tt := range tests { |
| 443 | t.Run(tt.name, func(t *testing.T) { |
| 444 | va := &VoltApplication{ |
| 445 | macPortMap: macPort, |
| 446 | } |
| 447 | va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port) |
| 448 | }) |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | func TestVoltApplication_GetMacInPortMap(t *testing.T) { |
| 453 | type args struct { |
| 454 | macAddr net.HardwareAddr |
| 455 | } |
| 456 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 457 | macPort := map[string]string{} |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 458 | macPort[macAdd.String()] = test_data |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 459 | tests := []struct { |
| 460 | name string |
| 461 | args args |
| 462 | want string |
| 463 | }{ |
| 464 | { |
| 465 | name: "Positive_Case_GetMacInPortMap", |
| 466 | args: args{ |
| 467 | macAddr: macAdd, |
| 468 | }, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 469 | want: test_data, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 470 | }, |
| 471 | } |
| 472 | for _, tt := range tests { |
| 473 | t.Run(tt.name, func(t *testing.T) { |
| 474 | va := &VoltApplication{ |
| 475 | macPortMap: macPort, |
| 476 | } |
| 477 | if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want { |
| 478 | t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want) |
| 479 | } |
| 480 | }) |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | func Test_pushFlowFailureNotif(t *testing.T) { |
| 485 | type args struct { |
| 486 | flowStatus intf.FlowStatus |
| 487 | } |
| 488 | tests := []struct { |
| 489 | name string |
| 490 | args args |
| 491 | }{ |
| 492 | { |
| 493 | name: "Positive_Case_pushFlowFailureNotif", |
| 494 | args: args{ |
| 495 | flowStatus: intf.FlowStatus{ |
| 496 | Device: "SDX6320031", |
| 497 | Cookie: "68786618880", |
| 498 | Status: 0, |
| 499 | Flow: &of.VoltSubFlow{ |
| 500 | Cookie: 68786618880, |
| 501 | TableID: 0, |
| 502 | Priority: 100, |
| 503 | ErrorReason: "", |
| 504 | OldCookie: 0, |
| 505 | }, |
| 506 | }, |
| 507 | }, |
| 508 | }, |
| 509 | } |
| 510 | for _, tt := range tests { |
| 511 | t.Run(tt.name, func(t *testing.T) { |
| 512 | pushFlowFailureNotif(tt.args.flowStatus) |
| 513 | }) |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | func TestGetPonPortIDFromUNIPort(t *testing.T) { |
| 518 | type args struct { |
| 519 | uniPortID uint32 |
| 520 | } |
| 521 | tests := []struct { |
| 522 | name string |
| 523 | args args |
| 524 | want uint32 |
| 525 | }{ |
| 526 | { |
| 527 | name: "Positive_Case_pushFlowFailureNotif", |
| 528 | args: args{ |
| 529 | uniPortID: 1049600, |
| 530 | }, |
| 531 | want: 1, |
| 532 | }, |
| 533 | } |
| 534 | for _, tt := range tests { |
| 535 | t.Run(tt.name, func(t *testing.T) { |
| 536 | if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want { |
| 537 | t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want) |
| 538 | } |
| 539 | }) |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) { |
| 544 | type args struct { |
| 545 | cntx context.Context |
| 546 | flowStatus intf.FlowStatus |
| 547 | } |
| 548 | voltDev := &VoltDevice{ |
| 549 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 550 | SerialNum: "SDX6320031", |
| 551 | NniDhcpTrapVid: 123, |
| 552 | FlowAddEventMap: util.NewConcurrentMap(), |
| 553 | } |
| 554 | flowState := intf.FlowStatus{ |
| 555 | Device: "SDX6320031", |
| 556 | Cookie: "68786618880", |
| 557 | Status: 1005, |
| 558 | FlowModType: 0, |
| 559 | Flow: &of.VoltSubFlow{ |
| 560 | Cookie: 68786618880, |
| 561 | OldCookie: 0, |
| 562 | TableID: 0, |
| 563 | State: 0, |
| 564 | Priority: 100, |
| 565 | }, |
| 566 | } |
| 567 | flowAddEvent := map[string]*FlowEvent{} |
| 568 | flowEvent := &FlowEvent{ |
| 569 | device: "SDX6320031", |
| 570 | cookie: "68786618880", |
| 571 | eType: EventTypeControlFlowAdded, |
| 572 | } |
| 573 | flowAddEvent["68786618880"] = flowEvent |
| 574 | voltDev.FlowAddEventMap.Set("6878661888", flowEvent) |
| 575 | tests := []struct { |
| 576 | name string |
| 577 | args args |
| 578 | }{ |
| 579 | { |
| 580 | name: "Positive_Case_ProcessFlowModResultIndication", |
| 581 | args: args{ |
| 582 | cntx: context.Background(), |
| 583 | flowStatus: flowState, |
| 584 | }, |
| 585 | }, |
| 586 | { |
| 587 | name: "Negetive_Case_ProcessFlowModResultIndication", |
| 588 | args: args{ |
| 589 | cntx: context.Background(), |
| 590 | flowStatus: flowState, |
| 591 | }, |
| 592 | }, |
| 593 | } |
| 594 | for _, tt := range tests { |
| 595 | t.Run(tt.name, func(t *testing.T) { |
| 596 | va := &VoltApplication{ |
| 597 | DevicesDisc: sync.Map{}, |
| 598 | } |
| 599 | switch tt.name { |
| 600 | case "Positive_Case_ProcessFlowModResultIndication": |
| 601 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 602 | va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus) |
| 603 | case "Negetive_Case_ProcessFlowModResultIndication": |
| 604 | va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus) |
| 605 | } |
| 606 | }) |
| 607 | } |
| 608 | } |
| 609 | func Test_getPendingPoolKey(t *testing.T) { |
| 610 | type args struct { |
| 611 | mvlan of.VlanType |
| 612 | device string |
| 613 | } |
| 614 | |
| 615 | tests := []struct { |
| 616 | name string |
| 617 | args args |
| 618 | want string |
| 619 | }{ |
| 620 | { |
| 621 | name: "Positive_Case_getPendingPoolKey", |
| 622 | args: args{ |
| 623 | mvlan: of.VlanAny, |
| 624 | device: "SDX6320031", |
| 625 | }, |
| 626 | want: "4096_SDX6320031", |
| 627 | }, |
| 628 | } |
| 629 | for _, tt := range tests { |
| 630 | t.Run(tt.name, func(t *testing.T) { |
| 631 | if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want { |
| 632 | t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want) |
| 633 | } |
| 634 | }) |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | func TestNewVoltPort(t *testing.T) { |
| 639 | type args struct { |
| 640 | device string |
| 641 | name string |
| 642 | id uint32 |
| 643 | } |
| 644 | |
| 645 | voltPort := &VoltPort{ |
| 646 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 647 | Device: "SDX6320031", |
| 648 | ID: 16777472, |
| 649 | State: PortStateDown, |
| 650 | ChannelPerSubAlarmRaised: false, |
| 651 | Type: VoltPortTypeNni, |
| 652 | } |
| 653 | |
| 654 | voltPort1 := &VoltPort{ |
| 655 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 656 | Device: "SDX6320031", |
| 657 | ID: 1049600, |
| 658 | State: PortStateDown, |
| 659 | ChannelPerSubAlarmRaised: false, |
| 660 | PonPort: GetPonPortIDFromUNIPort(1049600), |
| 661 | } |
| 662 | tests := []struct { |
| 663 | name string |
| 664 | args args |
| 665 | want *VoltPort |
| 666 | }{ |
| 667 | { |
| 668 | name: "Positive_Case_TestNewVoltPort", |
| 669 | args: args{ |
| 670 | id: 16777472, |
| 671 | device: "SDX6320031", |
| 672 | name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 673 | }, |
| 674 | want: voltPort, |
| 675 | }, |
| 676 | { |
| 677 | name: "Positive_Case2_TestNewVoltPort", |
| 678 | args: args{ |
| 679 | id: 1049600, |
| 680 | device: "SDX6320031", |
| 681 | name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 682 | }, |
| 683 | want: voltPort1, |
| 684 | }, |
| 685 | } |
| 686 | for _, tt := range tests { |
| 687 | t.Run(tt.name, func(t *testing.T) { |
| 688 | switch tt.name { |
| 689 | case "Positive_Case_TestNewVoltPort": |
| 690 | if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) { |
| 691 | t.Errorf("NewVoltPort() = %v, want %v", got, tt.want) |
| 692 | } |
| 693 | case "Positive_Case2_TestNewVoltPort": |
| 694 | if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) { |
| 695 | t.Errorf("NewVoltPort() = %v, want %v", got, tt.want) |
| 696 | } |
| 697 | } |
| 698 | }) |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | func TestVoltPort_SetPortID(t *testing.T) { |
| 703 | type args struct { |
| 704 | id uint32 |
| 705 | } |
| 706 | tests := []struct { |
| 707 | name string |
| 708 | args args |
| 709 | }{ |
| 710 | { |
| 711 | name: "Positive_Case_TestNewVoltPort", |
| 712 | args: args{ |
| 713 | id: 16777472, |
| 714 | }, |
| 715 | }, |
| 716 | } |
| 717 | for _, tt := range tests { |
| 718 | t.Run(tt.name, func(t *testing.T) { |
| 719 | vp := &VoltPort{ |
| 720 | ID: 16777472, |
| 721 | Type: VoltPortTypeNni, |
| 722 | } |
| 723 | vp.SetPortID(tt.args.id) |
| 724 | }) |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | func TestNewVoltDevice(t *testing.T) { |
| 729 | type args struct { |
| 730 | name string |
| 731 | slno string |
| 732 | southBoundID string |
| 733 | } |
| 734 | |
| 735 | devConfig := &DeviceConfig{ |
| 736 | SerialNumber: "SDX6320033", |
| 737 | NniDhcpTrapVid: 4, |
| 738 | } |
| 739 | voltDevice := &VoltDevice{ |
| 740 | Name: "11c3175b-50f3-4220-9555-93df733ded1d", |
| 741 | SerialNum: "SDX6320033", |
| 742 | SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330", |
| 743 | State: controller.DeviceStateDOWN, |
| 744 | NniPort: "", |
| 745 | icmpv6GroupAdded: false, |
| 746 | IgmpDsFlowAppliedForMvlan: make(map[uint16]bool), |
| 747 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 748 | MigratingServices: util.NewConcurrentMap(), |
| 749 | VpvsBySvlan: util.NewConcurrentMap(), |
| 750 | FlowAddEventMap: util.NewConcurrentMap(), |
| 751 | FlowDelEventMap: util.NewConcurrentMap(), |
| 752 | GlobalDhcpFlowAdded: false, |
| 753 | NniDhcpTrapVid: 4, |
| 754 | } |
| 755 | |
| 756 | GetApplication().DevicesConfig.Store("SDX6320033", devConfig) |
| 757 | tests := []struct { |
| 758 | name string |
| 759 | args args |
| 760 | want *VoltDevice |
| 761 | }{ |
| 762 | { |
| 763 | name: "Positive_Case_TestNewVoltDevice", |
| 764 | args: args{ |
| 765 | name: "11c3175b-50f3-4220-9555-93df733ded1d", |
| 766 | slno: "SDX6320033", |
| 767 | southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330", |
| 768 | }, |
| 769 | want: voltDevice, |
| 770 | }, |
| 771 | } |
| 772 | for _, tt := range tests { |
| 773 | t.Run(tt.name, func(t *testing.T) { |
| 774 | if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) { |
| 775 | t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want) |
| 776 | } |
| 777 | }) |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) { |
| 782 | type args struct { |
| 783 | device string |
| 784 | svlan of.VlanType |
| 785 | } |
| 786 | |
| 787 | voltDev := &VoltDevice{ |
| 788 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 789 | SerialNum: "SDX6320033", |
| 790 | NniDhcpTrapVid: 123, |
| 791 | VpvsBySvlan: util.NewConcurrentMap(), |
| 792 | } |
| 793 | |
| 794 | cuncurrentMap := &util.ConcurrentMap{ |
| 795 | Count: atomic.NewUint64(0), |
| 796 | } |
| 797 | |
| 798 | voltDev1 := &VoltDevice{ |
| 799 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 800 | SerialNum: "SDX6320033", |
| 801 | NniDhcpTrapVid: 123, |
| 802 | VpvsBySvlan: cuncurrentMap, |
| 803 | } |
| 804 | tests := []struct { |
| 805 | name string |
| 806 | args args |
| 807 | want *util.ConcurrentMap |
| 808 | }{ |
| 809 | { |
| 810 | name: "Positive_Case_GetAssociatedVpvsForDevice", |
| 811 | args: args{ |
| 812 | device: "SDX6320033", |
| 813 | svlan: of.VlanAny, |
| 814 | }, |
| 815 | want: util.NewConcurrentMap(), |
| 816 | }, |
| 817 | { |
| 818 | name: "Positive_Case2_GetAssociatedVpvsForDevice", |
| 819 | args: args{ |
| 820 | device: "SDX6320033", |
| 821 | svlan: of.VlanAny, |
| 822 | }, |
| 823 | want: cuncurrentMap, |
| 824 | }, |
| 825 | { |
| 826 | name: "Negetive_Case2_GetAssociatedVpvsForDevice", |
| 827 | args: args{ |
| 828 | device: "SDX6320031", |
| 829 | svlan: of.VlanAny, |
| 830 | }, |
| 831 | want: nil, |
| 832 | }, |
| 833 | } |
| 834 | for _, tt := range tests { |
| 835 | t.Run(tt.name, func(t *testing.T) { |
| 836 | switch tt.name { |
| 837 | case "Positive_Case_GetAssociatedVpvsForDevice": |
| 838 | va := &VoltApplication{ |
| 839 | DevicesDisc: sync.Map{}, |
| 840 | VnetsBySvlan: util.NewConcurrentMap(), |
| 841 | } |
| 842 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 843 | if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 844 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 845 | } |
| 846 | case "Positive_Case2_GetAssociatedVpvsForDevice": |
| 847 | va1 := &VoltApplication{ |
| 848 | DevicesDisc: sync.Map{}, |
| 849 | VnetsBySvlan: cuncurrentMap, |
| 850 | } |
| 851 | va1.DevicesDisc.Store("SDX6320033", voltDev1) |
| 852 | va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap) |
| 853 | if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 854 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 855 | } |
| 856 | case "Negetive_Case2_GetAssociatedVpvsForDevice": |
| 857 | va1 := &VoltApplication{ |
| 858 | DevicesDisc: sync.Map{}, |
| 859 | } |
| 860 | if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 861 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 862 | } |
| 863 | } |
| 864 | }) |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) { |
| 869 | type args struct { |
| 870 | device string |
| 871 | vpv *VoltPortVnet |
| 872 | } |
| 873 | |
| 874 | vpv := &VoltPortVnet{ |
| 875 | Device: "SDX6320033", |
| 876 | SVlan: of.VlanAny, |
| 877 | } |
| 878 | voltDev := &VoltDevice{ |
| 879 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 880 | SerialNum: "SDX6320033", |
| 881 | NniDhcpTrapVid: 123, |
| 882 | VpvsBySvlan: util.NewConcurrentMap(), |
| 883 | } |
| 884 | tests := []struct { |
| 885 | name string |
| 886 | args args |
| 887 | }{ |
| 888 | { |
| 889 | name: "Positive_Case_AssociateVpvsToDevice", |
| 890 | args: args{ |
| 891 | device: "SDX6320033", |
| 892 | vpv: vpv, |
| 893 | }, |
| 894 | }, |
| 895 | { |
| 896 | name: "Negetive_Case_AssociateVpvsToDevice", |
| 897 | args: args{ |
| 898 | device: "SDX6320033", |
| 899 | vpv: vpv, |
| 900 | }, |
| 901 | }, |
| 902 | } |
| 903 | for _, tt := range tests { |
| 904 | t.Run(tt.name, func(t *testing.T) { |
| 905 | switch tt.name { |
| 906 | case "Positive_Case_AssociateVpvsToDevice": |
| 907 | va := &VoltApplication{ |
| 908 | DevicesDisc: sync.Map{}, |
| 909 | VnetsBySvlan: util.NewConcurrentMap(), |
| 910 | } |
| 911 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 912 | va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv) |
| 913 | case "Negetive_Case_AssociateVpvsToDevice": |
| 914 | va := &VoltApplication{ |
| 915 | DevicesDisc: sync.Map{}, |
| 916 | VnetsBySvlan: util.NewConcurrentMap(), |
| 917 | } |
| 918 | va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv) |
| 919 | } |
| 920 | }) |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) { |
| 925 | type args struct { |
| 926 | device string |
| 927 | vpv *VoltPortVnet |
| 928 | } |
| 929 | vpv := &VoltPortVnet{ |
| 930 | Device: "SDX6320033", |
| 931 | SVlan: of.VlanAny, |
| 932 | } |
| 933 | |
| 934 | voltDev := &VoltDevice{ |
| 935 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 936 | SerialNum: "SDX6320033", |
| 937 | NniDhcpTrapVid: 123, |
| 938 | VpvsBySvlan: util.NewConcurrentMap(), |
| 939 | } |
| 940 | tests := []struct { |
| 941 | name string |
| 942 | args args |
| 943 | }{ |
| 944 | { |
| 945 | name: "Positive_Case_DisassociateVpvsFromDevice", |
| 946 | args: args{ |
| 947 | device: "SDX6320033", |
| 948 | vpv: vpv, |
| 949 | }, |
| 950 | }, |
| 951 | { |
| 952 | name: "Negetive_Case_DisassociateVpvsFromDevice", |
| 953 | args: args{ |
| 954 | device: "SDX6320033", |
| 955 | vpv: vpv, |
| 956 | }, |
| 957 | }, |
| 958 | } |
| 959 | for _, tt := range tests { |
| 960 | t.Run(tt.name, func(t *testing.T) { |
| 961 | switch tt.name { |
| 962 | case "Positive_Case_DisassociateVpvsFromDevice": |
| 963 | va := &VoltApplication{ |
| 964 | DevicesDisc: sync.Map{}, |
| 965 | VnetsBySvlan: util.NewConcurrentMap(), |
| 966 | } |
| 967 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 968 | va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv) |
| 969 | case "Negetive_Case_DisassociateVpvsFromDevice": |
| 970 | va := &VoltApplication{ |
| 971 | DevicesDisc: sync.Map{}, |
| 972 | VnetsBySvlan: util.NewConcurrentMap(), |
| 973 | } |
| 974 | va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv) |
| 975 | } |
| 976 | }) |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | func TestVoltDevice_GetPort(t *testing.T) { |
| 981 | type args struct { |
| 982 | port string |
| 983 | } |
| 984 | voltPort := &VoltPort{ |
| 985 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 986 | Device: "SDX6320031", |
| 987 | ID: 16777472, |
| 988 | State: PortStateDown, |
| 989 | ChannelPerSubAlarmRaised: false, |
| 990 | Type: VoltPortTypeNni, |
| 991 | } |
| 992 | tests := []struct { |
| 993 | name string |
| 994 | args args |
| 995 | want *VoltPort |
| 996 | }{ |
| 997 | { |
| 998 | name: "Positive_Case_GetPort", |
| 999 | args: args{ |
| 1000 | port: "16777472", |
| 1001 | }, |
| 1002 | want: voltPort, |
| 1003 | }, |
| 1004 | { |
| 1005 | name: "Negetive_Case_GetPort", |
| 1006 | args: args{ |
| 1007 | port: "16777472", |
| 1008 | }, |
| 1009 | want: nil, |
| 1010 | }, |
| 1011 | } |
| 1012 | for _, tt := range tests { |
| 1013 | t.Run(tt.name, func(t *testing.T) { |
| 1014 | d := &VoltDevice{ |
| 1015 | Ports: sync.Map{}, |
| 1016 | } |
| 1017 | switch tt.name { |
| 1018 | case "Positive_Case_GetPort": |
| 1019 | d.Ports.Store("16777472", voltPort) |
| 1020 | if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) { |
| 1021 | t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want) |
| 1022 | } |
| 1023 | case "Negetive_Case_GetPort": |
| 1024 | if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) { |
| 1025 | t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want) |
| 1026 | } |
| 1027 | } |
| 1028 | }) |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | func TestVoltDevice_GetPortNameFromPortID(t *testing.T) { |
| 1033 | type args struct { |
| 1034 | portID uint32 |
| 1035 | } |
| 1036 | voltPort := &VoltPort{ |
| 1037 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1038 | Device: "SDX6320031", |
| 1039 | ID: 16777472, |
| 1040 | State: PortStateDown, |
| 1041 | ChannelPerSubAlarmRaised: false, |
| 1042 | Type: VoltPortTypeNni, |
| 1043 | } |
| 1044 | tests := []struct { |
| 1045 | name string |
| 1046 | args args |
| 1047 | want string |
| 1048 | }{ |
| 1049 | { |
| 1050 | name: "Positive_Case_GetPort", |
| 1051 | args: args{ |
| 1052 | portID: 16777472, |
| 1053 | }, |
| 1054 | want: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1055 | }, |
| 1056 | } |
| 1057 | for _, tt := range tests { |
| 1058 | t.Run(tt.name, func(t *testing.T) { |
| 1059 | d := &VoltDevice{ |
| 1060 | Ports: sync.Map{}, |
| 1061 | } |
| 1062 | d.Ports.Store(16777472, voltPort) |
| 1063 | if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want { |
| 1064 | t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want) |
| 1065 | } |
| 1066 | }) |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | func TestVoltDevice_DelPort(t *testing.T) { |
| 1071 | type args struct { |
| 1072 | port string |
| 1073 | } |
| 1074 | voltPort := &VoltPort{ |
| 1075 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1076 | Device: "SDX6320031", |
| 1077 | ID: 16777472, |
| 1078 | State: PortStateDown, |
| 1079 | ChannelPerSubAlarmRaised: false, |
| 1080 | Type: VoltPortTypeNni, |
| 1081 | } |
| 1082 | tests := []struct { |
| 1083 | name string |
| 1084 | args args |
| 1085 | }{ |
| 1086 | { |
| 1087 | name: "Positive_Case_DelPort", |
| 1088 | args: args{ |
| 1089 | port: "16777472", |
| 1090 | }, |
| 1091 | }, |
| 1092 | { |
| 1093 | name: "Negetive_Case_DelPort", |
| 1094 | args: args{ |
| 1095 | port: "16777472", |
| 1096 | }, |
| 1097 | }, |
| 1098 | } |
| 1099 | for _, tt := range tests { |
| 1100 | t.Run(tt.name, func(t *testing.T) { |
| 1101 | d := &VoltDevice{ |
| 1102 | Ports: sync.Map{}, |
| 1103 | } |
| 1104 | switch tt.name { |
| 1105 | case "Positive_Case_DelPort": |
| 1106 | d.Ports.Store("16777472", voltPort) |
| 1107 | d.DelPort(tt.args.port) |
| 1108 | case "Negetive_Case_DelPort": |
| 1109 | d.DelPort(tt.args.port) |
| 1110 | } |
| 1111 | }) |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | func TestVoltDevice_pushFlowsForUnis(t *testing.T) { |
| 1116 | type args struct { |
| 1117 | cntx context.Context |
| 1118 | } |
| 1119 | tests := []struct { |
| 1120 | name string |
| 1121 | args args |
| 1122 | }{ |
| 1123 | { |
| 1124 | name: "Positive_Case_pushFlowsForUnis", |
| 1125 | args: args{ |
| 1126 | cntx: context.Background(), |
| 1127 | }, |
| 1128 | }, |
| 1129 | { |
| 1130 | name: "Negetive_Case_pushFlowsForUnis", |
| 1131 | args: args{ |
| 1132 | cntx: context.Background(), |
| 1133 | }, |
| 1134 | }, |
| 1135 | { |
| 1136 | name: "Negetive_Case1_pushFlowsForUnis", |
| 1137 | args: args{ |
| 1138 | cntx: context.Background(), |
| 1139 | }, |
| 1140 | }, |
| 1141 | } |
| 1142 | for _, tt := range tests { |
| 1143 | t.Run(tt.name, func(t *testing.T) { |
| 1144 | d := &VoltDevice{ |
| 1145 | Name: "SDX6320031", |
| 1146 | SerialNum: "SDX6320031", |
| 1147 | Ports: sync.Map{}, |
| 1148 | } |
| 1149 | switch tt.name { |
| 1150 | case "Positive_Case_pushFlowsForUnis": |
| 1151 | voltPort := &VoltPort{ |
| 1152 | Name: "16777472", |
| 1153 | Device: "SDX6320031", |
| 1154 | ID: 16777472, |
| 1155 | State: PortStateUp, |
| 1156 | ChannelPerSubAlarmRaised: false, |
| 1157 | Type: VoltPortTypeNni, |
| 1158 | } |
| 1159 | d.Ports.Store("16777472", voltPort) |
| 1160 | ga := GetApplication() |
| 1161 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 1162 | voltPortVnet := &VoltPortVnet{ |
| 1163 | Device: "SDX6320031", |
| 1164 | Port: "16777472", |
| 1165 | DeleteInProgress: true, |
| 1166 | } |
| 1167 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 1168 | ga.VnetsByPort.Store("16777472", voltPortVnets) |
| 1169 | |
| 1170 | d.pushFlowsForUnis(tt.args.cntx) |
| 1171 | case "Negetive_Case_pushFlowsForUnis": |
| 1172 | voltPort1 := &VoltPort{ |
| 1173 | Name: "16777472", |
| 1174 | Device: "SDX6320031", |
| 1175 | ID: 16777472, |
| 1176 | State: PortStateDown, |
| 1177 | ChannelPerSubAlarmRaised: false, |
| 1178 | Type: VoltPortTypeNni, |
| 1179 | } |
| 1180 | d.Ports.Store("16777472", voltPort1) |
| 1181 | d.pushFlowsForUnis(tt.args.cntx) |
| 1182 | case "Negetive_Case1_pushFlowsForUnis": |
| 1183 | voltPort2 := &VoltPort{ |
| 1184 | Name: "16777472", |
| 1185 | Device: "SDX6320031", |
| 1186 | ID: 16777472, |
| 1187 | State: PortStateUp, |
| 1188 | ChannelPerSubAlarmRaised: false, |
| 1189 | Type: VoltPortTypeNni, |
| 1190 | } |
| 1191 | d.Ports.Store("1677747", voltPort2) |
| 1192 | d.pushFlowsForUnis(tt.args.cntx) |
| 1193 | } |
| 1194 | }) |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | func TestNewNbDevice(t *testing.T) { |
| 1199 | tests := []struct { |
| 1200 | name string |
| 1201 | want *NbDevice |
| 1202 | }{ |
| 1203 | { |
| 1204 | name: "Positive_Case_pushFlowsForUnis", |
| 1205 | want: &NbDevice{}, |
| 1206 | }, |
| 1207 | } |
| 1208 | for _, tt := range tests { |
| 1209 | t.Run(tt.name, func(t *testing.T) { |
| 1210 | if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) { |
| 1211 | t.Errorf("NewNbDevice() = %v, want %v", got, tt.want) |
| 1212 | } |
| 1213 | }) |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | func TestNbDevice_WriteToDb(t *testing.T) { |
| 1218 | type args struct { |
| 1219 | cntx context.Context |
| 1220 | portID uint32 |
| 1221 | ponPort *PonPortCfg |
| 1222 | } |
| 1223 | tests := []struct { |
| 1224 | name string |
| 1225 | args args |
| 1226 | }{ |
| 1227 | { |
| 1228 | name: "Positive_Case_pushFlowsForUnis", |
| 1229 | args: args{ |
| 1230 | cntx: context.Background(), |
| 1231 | portID: controller.NNIPortID, |
| 1232 | ponPort: &PonPortCfg{ |
| 1233 | PortID: controller.NNIPortID, |
| 1234 | EnableMulticastKPI: false, |
| 1235 | }, |
| 1236 | }, |
| 1237 | }, |
| 1238 | } |
| 1239 | for _, tt := range tests { |
| 1240 | t.Run(tt.name, func(t *testing.T) { |
| 1241 | nbd := &NbDevice{ |
| 1242 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1243 | } |
| 1244 | switch tt.name { |
| 1245 | case "Positive_Case_pushFlowsForUnis": |
| 1246 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1247 | db = dbintf |
| 1248 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1249 | nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort) |
| 1250 | } |
| 1251 | }) |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | func TestNbDevice_AddPortToNbDevice(t *testing.T) { |
| 1256 | type args struct { |
| 1257 | cntx context.Context |
| 1258 | portID uint32 |
| 1259 | allowedChannels uint32 |
| 1260 | enableMulticastKPI bool |
| 1261 | portAlarmProfileID string |
| 1262 | } |
| 1263 | ponPort := &PonPortCfg{ |
| 1264 | PortID: controller.NNIPortID, |
| 1265 | MaxActiveChannels: 123, |
| 1266 | EnableMulticastKPI: false, |
| 1267 | PortAlarmProfileID: "16777", |
| 1268 | } |
| 1269 | tests := []struct { |
| 1270 | name string |
| 1271 | args args |
| 1272 | want *PonPortCfg |
| 1273 | }{ |
| 1274 | { |
| 1275 | name: "Positive_Case_AddPortToNbDevice", |
| 1276 | args: args{ |
| 1277 | cntx: context.Background(), |
| 1278 | portID: controller.NNIPortID, |
| 1279 | allowedChannels: 123, |
| 1280 | enableMulticastKPI: false, |
| 1281 | portAlarmProfileID: "16777", |
| 1282 | }, |
| 1283 | want: ponPort, |
| 1284 | }, |
| 1285 | } |
| 1286 | for _, tt := range tests { |
| 1287 | t.Run(tt.name, func(t *testing.T) { |
| 1288 | nbd := &NbDevice{ |
| 1289 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1290 | PonPorts: sync.Map{}, |
| 1291 | } |
| 1292 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1293 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1294 | db = dbintf |
| 1295 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1296 | if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1297 | t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want) |
| 1298 | } |
| 1299 | }) |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | func TestVoltApplication_AddDeviceConfig(t *testing.T) { |
| 1304 | type args struct { |
| 1305 | cntx context.Context |
| 1306 | serialNum string |
| 1307 | hardwareIdentifier string |
| 1308 | nasID string |
| 1309 | ipAddress string |
| 1310 | uplinkPort string |
| 1311 | nniDhcpTrapID int |
| 1312 | } |
| 1313 | dvcConfg := &DeviceConfig{ |
| 1314 | SerialNumber: "SDX6320031", |
| 1315 | HardwareIdentifier: "0.0.0.0", |
| 1316 | IPAddress: "127.26.1.74", |
| 1317 | UplinkPort: "16777216", |
| 1318 | NasID: "12345", |
| 1319 | NniDhcpTrapVid: 123, |
| 1320 | } |
| 1321 | voltDev := &VoltDevice{ |
| 1322 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1323 | SerialNum: "SDX6320031", |
| 1324 | NniDhcpTrapVid: 123, |
| 1325 | } |
| 1326 | tests := []struct { |
| 1327 | name string |
| 1328 | args args |
| 1329 | wantErr bool |
| 1330 | }{ |
| 1331 | { |
| 1332 | name: "Positive_Case_AddDeviceConfig", |
| 1333 | args: args{ |
| 1334 | cntx: context.Background(), |
| 1335 | serialNum: "SDX6320031", |
| 1336 | hardwareIdentifier: "0.0.0.0.", |
| 1337 | nasID: "12345", |
| 1338 | ipAddress: "127.26.1.74", |
| 1339 | uplinkPort: "16777216", |
| 1340 | nniDhcpTrapID: 123, |
| 1341 | }, |
| 1342 | wantErr: false, |
| 1343 | }, |
| 1344 | } |
| 1345 | for _, tt := range tests { |
| 1346 | t.Run(tt.name, func(t *testing.T) { |
| 1347 | va := &VoltApplication{ |
| 1348 | DevicesConfig: sync.Map{}, |
| 1349 | } |
| 1350 | va.DevicesConfig.Store("SDX6320031", dvcConfg) |
| 1351 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1352 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1353 | db = dbintf |
| 1354 | dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1355 | if err := va.AddDeviceConfig(tt.args.cntx, tt.args.serialNum, tt.args.hardwareIdentifier, tt.args.nasID, tt.args.ipAddress, tt.args.uplinkPort, tt.args.nniDhcpTrapID); (err != nil) != tt.wantErr { |
| 1356 | t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr) |
| 1357 | } |
| 1358 | }) |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | func TestVoltApplication_GetDeviceConfig(t *testing.T) { |
| 1363 | type args struct { |
| 1364 | serNum string |
| 1365 | } |
| 1366 | dvcConfg := &DeviceConfig{ |
| 1367 | SerialNumber: "SDX6320031", |
| 1368 | HardwareIdentifier: "0.0.0.0", |
| 1369 | IPAddress: "127.26.1.74", |
| 1370 | UplinkPort: "16777216", |
| 1371 | NasID: "12345", |
| 1372 | NniDhcpTrapVid: 123, |
| 1373 | } |
| 1374 | tests := []struct { |
| 1375 | name string |
| 1376 | args args |
| 1377 | want *DeviceConfig |
| 1378 | }{ |
| 1379 | { |
| 1380 | name: "Positive_Case_GetDeviceConfig", |
| 1381 | args: args{ |
| 1382 | serNum: "SDX6320031", |
| 1383 | }, |
| 1384 | want: dvcConfg, |
| 1385 | }, |
| 1386 | { |
| 1387 | name: "Negetive_Case_GetDeviceConfig", |
| 1388 | args: args{ |
| 1389 | serNum: "SDX6320031", |
| 1390 | }, |
| 1391 | want: nil, |
| 1392 | }, |
| 1393 | } |
| 1394 | for _, tt := range tests { |
| 1395 | t.Run(tt.name, func(t *testing.T) { |
| 1396 | va := &VoltApplication{ |
| 1397 | DevicesConfig: sync.Map{}, |
| 1398 | } |
| 1399 | switch tt.name { |
| 1400 | case "Positive_Case_GetDeviceConfig": |
| 1401 | va.DevicesConfig.Store("SDX6320031", dvcConfg) |
| 1402 | if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) { |
| 1403 | t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want) |
| 1404 | } |
| 1405 | case "Negetive_Case_GetDeviceConfig": |
| 1406 | if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) { |
| 1407 | t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want) |
| 1408 | } |
| 1409 | } |
| 1410 | }) |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | func TestNbDevice_UpdatePortToNbDevice(t *testing.T) { |
| 1415 | type args struct { |
| 1416 | cntx context.Context |
| 1417 | portID uint32 |
| 1418 | allowedChannels uint32 |
| 1419 | enableMulticastKPI bool |
| 1420 | portAlarmProfileID string |
| 1421 | } |
| 1422 | ponPort := &PonPortCfg{ |
| 1423 | PortID: controller.NNIPortID, |
| 1424 | MaxActiveChannels: 123, |
| 1425 | EnableMulticastKPI: false, |
| 1426 | PortAlarmProfileID: "16777", |
| 1427 | } |
| 1428 | tests := []struct { |
| 1429 | name string |
| 1430 | args args |
| 1431 | want *PonPortCfg |
| 1432 | }{ |
| 1433 | { |
| 1434 | name: "Positive_Case_UpdatePortToNbDevice", |
| 1435 | args: args{ |
| 1436 | cntx: context.Background(), |
| 1437 | portID: controller.NNIPortID, |
| 1438 | allowedChannels: 123, |
| 1439 | enableMulticastKPI: false, |
| 1440 | portAlarmProfileID: "16777", |
| 1441 | }, |
| 1442 | want: ponPort, |
| 1443 | }, |
| 1444 | { |
| 1445 | name: "Negetive_Case_UpdatePortToNbDevice", |
| 1446 | args: args{ |
| 1447 | cntx: context.Background(), |
| 1448 | portID: 0, |
| 1449 | allowedChannels: 123, |
| 1450 | enableMulticastKPI: false, |
| 1451 | portAlarmProfileID: "16777", |
| 1452 | }, |
| 1453 | want: nil, |
| 1454 | }, |
| 1455 | } |
| 1456 | for _, tt := range tests { |
| 1457 | t.Run(tt.name, func(t *testing.T) { |
| 1458 | nbd := &NbDevice{ |
| 1459 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1460 | PonPorts: sync.Map{}, |
| 1461 | } |
| 1462 | switch tt.name { |
| 1463 | case "Positive_Case_UpdatePortToNbDevice": |
| 1464 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1465 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1466 | db = dbintf |
| 1467 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1468 | if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1469 | t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want) |
| 1470 | } |
| 1471 | case "Negetive_Case_UpdatePortToNbDevice": |
| 1472 | if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1473 | t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want) |
| 1474 | } |
| 1475 | } |
| 1476 | }) |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | func TestNbDevice_DeletePortFromNbDevice(t *testing.T) { |
| 1481 | type args struct { |
| 1482 | cntx context.Context |
| 1483 | portID uint32 |
| 1484 | } |
| 1485 | ponPort := &PonPortCfg{ |
| 1486 | PortID: controller.NNIPortID, |
| 1487 | MaxActiveChannels: 123, |
| 1488 | EnableMulticastKPI: false, |
| 1489 | PortAlarmProfileID: "16777", |
| 1490 | } |
| 1491 | tests := []struct { |
| 1492 | name string |
| 1493 | args args |
| 1494 | }{ |
| 1495 | { |
| 1496 | name: "Positive_Case_DeletePortFromNbDevice", |
| 1497 | args: args{ |
| 1498 | portID: controller.NNIPortID, |
| 1499 | }, |
| 1500 | }, |
| 1501 | } |
| 1502 | for _, tt := range tests { |
| 1503 | t.Run(tt.name, func(t *testing.T) { |
| 1504 | nbd := &NbDevice{ |
| 1505 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1506 | PonPorts: sync.Map{}, |
| 1507 | } |
| 1508 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1509 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1510 | db = dbintf |
| 1511 | dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes() |
| 1512 | nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID) |
| 1513 | }) |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) { |
| 1518 | type args struct { |
| 1519 | cookie string |
| 1520 | event *FlowEvent |
| 1521 | } |
| 1522 | flowEvent := &FlowEvent{ |
| 1523 | device: "SDX6320031", |
| 1524 | cookie: "68786618880", |
| 1525 | eType: EventTypeControlFlowAdded, |
| 1526 | } |
| 1527 | tests := []struct { |
| 1528 | name string |
| 1529 | args args |
| 1530 | }{ |
| 1531 | { |
| 1532 | name: "Positive_Case_RegisterFlowAddEvent", |
| 1533 | args: args{ |
| 1534 | cookie: "68786618880", |
| 1535 | event: flowEvent, |
| 1536 | }, |
| 1537 | }, |
| 1538 | } |
| 1539 | for _, tt := range tests { |
| 1540 | t.Run(tt.name, func(t *testing.T) { |
| 1541 | d := &VoltDevice{ |
| 1542 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1543 | } |
| 1544 | d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event) |
| 1545 | }) |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) { |
| 1550 | type args struct { |
| 1551 | cookie string |
| 1552 | event *FlowEvent |
| 1553 | } |
| 1554 | flowEvent := &FlowEvent{ |
| 1555 | device: "SDX6320031", |
| 1556 | cookie: "68786618880", |
| 1557 | eType: EventTypeControlFlowRemoved, |
| 1558 | } |
| 1559 | tests := []struct { |
| 1560 | name string |
| 1561 | args args |
| 1562 | }{ |
| 1563 | { |
| 1564 | name: "Positive_Case_RegisterFlowDelEvent", |
| 1565 | args: args{ |
| 1566 | cookie: "68786618880", |
| 1567 | event: flowEvent, |
| 1568 | }, |
| 1569 | }, |
| 1570 | } |
| 1571 | for _, tt := range tests { |
| 1572 | t.Run(tt.name, func(t *testing.T) { |
| 1573 | d := &VoltDevice{ |
| 1574 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1575 | } |
| 1576 | d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event) |
| 1577 | }) |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) { |
| 1582 | type args struct { |
| 1583 | cookie string |
| 1584 | flowModType of.Command |
| 1585 | } |
| 1586 | tests := []struct { |
| 1587 | name string |
| 1588 | args args |
| 1589 | }{ |
| 1590 | { |
| 1591 | name: "Positive_Case_RegisterFlowDelEvent", |
| 1592 | args: args{ |
| 1593 | cookie: "68786618880", |
| 1594 | flowModType: of.CommandDel, |
| 1595 | }, |
| 1596 | }, |
| 1597 | { |
| 1598 | name: "Negetive_Case_RegisterFlowDelEvent", |
| 1599 | args: args{ |
| 1600 | cookie: "68786618880", |
| 1601 | flowModType: opt82, |
| 1602 | }, |
| 1603 | }, |
| 1604 | } |
| 1605 | for _, tt := range tests { |
| 1606 | t.Run(tt.name, func(t *testing.T) { |
| 1607 | switch tt.name { |
| 1608 | case "Positive_Case_RegisterFlowDelEvent": |
| 1609 | d := &VoltDevice{ |
| 1610 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1611 | } |
| 1612 | d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType) |
| 1613 | case "Negetive_Case_RegisterFlowDelEvent": |
| 1614 | d := &VoltDevice{ |
| 1615 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1616 | } |
| 1617 | d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType) |
| 1618 | } |
| 1619 | }) |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | func TestVoltApplication_InitStaticConfig(t *testing.T) { |
| 1624 | tests := []struct { |
| 1625 | name string |
| 1626 | }{ |
| 1627 | { |
| 1628 | name: "Positive_Case_InitStaticConfig", |
| 1629 | }, |
| 1630 | } |
| 1631 | for _, tt := range tests { |
| 1632 | t.Run(tt.name, func(t *testing.T) { |
| 1633 | va := &VoltApplication{} |
| 1634 | va.InitStaticConfig() |
| 1635 | }) |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | func TestVoltApplication_SetVendorID(t *testing.T) { |
| 1640 | type args struct { |
| 1641 | vendorID string |
| 1642 | } |
| 1643 | tests := []struct { |
| 1644 | name string |
| 1645 | args args |
| 1646 | }{ |
| 1647 | { |
| 1648 | name: "Positive_Case_SetVendorID", |
| 1649 | args: args{ |
| 1650 | vendorID: "DT", |
| 1651 | }, |
| 1652 | }, |
| 1653 | } |
| 1654 | for _, tt := range tests { |
| 1655 | t.Run(tt.name, func(t *testing.T) { |
| 1656 | va := &VoltApplication{} |
| 1657 | va.SetVendorID(tt.args.vendorID) |
| 1658 | }) |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | func TestVoltApplication_GetVendorID(t *testing.T) { |
| 1663 | tests := []struct { |
| 1664 | name string |
| 1665 | want string |
| 1666 | }{ |
| 1667 | { |
| 1668 | name: "Positive_Case_GetVendorID", |
| 1669 | want: "DT", |
| 1670 | }, |
| 1671 | } |
| 1672 | for _, tt := range tests { |
| 1673 | t.Run(tt.name, func(t *testing.T) { |
| 1674 | va := &VoltApplication{ |
| 1675 | vendorID: "DT", |
| 1676 | } |
| 1677 | if got := va.GetVendorID(); got != tt.want { |
| 1678 | t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want) |
| 1679 | } |
| 1680 | }) |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | func TestVoltApplication_SetRebootFlag(t *testing.T) { |
| 1685 | type args struct { |
| 1686 | flag bool |
| 1687 | } |
| 1688 | tests := []struct { |
| 1689 | name string |
| 1690 | args args |
| 1691 | }{ |
| 1692 | { |
| 1693 | name: "Positive_Case_SetRebootFlag", |
| 1694 | args: args{ |
| 1695 | flag: true, |
| 1696 | }, |
| 1697 | }, |
| 1698 | } |
| 1699 | for _, tt := range tests { |
| 1700 | t.Run(tt.name, func(t *testing.T) { |
| 1701 | va := &VoltApplication{} |
| 1702 | va.SetRebootFlag(tt.args.flag) |
| 1703 | }) |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | func TestVoltApplication_GetUpgradeFlag(t *testing.T) { |
| 1708 | tests := []struct { |
| 1709 | name string |
| 1710 | want bool |
| 1711 | }{ |
| 1712 | { |
| 1713 | name: "Positive_Case_GetUpgradeFlag", |
| 1714 | want: true, |
| 1715 | }, |
| 1716 | } |
| 1717 | for _, tt := range tests { |
| 1718 | t.Run(tt.name, func(t *testing.T) { |
| 1719 | va := &VoltApplication{} |
| 1720 | isUpgradeComplete = true |
| 1721 | if got := va.GetUpgradeFlag(); got != tt.want { |
| 1722 | t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want) |
| 1723 | } |
| 1724 | }) |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | func TestVoltApplication_SetUpgradeFlag(t *testing.T) { |
| 1729 | type args struct { |
| 1730 | flag bool |
| 1731 | } |
| 1732 | tests := []struct { |
| 1733 | name string |
| 1734 | args args |
| 1735 | }{ |
| 1736 | { |
| 1737 | name: "Positive_Case_GetUpgradeFlag", |
| 1738 | args: args{ |
| 1739 | flag: true, |
| 1740 | }, |
| 1741 | }, |
| 1742 | } |
| 1743 | for _, tt := range tests { |
| 1744 | t.Run(tt.name, func(t *testing.T) { |
| 1745 | va := &VoltApplication{} |
| 1746 | va.SetUpgradeFlag(tt.args.flag) |
| 1747 | }) |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | func TestVoltApplication_AddDevice(t *testing.T) { |
| 1752 | type args struct { |
| 1753 | cntx context.Context |
| 1754 | device string |
| 1755 | slno string |
| 1756 | southBoundID string |
| 1757 | } |
| 1758 | voltDev := &VoltDevice{ |
| 1759 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1760 | SerialNum: "SDX6320031", |
| 1761 | NniDhcpTrapVid: 123, |
| 1762 | NniPort: "16777216", |
| 1763 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1764 | } |
| 1765 | nbd := &NbDevice{ |
| 1766 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1767 | PonPorts: sync.Map{}, |
| 1768 | } |
| 1769 | ponPortCnf := &PonPortCfg{ |
| 1770 | PortID: controller.NNIPortID, |
| 1771 | MaxActiveChannels: 123, |
| 1772 | EnableMulticastKPI: false, |
| 1773 | PortAlarmProfileID: "16777", |
| 1774 | } |
| 1775 | tests := []struct { |
| 1776 | name string |
| 1777 | args args |
| 1778 | }{ |
| 1779 | { |
| 1780 | name: "Positive_Case_AddDevice", |
| 1781 | args: args{ |
| 1782 | cntx: context.Background(), |
| 1783 | device: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1784 | slno: "SDX6320031", |
| 1785 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1786 | }, |
| 1787 | }, |
| 1788 | { |
| 1789 | name: "Negetive_Case_AddDevice", |
| 1790 | args: args{ |
| 1791 | cntx: context.Background(), |
| 1792 | device: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1793 | slno: "SDX6320031", |
| 1794 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1795 | }, |
| 1796 | }, |
| 1797 | } |
| 1798 | for _, tt := range tests { |
| 1799 | t.Run(tt.name, func(t *testing.T) { |
| 1800 | va := &VoltApplication{ |
| 1801 | DevicesDisc: sync.Map{}, |
| 1802 | NbDevice: sync.Map{}, |
| 1803 | } |
| 1804 | switch tt.name { |
| 1805 | case "Positive_Case_AddDevice": |
| 1806 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1807 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd) |
| 1808 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 1809 | va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID) |
| 1810 | case "Negetive_Case_AddDevice": |
| 1811 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1812 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 1813 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1814 | db = dbintf |
| 1815 | dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes() |
| 1816 | va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID) |
| 1817 | } |
| 1818 | }) |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | func TestVoltApplication_DelDevice(t *testing.T) { |
| 1823 | type args struct { |
| 1824 | cntx context.Context |
| 1825 | device string |
| 1826 | } |
| 1827 | voltDev := &VoltDevice{ |
| 1828 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1829 | SerialNum: "SDX6320031", |
| 1830 | NniDhcpTrapVid: 123, |
| 1831 | NniPort: "16777216", |
| 1832 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1833 | } |
| 1834 | tests := []struct { |
| 1835 | name string |
| 1836 | args args |
| 1837 | }{ |
| 1838 | { |
| 1839 | name: "Positive_Case_AddDevice", |
| 1840 | args: args{ |
| 1841 | cntx: context.Background(), |
| 1842 | device: "SDX6320031", |
| 1843 | }, |
| 1844 | }, |
| 1845 | { |
| 1846 | name: "Delete_Case_AddDevice", |
| 1847 | args: args{ |
| 1848 | cntx: context.Background(), |
| 1849 | device: "SDX6320031", |
| 1850 | }, |
| 1851 | }, |
| 1852 | } |
| 1853 | for _, tt := range tests { |
| 1854 | t.Run(tt.name, func(t *testing.T) { |
| 1855 | va := &VoltApplication{ |
| 1856 | DevicesDisc: sync.Map{}, |
| 1857 | } |
| 1858 | switch tt.name { |
| 1859 | case "Positive_Case_AddDevice": |
| 1860 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1861 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1862 | db = dbintf |
| 1863 | dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes() |
| 1864 | dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes() |
| 1865 | dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes() |
| 1866 | dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes() |
| 1867 | dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes() |
| 1868 | va.DelDevice(tt.args.cntx, tt.args.device) |
| 1869 | case "Delete_Case_AddDevice": |
| 1870 | va.DelDevice(tt.args.cntx, tt.args.device) |
| 1871 | } |
| 1872 | }) |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | func TestVoltApplication_PortAddInd(t *testing.T) { |
| 1877 | type args struct { |
| 1878 | cntx context.Context |
| 1879 | device string |
| 1880 | id uint32 |
| 1881 | portName string |
| 1882 | } |
| 1883 | voltDev := &VoltDevice{ |
| 1884 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1885 | SerialNum: "SDX6320031", |
| 1886 | NniDhcpTrapVid: 123, |
| 1887 | NniPort: "16777216", |
| 1888 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1889 | } |
| 1890 | tests := []struct { |
| 1891 | name string |
| 1892 | args args |
| 1893 | }{ |
| 1894 | { |
| 1895 | name: "Positive_Case_PortAddInd", |
| 1896 | args: args{ |
| 1897 | cntx: context.Background(), |
| 1898 | device: "SDX6320031", |
| 1899 | id: controller.NNIPortID, |
| 1900 | portName: "16777216", |
| 1901 | }, |
| 1902 | }, |
| 1903 | { |
| 1904 | name: "Negetive_Case_PortAddInd", |
| 1905 | args: args{ |
| 1906 | cntx: context.Background(), |
| 1907 | device: "SDX6320031", |
| 1908 | id: controller.NNIPortID, |
| 1909 | portName: "16777216", |
| 1910 | }, |
| 1911 | }, |
| 1912 | } |
| 1913 | for _, tt := range tests { |
| 1914 | t.Run(tt.name, func(t *testing.T) { |
| 1915 | va := &VoltApplication{ |
| 1916 | DevicesDisc: sync.Map{}, |
| 1917 | } |
| 1918 | switch tt.name { |
| 1919 | case "Positive_Case_PortAddInd": |
| 1920 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1921 | va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName) |
| 1922 | case "Negetive_Case_PortAddInd": |
| 1923 | va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName) |
| 1924 | } |
| 1925 | }) |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | func TestVoltApplication_PortUpdateInd(t *testing.T) { |
| 1930 | type args struct { |
| 1931 | device string |
| 1932 | portName string |
| 1933 | id uint32 |
| 1934 | } |
| 1935 | voltDev := &VoltDevice{ |
| 1936 | Name: "SDX6320031", |
| 1937 | SerialNum: "SDX6320031", |
| 1938 | NniDhcpTrapVid: 123, |
| 1939 | NniPort: "16777216", |
| 1940 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1941 | } |
| 1942 | tests := []struct { |
| 1943 | name string |
| 1944 | args args |
| 1945 | }{ |
| 1946 | { |
| 1947 | name: "Positive_Case_PortUpdateInd", |
| 1948 | args: args{ |
| 1949 | device: "SDX6320031", |
| 1950 | id: controller.NNIPortID, |
| 1951 | portName: "16777216", |
| 1952 | }, |
| 1953 | }, |
| 1954 | { |
| 1955 | name: "Negetive_Case_PortUpdateInd", |
| 1956 | args: args{ |
| 1957 | device: "SDX6320031", |
| 1958 | id: controller.NNIPortID, |
| 1959 | portName: "16777216", |
| 1960 | }, |
| 1961 | }, |
| 1962 | } |
| 1963 | for _, tt := range tests { |
| 1964 | t.Run(tt.name, func(t *testing.T) { |
| 1965 | va := &VoltApplication{ |
| 1966 | DevicesDisc: sync.Map{}, |
| 1967 | } |
| 1968 | switch tt.name { |
| 1969 | case "Positive_Case_PortAddInd": |
| 1970 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1971 | d := &VoltDevice{ |
| 1972 | Ports: sync.Map{}, |
| 1973 | } |
| 1974 | voltPort := &VoltPort{ |
| 1975 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1976 | Device: "SDX6320031", |
| 1977 | ID: 16777472, |
| 1978 | State: PortStateDown, |
| 1979 | ChannelPerSubAlarmRaised: false, |
| 1980 | Type: VoltPortTypeNni, |
| 1981 | } |
| 1982 | d.Ports.Store(16777472, voltPort) |
| 1983 | va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id) |
| 1984 | case "Negetive_Case_PortUpdateInd": |
| 1985 | va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id) |
| 1986 | } |
| 1987 | }) |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | func TestVoltApplication_AddNbPonPort(t *testing.T) { |
| 1992 | type args struct { |
| 1993 | cntx context.Context |
| 1994 | oltSbID string |
| 1995 | portID uint32 |
| 1996 | maxAllowedChannels uint32 |
| 1997 | enableMulticastKPI bool |
| 1998 | portAlarmProfileID string |
| 1999 | } |
| 2000 | voltDev := &VoltDevice{ |
| 2001 | Name: "SDX6320031", |
| 2002 | SerialNum: "SDX6320031", |
| 2003 | NniDhcpTrapVid: 123, |
| 2004 | NniPort: "16777216", |
| 2005 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2006 | } |
| 2007 | nbd := &NbDevice{ |
| 2008 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2009 | } |
| 2010 | tests := []struct { |
| 2011 | name string |
| 2012 | args args |
| 2013 | wantErr bool |
| 2014 | }{ |
| 2015 | { |
| 2016 | name: "Positive_Case_AddNbPonPort", |
| 2017 | args: args{ |
| 2018 | cntx: context.Background(), |
| 2019 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2020 | portID: 16777472, |
| 2021 | maxAllowedChannels: 0, |
| 2022 | enableMulticastKPI: false, |
| 2023 | portAlarmProfileID: "16777", |
| 2024 | }, |
| 2025 | }, |
| 2026 | { |
| 2027 | name: "Negetive_Case_AddNbPonPort", |
| 2028 | args: args{ |
| 2029 | cntx: context.Background(), |
| 2030 | oltSbID: "0", |
| 2031 | portID: 16777472, |
| 2032 | maxAllowedChannels: 0, |
| 2033 | enableMulticastKPI: false, |
| 2034 | portAlarmProfileID: "16777", |
| 2035 | }, |
| 2036 | }, |
| 2037 | } |
| 2038 | for _, tt := range tests { |
| 2039 | t.Run(tt.name, func(t *testing.T) { |
| 2040 | va := &VoltApplication{ |
| 2041 | DevicesDisc: sync.Map{}, |
| 2042 | NbDevice: sync.Map{}, |
| 2043 | } |
| 2044 | switch tt.name { |
| 2045 | case "Positive_Case_AddNbPonPort": |
| 2046 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2047 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2048 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2049 | db = dbintf |
| 2050 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2051 | if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2052 | t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2053 | } |
| 2054 | case "Negetive_Case_AddNbPonPort": |
| 2055 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2056 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2057 | db = dbintf |
| 2058 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2059 | if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2060 | t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2061 | } |
| 2062 | } |
| 2063 | }) |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | func TestVoltApplication_UpdateNbPonPort(t *testing.T) { |
| 2068 | type args struct { |
| 2069 | cntx context.Context |
| 2070 | oltSbID string |
| 2071 | portID uint32 |
| 2072 | maxAllowedChannels uint32 |
| 2073 | enableMulticastKPI bool |
| 2074 | portAlarmProfileID string |
| 2075 | } |
| 2076 | voltDev := &VoltDevice{ |
| 2077 | Name: "SDX6320031", |
| 2078 | SerialNum: "SDX6320031", |
| 2079 | NniDhcpTrapVid: 123, |
| 2080 | NniPort: "16777216", |
| 2081 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2082 | ActiveChannelsPerPon: sync.Map{}, |
| 2083 | } |
| 2084 | nbd := &NbDevice{ |
| 2085 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2086 | PonPorts: sync.Map{}, |
| 2087 | } |
| 2088 | ponPortCnf := &PonPortCfg{ |
| 2089 | PortID: controller.NNIPortID, |
| 2090 | MaxActiveChannels: 123, |
| 2091 | EnableMulticastKPI: false, |
| 2092 | PortAlarmProfileID: "16777", |
| 2093 | } |
| 2094 | tests := []struct { |
| 2095 | name string |
| 2096 | args args |
| 2097 | wantErr bool |
| 2098 | }{ |
| 2099 | { |
| 2100 | name: "Positive_Case_UpdateNbPonPort", |
| 2101 | args: args{ |
| 2102 | cntx: context.Background(), |
| 2103 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2104 | portID: controller.NNIPortID, |
| 2105 | maxAllowedChannels: 0, |
| 2106 | enableMulticastKPI: false, |
| 2107 | portAlarmProfileID: "16777", |
| 2108 | }, |
| 2109 | wantErr: false, |
| 2110 | }, |
| 2111 | { |
| 2112 | name: "Negetive_Case_Port_doesn't_exists", |
| 2113 | args: args{ |
| 2114 | cntx: context.Background(), |
| 2115 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2116 | portID: 16777472, |
| 2117 | maxAllowedChannels: 0, |
| 2118 | enableMulticastKPI: false, |
| 2119 | portAlarmProfileID: "16777", |
| 2120 | }, |
| 2121 | wantErr: true, |
| 2122 | }, |
| 2123 | { |
| 2124 | name: "Negetive_Case_Device-doesn't-exists", |
| 2125 | args: args{ |
| 2126 | cntx: context.Background(), |
| 2127 | oltSbID: "0", |
| 2128 | portID: 16777472, |
| 2129 | maxAllowedChannels: 0, |
| 2130 | enableMulticastKPI: false, |
| 2131 | portAlarmProfileID: "16777", |
| 2132 | }, |
| 2133 | wantErr: true, |
| 2134 | }, |
| 2135 | } |
| 2136 | for _, tt := range tests { |
| 2137 | t.Run(tt.name, func(t *testing.T) { |
| 2138 | va := &VoltApplication{ |
| 2139 | DevicesDisc: sync.Map{}, |
| 2140 | NbDevice: sync.Map{}, |
| 2141 | } |
| 2142 | switch tt.name { |
| 2143 | case "Positive_Case_UpdateNbPonPort": |
| 2144 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2145 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 2146 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2147 | voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf) |
| 2148 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2149 | db = dbintf |
| 2150 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2151 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2152 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2153 | } |
| 2154 | case "Negetive_Case_Port_doesn't_exists": |
| 2155 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2156 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2157 | db = dbintf |
| 2158 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2159 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2160 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2161 | } |
| 2162 | case "Negetive_Case_Device-doesn't-exists": |
| 2163 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2164 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2165 | db = dbintf |
| 2166 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2167 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2168 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2169 | } |
| 2170 | } |
| 2171 | }) |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | func TestVoltApplication_DeleteNbPonPort(t *testing.T) { |
| 2176 | type args struct { |
| 2177 | cntx context.Context |
| 2178 | oltSbID string |
| 2179 | portID uint32 |
| 2180 | } |
| 2181 | voltDev := &VoltDevice{ |
| 2182 | Name: "SDX6320031", |
| 2183 | SerialNum: "SDX6320031", |
| 2184 | NniDhcpTrapVid: 123, |
| 2185 | NniPort: "16777216", |
| 2186 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2187 | ActiveChannelsPerPon: sync.Map{}, |
| 2188 | } |
| 2189 | nbd := &NbDevice{ |
| 2190 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2191 | } |
| 2192 | ponPortCnf := &PonPortCfg{ |
| 2193 | PortID: controller.NNIPortID, |
| 2194 | MaxActiveChannels: 123, |
| 2195 | EnableMulticastKPI: false, |
| 2196 | PortAlarmProfileID: "16777", |
| 2197 | } |
| 2198 | tests := []struct { |
| 2199 | name string |
| 2200 | args args |
| 2201 | wantErr bool |
| 2202 | }{ |
| 2203 | { |
| 2204 | name: "Positive_Case_DeleteNbPonPort", |
| 2205 | args: args{ |
| 2206 | cntx: context.Background(), |
| 2207 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2208 | portID: controller.NNIPortID, |
| 2209 | }, |
| 2210 | wantErr: false, |
| 2211 | }, |
| 2212 | { |
| 2213 | name: "Negetive_Case_DeleteNbPonPort", |
| 2214 | args: args{ |
| 2215 | cntx: context.Background(), |
| 2216 | oltSbID: "0", |
| 2217 | portID: controller.NNIPortID, |
| 2218 | }, |
| 2219 | wantErr: false, |
| 2220 | }, |
| 2221 | } |
| 2222 | for _, tt := range tests { |
| 2223 | t.Run(tt.name, func(t *testing.T) { |
| 2224 | va := &VoltApplication{ |
| 2225 | DevicesDisc: sync.Map{}, |
| 2226 | NbDevice: sync.Map{}, |
| 2227 | } |
| 2228 | switch tt.name { |
| 2229 | case "Positive_Case_DeleteNbPonPort": |
| 2230 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2231 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 2232 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2233 | voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf) |
| 2234 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2235 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2236 | db = dbintf |
| 2237 | dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2238 | if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr { |
| 2239 | t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2240 | } |
| 2241 | case "Negetive_Case_DeleteNbPonPort": |
| 2242 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2243 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2244 | db = dbintf |
| 2245 | dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2246 | if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr { |
| 2247 | t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2248 | } |
| 2249 | } |
| 2250 | }) |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | func TestVoltApplication_DeviceUpInd(t *testing.T) { |
| 2255 | type args struct { |
| 2256 | device string |
| 2257 | } |
| 2258 | voltDev := &VoltDevice{ |
| 2259 | Name: "SDX6320031", |
| 2260 | SerialNum: "SDX6320031", |
| 2261 | NniDhcpTrapVid: 123, |
| 2262 | NniPort: "16777216", |
| 2263 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2264 | } |
| 2265 | tests := []struct { |
| 2266 | name string |
| 2267 | args args |
| 2268 | }{ |
| 2269 | { |
| 2270 | name: "Positive_Case_DeviceUpInd", |
| 2271 | args: args{ |
| 2272 | device: "SDX6320031", |
| 2273 | }, |
| 2274 | }, |
| 2275 | { |
| 2276 | name: "Negetive_Case_DeviceUpInd", |
| 2277 | args: args{ |
| 2278 | device: "o", |
| 2279 | }, |
| 2280 | }, |
| 2281 | } |
| 2282 | for _, tt := range tests { |
| 2283 | t.Run(tt.name, func(t *testing.T) { |
| 2284 | va := &VoltApplication{ |
| 2285 | DevicesDisc: sync.Map{}, |
| 2286 | } |
| 2287 | switch tt.name { |
| 2288 | case "Positive_Case_DeviceUpInd": |
| 2289 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2290 | va.DeviceUpInd(tt.args.device) |
| 2291 | case "Negetive_Case_DeviceUpInd": |
| 2292 | va.DeviceUpInd(tt.args.device) |
| 2293 | } |
| 2294 | }) |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | func TestVoltApplication_DeviceDownInd(t *testing.T) { |
| 2299 | type args struct { |
| 2300 | device string |
| 2301 | } |
| 2302 | voltDev := &VoltDevice{ |
| 2303 | Name: "SDX6320031", |
| 2304 | SerialNum: "SDX6320031", |
| 2305 | NniDhcpTrapVid: 123, |
| 2306 | NniPort: "16777216", |
| 2307 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2308 | } |
| 2309 | tests := []struct { |
| 2310 | name string |
| 2311 | args args |
| 2312 | }{ |
| 2313 | { |
| 2314 | name: "Positive_Case_DeviceDownInd", |
| 2315 | args: args{ |
| 2316 | device: "SDX6320031", |
| 2317 | }, |
| 2318 | }, |
| 2319 | { |
| 2320 | name: "Negetive_Case_DeviceDownInd", |
| 2321 | args: args{ |
| 2322 | device: "o", |
| 2323 | }, |
| 2324 | }, |
| 2325 | } |
| 2326 | for _, tt := range tests { |
| 2327 | t.Run(tt.name, func(t *testing.T) { |
| 2328 | va := &VoltApplication{ |
| 2329 | DevicesDisc: sync.Map{}, |
| 2330 | } |
| 2331 | switch tt.name { |
| 2332 | case "Positive_Case_DeviceDownInd": |
| 2333 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2334 | va.DeviceDownInd(tt.args.device) |
| 2335 | case "Negetive_Case_DeviceDownInd": |
| 2336 | va.DeviceDownInd(tt.args.device) |
| 2337 | } |
| 2338 | }) |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | func TestVoltApplication_DeviceRebootInd(t *testing.T) { |
| 2343 | type args struct { |
| 2344 | cntx context.Context |
| 2345 | device string |
| 2346 | serialNum string |
| 2347 | southBoundID string |
| 2348 | } |
| 2349 | voltDev := &VoltDevice{ |
| 2350 | Name: "SDX6320031", |
| 2351 | SerialNum: "SDX6320031", |
| 2352 | NniDhcpTrapVid: 123, |
| 2353 | NniPort: "16777216", |
| 2354 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2355 | State: controller.DeviceStateREBOOTED, |
| 2356 | } |
| 2357 | tests := []struct { |
| 2358 | name string |
| 2359 | args args |
| 2360 | }{ |
| 2361 | { |
| 2362 | name: "Positive_Case_DeviceRebootInd", |
| 2363 | args: args{ |
| 2364 | device: "SDX6320031", |
| 2365 | serialNum: "SDX6320031", |
| 2366 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2367 | }, |
| 2368 | }, |
| 2369 | } |
| 2370 | for _, tt := range tests { |
| 2371 | t.Run(tt.name, func(t *testing.T) { |
| 2372 | va := &VoltApplication{ |
| 2373 | DevicesDisc: sync.Map{}, |
| 2374 | } |
| 2375 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2376 | va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID) |
| 2377 | }) |
| 2378 | } |
| 2379 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame^] | 2380 | |
| 2381 | func TestVoltApplication_GetDeviceFromPort(t *testing.T) { |
| 2382 | type args struct { |
| 2383 | port string |
| 2384 | } |
| 2385 | voltDev := &VoltDevice{ |
| 2386 | Name: "SDX6320031", |
| 2387 | SerialNum: "SDX6320031", |
| 2388 | NniDhcpTrapVid: 123, |
| 2389 | NniPort: "16777216", |
| 2390 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2391 | Ports: sync.Map{}, |
| 2392 | } |
| 2393 | voltPort := &VoltPort{ |
| 2394 | Name: "16777216", |
| 2395 | Device: "SDX6320031", |
| 2396 | ID: 16777216, |
| 2397 | State: PortStateDown, |
| 2398 | ChannelPerSubAlarmRaised: false, |
| 2399 | Type: VoltPortTypeNni, |
| 2400 | } |
| 2401 | tests := []struct { |
| 2402 | name string |
| 2403 | args args |
| 2404 | want *VoltDevice |
| 2405 | wantErr bool |
| 2406 | }{ |
| 2407 | { |
| 2408 | name: "Positive_Case_GetDeviceFromPort", |
| 2409 | args: args{ |
| 2410 | port: "16777216", |
| 2411 | }, |
| 2412 | want: voltDev, |
| 2413 | wantErr: false, |
| 2414 | }, |
| 2415 | } |
| 2416 | for _, tt := range tests { |
| 2417 | t.Run(tt.name, func(t *testing.T) { |
| 2418 | va := &VoltApplication{ |
| 2419 | DevicesDisc: sync.Map{}, |
| 2420 | PortsDisc: sync.Map{}, |
| 2421 | } |
| 2422 | va.PortsDisc.Store("16777216", voltPort) |
| 2423 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2424 | got, err := va.GetDeviceFromPort(tt.args.port) |
| 2425 | if (err != nil) != tt.wantErr { |
| 2426 | t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2427 | return |
| 2428 | } |
| 2429 | if !reflect.DeepEqual(got, tt.want) { |
| 2430 | t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want) |
| 2431 | } |
| 2432 | }) |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | func TestVoltApplication_GetPortID(t *testing.T) { |
| 2437 | type args struct { |
| 2438 | port string |
| 2439 | } |
| 2440 | voltPort := &VoltPort{ |
| 2441 | Name: "16777216", |
| 2442 | Device: "SDX6320031", |
| 2443 | ID: 16777216, |
| 2444 | State: PortStateDown, |
| 2445 | ChannelPerSubAlarmRaised: false, |
| 2446 | Type: VoltPortTypeNni, |
| 2447 | } |
| 2448 | tests := []struct { |
| 2449 | name string |
| 2450 | args args |
| 2451 | want uint32 |
| 2452 | wantErr bool |
| 2453 | }{ |
| 2454 | { |
| 2455 | name: "Positive_Case_GetPortID", |
| 2456 | args: args{ |
| 2457 | port: "16777216", |
| 2458 | }, |
| 2459 | want: 16777216, |
| 2460 | wantErr: false, |
| 2461 | }, |
| 2462 | } |
| 2463 | for _, tt := range tests { |
| 2464 | t.Run(tt.name, func(t *testing.T) { |
| 2465 | va := &VoltApplication{ |
| 2466 | PortsDisc: sync.Map{}, |
| 2467 | } |
| 2468 | va.PortsDisc.Store("16777216", voltPort) |
| 2469 | got, err := va.GetPortID(tt.args.port) |
| 2470 | if (err != nil) != tt.wantErr { |
| 2471 | t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 2472 | return |
| 2473 | } |
| 2474 | if got != tt.want { |
| 2475 | t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want) |
| 2476 | } |
| 2477 | }) |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | func TestVoltApplication_GetPortName(t *testing.T) { |
| 2482 | type args struct { |
| 2483 | port uint32 |
| 2484 | } |
| 2485 | voltPort := &VoltPort{ |
| 2486 | Name: "16777216", |
| 2487 | Device: "SDX6320031", |
| 2488 | ID: 16777216, |
| 2489 | State: PortStateDown, |
| 2490 | ChannelPerSubAlarmRaised: false, |
| 2491 | Type: VoltPortTypeNni, |
| 2492 | } |
| 2493 | tests := []struct { |
| 2494 | name string |
| 2495 | args args |
| 2496 | want string |
| 2497 | wantErr bool |
| 2498 | }{ |
| 2499 | { |
| 2500 | name: "Positive_Case_GetPortID", |
| 2501 | args: args{ |
| 2502 | port: 16777216, |
| 2503 | }, |
| 2504 | want: "16777216", |
| 2505 | wantErr: false, |
| 2506 | }, |
| 2507 | } |
| 2508 | for _, tt := range tests { |
| 2509 | t.Run(tt.name, func(t *testing.T) { |
| 2510 | va := &VoltApplication{ |
| 2511 | PortsDisc: sync.Map{}, |
| 2512 | } |
| 2513 | va.PortsDisc.Store("16777216", voltPort) |
| 2514 | got, err := va.GetPortName(tt.args.port) |
| 2515 | if (err != nil) != tt.wantErr { |
| 2516 | t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr) |
| 2517 | return |
| 2518 | } |
| 2519 | if got != tt.want { |
| 2520 | t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want) |
| 2521 | } |
| 2522 | }) |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | func TestVoltApplication_PortUpInd(t *testing.T) { |
| 2527 | type args struct { |
| 2528 | cntx context.Context |
| 2529 | device string |
| 2530 | port string |
| 2531 | } |
| 2532 | voltDev := &VoltDevice{ |
| 2533 | Name: "SDX6320031", |
| 2534 | SerialNum: "SDX6320031", |
| 2535 | NniDhcpTrapVid: 123, |
| 2536 | NniPort: "16777472", |
| 2537 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2538 | Ports: sync.Map{}, |
| 2539 | VpvsBySvlan: util.NewConcurrentMap(), |
| 2540 | } |
| 2541 | voltPort := &VoltPort{ |
| 2542 | Name: "16777472", |
| 2543 | Device: "SDX6320031", |
| 2544 | ID: 16777472, |
| 2545 | State: PortStateUp, |
| 2546 | ChannelPerSubAlarmRaised: false, |
| 2547 | Type: VoltPortTypeNni, |
| 2548 | } |
| 2549 | voltServ := &VoltService{ |
| 2550 | VoltServiceOper: VoltServiceOper{ |
| 2551 | Device: "SDX6320031", |
| 2552 | }, |
| 2553 | VoltServiceCfg: VoltServiceCfg{ |
| 2554 | IsActivated: true, |
| 2555 | }, |
| 2556 | } |
| 2557 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 2558 | voltPortVnet := &VoltPortVnet{ |
| 2559 | Device: "SDX6320031", |
| 2560 | Port: "16777472", |
| 2561 | DeleteInProgress: false, |
| 2562 | services: sync.Map{}, |
| 2563 | SVlan: 4096, |
| 2564 | CVlan: 2310, |
| 2565 | UniVlan: 4096, |
| 2566 | SVlanTpid: 65, |
| 2567 | servicesCount: atomic.NewUint64(1), |
| 2568 | } |
| 2569 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 2570 | |
| 2571 | tests := []struct { |
| 2572 | name string |
| 2573 | args args |
| 2574 | }{ |
| 2575 | { |
| 2576 | name: "Positive_Case_PortUpInd", |
| 2577 | args: args{ |
| 2578 | cntx: context.Background(), |
| 2579 | port: "16777472", |
| 2580 | device: "SDX6320031", |
| 2581 | }, |
| 2582 | }, |
| 2583 | } |
| 2584 | for _, tt := range tests { |
| 2585 | t.Run(tt.name, func(t *testing.T) { |
| 2586 | va := &VoltApplication{ |
| 2587 | DevicesDisc: sync.Map{}, |
| 2588 | VnetsByPort: sync.Map{}, |
| 2589 | } |
| 2590 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2591 | voltDev.Ports.Store("16777472", voltPort) |
| 2592 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 2593 | voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ) |
| 2594 | voltapp := GetApplication() |
| 2595 | voltapp.DevicesDisc.Store("SDX6320031", voltDev) |
| 2596 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2597 | db = dbintf |
| 2598 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2599 | va.PortUpInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 2600 | }) |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | func TestVoltApplication_PortDownInd(t *testing.T) { |
| 2605 | type args struct { |
| 2606 | cntx context.Context |
| 2607 | device string |
| 2608 | port string |
| 2609 | } |
| 2610 | voltDev := &VoltDevice{ |
| 2611 | Name: "SDX6320031", |
| 2612 | SerialNum: "SDX6320031", |
| 2613 | NniDhcpTrapVid: 123, |
| 2614 | NniPort: "16777472", |
| 2615 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2616 | Ports: sync.Map{}, |
| 2617 | VpvsBySvlan: util.NewConcurrentMap(), |
| 2618 | } |
| 2619 | voltPort := &VoltPort{ |
| 2620 | Name: "16777472", |
| 2621 | Device: "SDX6320031", |
| 2622 | ID: 16777472, |
| 2623 | State: PortStateDown, |
| 2624 | ChannelPerSubAlarmRaised: false, |
| 2625 | Type: VoltPortTypeNni, |
| 2626 | } |
| 2627 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 2628 | voltPortVnet := &VoltPortVnet{ |
| 2629 | Device: "SDX6320031", |
| 2630 | Port: "16777472", |
| 2631 | DeleteInProgress: false, |
| 2632 | services: sync.Map{}, |
| 2633 | SVlan: 4096, |
| 2634 | CVlan: 2310, |
| 2635 | UniVlan: 4096, |
| 2636 | SVlanTpid: 65, |
| 2637 | servicesCount: atomic.NewUint64(1), |
| 2638 | } |
| 2639 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 2640 | tests := []struct { |
| 2641 | name string |
| 2642 | args args |
| 2643 | }{ |
| 2644 | { |
| 2645 | name: "Positive_Case_PortDownInd", |
| 2646 | args: args{ |
| 2647 | cntx: context.Background(), |
| 2648 | port: "16777472", |
| 2649 | device: "SDX6320031", |
| 2650 | }, |
| 2651 | }, |
| 2652 | } |
| 2653 | for _, tt := range tests { |
| 2654 | t.Run(tt.name, func(t *testing.T) { |
| 2655 | va := &VoltApplication{} |
| 2656 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2657 | voltDev.Ports.Store("16777472", voltPort) |
| 2658 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 2659 | voltApp := GetApplication() |
| 2660 | voltApp.DevicesDisc.Store("SDX6320031", voltDev) |
| 2661 | va.PortDownInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 2662 | }) |
| 2663 | } |
| 2664 | } |
| 2665 | |
| 2666 | func TestVoltApplication_UpdateDeviceSerialNumberList(t *testing.T) { |
| 2667 | type args struct { |
| 2668 | oldOltSlNo string |
| 2669 | newOltSlNo string |
| 2670 | } |
| 2671 | voltDev := &VoltDevice{ |
| 2672 | Name: "49686e2d-618f-4e8e-bca0", |
| 2673 | SerialNum: "SDX6320031", |
| 2674 | NniDhcpTrapVid: 123, |
| 2675 | NniPort: "16777472", |
| 2676 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2677 | Ports: sync.Map{}, |
| 2678 | VpvsBySvlan: util.NewConcurrentMap(), |
| 2679 | } |
| 2680 | tests := []struct { |
| 2681 | name string |
| 2682 | args args |
| 2683 | }{ |
| 2684 | { |
| 2685 | name: "Positive_Case_UpdateDeviceSerialNumberList", |
| 2686 | args: args{ |
| 2687 | oldOltSlNo: "SDX6320030", |
| 2688 | newOltSlNo: "SDX6320031", |
| 2689 | }, |
| 2690 | }, |
| 2691 | } |
| 2692 | for _, tt := range tests { |
| 2693 | t.Run(tt.name, func(t *testing.T) { |
| 2694 | va := &VoltApplication{} |
| 2695 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2696 | va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo) |
| 2697 | }) |
| 2698 | } |
| 2699 | } |