vinokuma | 703a70b | 2023-07-17 10:06:43 +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 | "reflect" |
| 21 | "testing" |
| 22 | cntlr "voltha-go-controller/internal/pkg/controller" |
| 23 | "voltha-go-controller/internal/pkg/of" |
| 24 | "voltha-go-controller/internal/pkg/util" |
| 25 | "voltha-go-controller/internal/test/mocks" |
| 26 | |
| 27 | "github.com/golang/mock/gomock" |
| 28 | "github.com/stretchr/testify/assert" |
| 29 | ) |
| 30 | |
| 31 | func TestVoltPortVnet_JSONMarshal(t *testing.T) { |
| 32 | tests := []struct { |
| 33 | name string |
| 34 | want []byte |
| 35 | wantErr bool |
| 36 | }{ |
| 37 | { |
| 38 | name: "VoltPortVnet_JSONMarshal", |
| 39 | }, |
| 40 | } |
| 41 | for _, tt := range tests { |
| 42 | t.Run(tt.name, func(t *testing.T) { |
| 43 | vpv := &VoltPortVnet{} |
| 44 | _, err := vpv.JSONMarshal() |
| 45 | if (err != nil) != tt.wantErr { |
| 46 | t.Errorf("VoltPortVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr) |
| 47 | return |
| 48 | } |
| 49 | }) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func TestVoltPortVnet_IsServiceActivated(t *testing.T) { |
| 54 | type args struct { |
| 55 | cntx context.Context |
| 56 | } |
| 57 | tests := []struct { |
| 58 | name string |
| 59 | args args |
| 60 | want bool |
| 61 | }{ |
| 62 | { |
| 63 | name: "VoltPortVnet_IsServiceActivated", |
| 64 | args: args{ |
| 65 | cntx: context.Background(), |
| 66 | }, |
| 67 | }, |
| 68 | } |
| 69 | for _, tt := range tests { |
| 70 | t.Run(tt.name, func(t *testing.T) { |
| 71 | vpv := &VoltPortVnet{} |
| 72 | voltServ := &VoltService{ |
| 73 | VoltServiceOper: VoltServiceOper{ |
| 74 | Device: test_device, |
| 75 | ForceDelete: true, |
| 76 | }, |
| 77 | } |
| 78 | vpv.services.Store(test_device, voltServ) |
| 79 | if got := vpv.IsServiceActivated(tt.args.cntx); got != tt.want { |
| 80 | t.Errorf("VoltPortVnet.IsServiceActivated() = %v, want %v", got, tt.want) |
| 81 | } |
| 82 | }) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestVoltVnet_JSONMarshal(t *testing.T) { |
| 87 | tests := []struct { |
| 88 | name string |
| 89 | want []byte |
| 90 | wantErr bool |
| 91 | }{ |
| 92 | { |
| 93 | name: "VoltVnet_JSONMarshal", |
| 94 | }, |
| 95 | } |
| 96 | for _, tt := range tests { |
| 97 | t.Run(tt.name, func(t *testing.T) { |
| 98 | vv := &VoltVnet{} |
| 99 | _, err := vv.JSONMarshal() |
| 100 | if (err != nil) != tt.wantErr { |
| 101 | t.Errorf("VoltVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr) |
| 102 | return |
| 103 | } |
| 104 | }) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | func TestVoltVnet_TriggerAssociatedFlowDelete(t *testing.T) { |
| 109 | type args struct { |
| 110 | cntx context.Context |
| 111 | device string |
| 112 | } |
| 113 | tests := []struct { |
| 114 | name string |
| 115 | args args |
| 116 | want bool |
| 117 | }{ |
| 118 | { |
| 119 | name: "VoltVnet_TriggerAssociatedFlowDelete", |
| 120 | args: args{ |
| 121 | cntx: context.Background(), |
| 122 | device: test_device, |
| 123 | }, |
| 124 | want: true, |
| 125 | }, |
| 126 | { |
| 127 | name: "cookieList_empty", |
| 128 | args: args{ |
| 129 | cntx: context.Background(), |
| 130 | device: test_device, |
| 131 | }, |
| 132 | want: false, |
| 133 | }, |
| 134 | } |
| 135 | for _, tt := range tests { |
| 136 | t.Run(tt.name, func(t *testing.T) { |
| 137 | vv := &VoltVnet{} |
| 138 | switch tt.name { |
| 139 | case "VoltVnet_TriggerAssociatedFlowDelete": |
| 140 | cookie := map[string]bool{} |
| 141 | cookie["1234"] = true |
| 142 | pendingDeleteFlow := map[string]map[string]bool{} |
| 143 | pendingDeleteFlow[test_device] = cookie |
| 144 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 145 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 146 | db = dbintf |
| 147 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 148 | if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want { |
| 149 | t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 150 | } |
| 151 | case "cookieList_empty": |
| 152 | if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want { |
| 153 | t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 154 | } |
| 155 | } |
| 156 | }) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | func TestVoltApplication_GetMatchingMcastService(t *testing.T) { |
| 161 | type args struct { |
| 162 | port string |
| 163 | device string |
| 164 | cvlan of.VlanType |
| 165 | } |
| 166 | tests := []struct { |
| 167 | name string |
| 168 | args args |
| 169 | want *VoltService |
| 170 | }{ |
| 171 | { |
| 172 | name: "VoltApplication_GetMatchingMcastService", |
| 173 | args: args{ |
| 174 | port: "test_port", |
| 175 | device: test_device, |
| 176 | cvlan: of.VlanAny, |
| 177 | }, |
| 178 | }, |
| 179 | { |
| 180 | name: "dIntf_error", |
| 181 | args: args{ |
| 182 | port: "test_port", |
| 183 | device: test_device, |
| 184 | cvlan: of.VlanAny, |
| 185 | }, |
| 186 | }, |
| 187 | { |
| 188 | name: "port == d.NniPort", |
| 189 | args: args{ |
| 190 | port: "test_port", |
| 191 | device: test_device, |
| 192 | cvlan: of.VlanAny, |
| 193 | }, |
| 194 | }, |
| 195 | { |
| 196 | name: "vnets_error", |
| 197 | args: args{ |
| 198 | port: "", |
| 199 | device: test_device, |
| 200 | cvlan: of.VlanAny, |
| 201 | }, |
| 202 | }, |
| 203 | } |
| 204 | for _, tt := range tests { |
| 205 | t.Run(tt.name, func(t *testing.T) { |
| 206 | va := &VoltApplication{} |
| 207 | switch tt.name { |
| 208 | case "VoltApplication_GetMatchingMcastService": |
| 209 | va.DevicesDisc.Store(test_device, voltDevice) |
| 210 | va.VnetsByPort.Store("test_port", voltPortVnet1) |
| 211 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 212 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 213 | } |
| 214 | case "dIntf_error": |
| 215 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 216 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 217 | } |
| 218 | case "port == d.NniPort": |
| 219 | va.DevicesDisc.Store(test_device, voltDevice) |
| 220 | voltDevice.NniPort = "test_port" |
| 221 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 222 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 223 | } |
| 224 | case "vnets_error": |
| 225 | va.DevicesDisc.Store(test_device, voltDevice) |
| 226 | va.VnetsByPort.Store("test_port1", voltPortVnet1) |
| 227 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 228 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 229 | } |
| 230 | } |
| 231 | }) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func TestVoltPortVnet_IgmpFlowInstallFailure(t *testing.T) { |
| 236 | type args struct { |
| 237 | cookie string |
| 238 | errorCode uint32 |
| 239 | errReason string |
| 240 | } |
| 241 | tests := []struct { |
| 242 | name string |
| 243 | args args |
| 244 | }{ |
| 245 | { |
| 246 | name: "VoltPortVnet_IgmpFlowInstallFailure", |
| 247 | args: args{ |
| 248 | cookie: "test_cookie", |
| 249 | errorCode: uint32(1), |
| 250 | errReason: "errReason", |
| 251 | }, |
| 252 | }, |
| 253 | } |
| 254 | for _, tt := range tests { |
| 255 | t.Run(tt.name, func(t *testing.T) { |
| 256 | vpv := &VoltPortVnet{} |
| 257 | switch tt.name { |
| 258 | case "VoltPortVnet_IgmpFlowInstallFailure": |
| 259 | voltService.IgmpEnabled = true |
| 260 | vpv.services.Store("test_cookie", voltService) |
| 261 | vpv.IgmpFlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
| 262 | } |
| 263 | }) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | func TestVoltVnet_FlowRemoveFailure(t *testing.T) { |
| 268 | type args struct { |
| 269 | cntx context.Context |
| 270 | cookie string |
| 271 | device string |
| 272 | errorCode uint32 |
| 273 | errReason string |
| 274 | } |
| 275 | tests := []struct { |
| 276 | name string |
| 277 | args args |
| 278 | }{ |
| 279 | { |
| 280 | name: "VoltVnet_FlowRemoveFailure", |
| 281 | args: args{ |
| 282 | cntx: context.Background(), |
| 283 | cookie: "1234", |
| 284 | device: test_device, |
| 285 | }, |
| 286 | }, |
| 287 | { |
| 288 | name: "mismatch_cookie", |
| 289 | args: args{ |
| 290 | cntx: context.Background(), |
| 291 | cookie: "1234", |
| 292 | device: test_device, |
| 293 | }, |
| 294 | }, |
| 295 | } |
| 296 | for _, tt := range tests { |
| 297 | t.Run(tt.name, func(t *testing.T) { |
| 298 | vv := &VoltVnet{} |
| 299 | switch tt.name { |
| 300 | case "VoltVnet_FlowRemoveFailure": |
| 301 | cookie := map[string]bool{} |
| 302 | cookie["1234"] = true |
| 303 | pendingDeleteFlow := map[string]map[string]bool{} |
| 304 | pendingDeleteFlow[test_device] = cookie |
| 305 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 306 | vv.DeleteInProgress = true |
| 307 | vv.Name = "test_name" |
| 308 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 309 | db = dbintf |
| 310 | dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1) |
| 311 | vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 312 | case "mismatch_cookie": |
| 313 | cookie := map[string]bool{} |
| 314 | cookie["12345"] = true |
| 315 | pendingDeleteFlow := map[string]map[string]bool{} |
| 316 | pendingDeleteFlow[test_device] = cookie |
| 317 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 318 | vv.DeleteInProgress = true |
| 319 | vv.Name = "test_name" |
| 320 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 321 | db = dbintf |
| 322 | dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1) |
| 323 | vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 324 | } |
| 325 | }) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | func TestVoltVnet_FlowRemoveSuccess(t *testing.T) { |
| 330 | type args struct { |
| 331 | cntx context.Context |
| 332 | cookie string |
| 333 | device string |
| 334 | } |
| 335 | tests := []struct { |
| 336 | name string |
| 337 | args args |
| 338 | }{ |
| 339 | { |
| 340 | name: "VoltVnet_FlowRemoveSuccess", |
| 341 | args: args{ |
| 342 | cntx: context.Background(), |
| 343 | cookie: "1234", |
| 344 | device: test_device, |
| 345 | }, |
| 346 | }, |
| 347 | } |
| 348 | for _, tt := range tests { |
| 349 | t.Run(tt.name, func(t *testing.T) { |
| 350 | vv := &VoltVnet{} |
| 351 | cookie := map[string]bool{} |
| 352 | cookie["1234"] = true |
| 353 | pendingDeleteFlow := map[string]map[string]bool{} |
| 354 | pendingDeleteFlow[test_device] = cookie |
| 355 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 356 | ga := GetApplication() |
| 357 | voltDevice.ConfiguredVlanForDeviceFlows = util.NewConcurrentMap() |
| 358 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 359 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 360 | db = dbintf |
| 361 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 362 | vv.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie, tt.args.device) |
| 363 | }) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func TestVoltPortVnet_FlowRemoveFailure(t *testing.T) { |
| 368 | type args struct { |
| 369 | cntx context.Context |
| 370 | cookie string |
| 371 | device string |
| 372 | errorCode uint32 |
| 373 | errReason string |
| 374 | } |
| 375 | tests := []struct { |
| 376 | name string |
| 377 | args args |
| 378 | }{ |
| 379 | { |
| 380 | name: "VoltPortVnet_FlowRemoveFailure", |
| 381 | args: args{ |
| 382 | cntx: context.Background(), |
| 383 | cookie: "1234", |
| 384 | device: test_device, |
| 385 | }, |
| 386 | }, |
| 387 | { |
| 388 | name: "DeleteInProgress_false", |
| 389 | args: args{ |
| 390 | cntx: context.Background(), |
| 391 | cookie: "1234", |
| 392 | device: test_device, |
| 393 | }, |
| 394 | }, |
| 395 | } |
| 396 | for _, tt := range tests { |
| 397 | t.Run(tt.name, func(t *testing.T) { |
| 398 | vpv := &VoltPortVnet{} |
| 399 | switch tt.name { |
| 400 | case "VoltPortVnet_FlowRemoveFailure": |
| 401 | vpv.services.Store("1234", voltService) |
| 402 | vpv.DeleteInProgress = true |
| 403 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 404 | db = dbintf |
| 405 | dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 406 | vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 407 | case "DeleteInProgress_false": |
| 408 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 409 | db = dbintf |
| 410 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 411 | vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 412 | } |
| 413 | }) |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | func TestVoltPortVnet_PushFlows(t *testing.T) { |
| 418 | type args struct { |
| 419 | cntx context.Context |
| 420 | device *VoltDevice |
| 421 | flow *of.VoltFlow |
| 422 | } |
| 423 | vsf := make(map[uint64]*of.VoltSubFlow) |
| 424 | vsf[uint64(1)] = &of.VoltSubFlow{ |
| 425 | Cookie: uint64(1234), |
| 426 | } |
| 427 | tests := []struct { |
| 428 | name string |
| 429 | args args |
| 430 | wantErr bool |
| 431 | }{ |
| 432 | { |
| 433 | name: "VoltPortVnet_PushFlows", |
| 434 | args: args{ |
| 435 | cntx: context.Background(), |
| 436 | device: voltDevice, |
| 437 | flow: &of.VoltFlow{ |
| 438 | PortName: "test_port", |
| 439 | SubFlows: vsf, |
| 440 | }, |
| 441 | }, |
| 442 | }, |
| 443 | } |
| 444 | for _, tt := range tests { |
| 445 | t.Run(tt.name, func(t *testing.T) { |
| 446 | vpv := &VoltPortVnet{} |
| 447 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 448 | err := vpv.PushFlows(tt.args.cntx, tt.args.device, tt.args.flow) |
| 449 | assert.NotNil(t, err) |
| 450 | }) |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | func TestVoltPortVnet_isVlanMatching(t *testing.T) { |
| 455 | type args struct { |
| 456 | cvlan of.VlanType |
| 457 | svlan of.VlanType |
| 458 | } |
| 459 | tests := []struct { |
| 460 | name string |
| 461 | args args |
| 462 | want bool |
| 463 | }{ |
| 464 | { |
| 465 | name: "VoltPortVnet_isVlanMatching", |
| 466 | args: args{ |
| 467 | cvlan: of.VlanAny, |
| 468 | svlan: of.VlanAny, |
| 469 | }, |
| 470 | want: true, |
| 471 | }, |
| 472 | { |
| 473 | name: "vpv.VlanControl_nil", |
| 474 | args: args{ |
| 475 | cvlan: of.VlanAny, |
| 476 | svlan: of.VlanAny, |
| 477 | }, |
| 478 | want: true, |
| 479 | }, |
| 480 | } |
| 481 | for _, tt := range tests { |
| 482 | t.Run(tt.name, func(t *testing.T) { |
| 483 | vpv := &VoltPortVnet{} |
| 484 | switch tt.name { |
| 485 | case "VoltPortVnet_isVlanMatching": |
| 486 | vpv.VlanControl = ONUCVlanOLTSVlan |
| 487 | vpv.SVlan = of.VlanAny |
| 488 | vpv.CVlan = of.VlanAny |
| 489 | if got := vpv.isVlanMatching(tt.args.cvlan, tt.args.svlan); got != tt.want { |
| 490 | t.Errorf("VoltPortVnet.isVlanMatching() = %v, want %v", got, tt.want) |
| 491 | } |
| 492 | } |
| 493 | }) |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | func TestProcessIcmpv6McGroup(t *testing.T) { |
| 498 | type args struct { |
| 499 | device string |
| 500 | delete bool |
| 501 | } |
| 502 | tests := []struct { |
| 503 | name string |
| 504 | args args |
| 505 | wantErr bool |
| 506 | }{ |
| 507 | { |
| 508 | name: "TestProcessIcmpv6McGroup", |
| 509 | args: args{ |
| 510 | device: test_device, |
| 511 | delete: false, |
| 512 | }, |
| 513 | }, |
| 514 | } |
| 515 | for _, tt := range tests { |
| 516 | t.Run(tt.name, func(t *testing.T) { |
| 517 | err := ProcessIcmpv6McGroup(tt.args.device, tt.args.delete) |
| 518 | assert.NotNil(t, err) |
| 519 | }) |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | func TestVoltVnet_setPbitRemarking(t *testing.T) { |
| 524 | tests := []struct { |
| 525 | name string |
| 526 | want uint32 |
| 527 | }{ |
| 528 | { |
| 529 | name: "VoltVnet_setPbitRemarking", |
| 530 | }, |
| 531 | } |
| 532 | for _, tt := range tests { |
| 533 | t.Run(tt.name, func(t *testing.T) { |
| 534 | vv := &VoltVnet{} |
| 535 | a := make(map[of.PbitType]of.PbitType) |
| 536 | a[of.PbitMatchAll] = of.PbitMatchAll |
| 537 | vv.CtrlPktPbitRemark = a |
| 538 | if got := vv.setPbitRemarking(); got != tt.want { |
| 539 | t.Errorf("VoltVnet.setPbitRemarking() = %v, want %v", got, tt.want) |
| 540 | } |
| 541 | }) |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | func TestBuildDSArpFlow(t *testing.T) { |
| 546 | type args struct { |
| 547 | inport uint32 |
| 548 | vnet *VoltVnet |
| 549 | } |
| 550 | tests := []struct { |
| 551 | name string |
| 552 | args args |
| 553 | want *of.VoltFlow |
| 554 | }{ |
| 555 | { |
| 556 | name: "BuildDSArpFlow", |
| 557 | args: args{ |
| 558 | inport: uint32(1), |
| 559 | vnet: &VoltVnet{ |
| 560 | Version: "test_version", |
| 561 | }, |
| 562 | }, |
| 563 | }, |
| 564 | } |
| 565 | for _, tt := range tests { |
| 566 | t.Run(tt.name, func(t *testing.T) { |
| 567 | switch tt.name { |
| 568 | case "BuildDSArpFlow": |
| 569 | got := BuildDSArpFlow(tt.args.inport, tt.args.vnet) |
| 570 | assert.NotNil(t, got) |
| 571 | } |
| 572 | }) |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | func TestBuildICMPv6Flow(t *testing.T) { |
| 577 | type args struct { |
| 578 | inport uint32 |
| 579 | vnet *VoltVnet |
| 580 | } |
| 581 | tests := []struct { |
| 582 | name string |
| 583 | args args |
| 584 | want *of.VoltFlow |
| 585 | }{ |
| 586 | { |
| 587 | name: "BuildICMPv6Flow", |
| 588 | args: args{ |
| 589 | inport: uint32(1), |
| 590 | vnet: &VoltVnet{ |
| 591 | Version: "test_version", |
| 592 | }, |
| 593 | }, |
| 594 | }, |
| 595 | } |
| 596 | for _, tt := range tests { |
| 597 | t.Run(tt.name, func(t *testing.T) { |
| 598 | got := BuildICMPv6Flow(tt.args.inport, tt.args.vnet) |
| 599 | assert.NotNil(t, got) |
| 600 | }) |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | func TestVoltApplication_DeleteDevFlowForVlanFromDevice(t *testing.T) { |
| 605 | type args struct { |
| 606 | cntx context.Context |
| 607 | vnet *VoltVnet |
| 608 | deviceSerialNum string |
| 609 | } |
| 610 | tests := []struct { |
| 611 | name string |
| 612 | args args |
| 613 | }{ |
| 614 | { |
| 615 | name: "device.SerialNum != deviceSerialNum", |
| 616 | args: args{ |
| 617 | cntx: context.Background(), |
| 618 | vnet: &VoltVnet{ |
| 619 | Version: "test_version", |
| 620 | }, |
| 621 | }, |
| 622 | }, |
| 623 | { |
| 624 | name: "VoltApplication_DeleteDevFlowForVlanFromDevice", |
| 625 | args: args{ |
| 626 | cntx: context.Background(), |
| 627 | vnet: &VoltVnet{ |
| 628 | Version: "test_version", |
| 629 | }, |
| 630 | deviceSerialNum: "test_serial_number", |
| 631 | }, |
| 632 | }, |
| 633 | } |
| 634 | for _, tt := range tests { |
| 635 | t.Run(tt.name, func(t *testing.T) { |
| 636 | va := &VoltApplication{} |
| 637 | switch tt.name { |
| 638 | case "device.SerialNum != deviceSerialNum": |
| 639 | va.DevicesDisc.Store(test_device, voltDevice) |
| 640 | va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum) |
| 641 | case "VoltApplication_DeleteDevFlowForVlanFromDevice": |
| 642 | va.DevicesDisc.Store(test_device, voltDevice) |
| 643 | va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum) |
| 644 | } |
| 645 | }) |
| 646 | } |
| 647 | } |