Akash Soni | 9fad736 | 2023-10-03 12:19:37 +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 | "net" |
| 20 | "testing" |
| 21 | |
| 22 | "github.com/stretchr/testify/assert" |
| 23 | ) |
| 24 | |
| 25 | func TestNewIgmpGroupPort(t *testing.T) { |
| 26 | type args struct { |
| 27 | port string |
| 28 | cvlan uint16 |
| 29 | pbit uint8 |
| 30 | version uint8 |
| 31 | incl bool |
| 32 | ponPortID uint32 |
| 33 | } |
| 34 | tests := []struct { |
| 35 | name string |
| 36 | args args |
| 37 | want *IgmpGroupPort |
| 38 | }{ |
| 39 | { |
| 40 | name: "NewIgmpGroupPort", |
| 41 | args: args{ |
| 42 | port: "256", |
| 43 | cvlan: AnyVlan, |
| 44 | pbit: 0, |
| 45 | version: uint8(12), |
| 46 | incl: true, |
| 47 | ponPortID: uint32(256), |
| 48 | }, |
| 49 | want: &IgmpGroupPort{}, |
| 50 | }, |
| 51 | } |
| 52 | for _, tt := range tests { |
| 53 | t.Run(tt.name, func(t *testing.T) { |
| 54 | got := NewIgmpGroupPort(tt.args.port, tt.args.cvlan, tt.args.pbit, tt.args.version, tt.args.incl, tt.args.ponPortID) |
| 55 | assert.NotNil(t, got) |
| 56 | }) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func TestIgmpGroupPort_DelExclSource(t *testing.T) { |
| 61 | type args struct { |
| 62 | src net.IP |
| 63 | } |
| 64 | tests := []struct { |
| 65 | name string |
| 66 | args args |
| 67 | }{ |
| 68 | { |
| 69 | name: "DelExclSource", |
| 70 | args: args{ |
| 71 | src: AllSystemsMulticastGroupIP, |
| 72 | }, |
| 73 | }, |
| 74 | { |
| 75 | name: "AddExclSource", |
| 76 | args: args{ |
| 77 | src: AllSystemsMulticastGroupIP, |
| 78 | }, |
| 79 | }, |
| 80 | { |
| 81 | name: "DelInclSource", |
| 82 | args: args{ |
| 83 | src: AllSystemsMulticastGroupIP, |
| 84 | }, |
| 85 | }, |
| 86 | { |
| 87 | name: "AddInclSource", |
| 88 | args: args{ |
| 89 | src: AllSystemsMulticastGroupIP, |
| 90 | }, |
| 91 | }, |
| 92 | { |
| 93 | name: "InclSourceIsIn", |
| 94 | args: args{ |
| 95 | src: AllSystemsMulticastGroupIP, |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | name: "ExclSourceIsIn", |
| 100 | args: args{ |
| 101 | src: AllSystemsMulticastGroupIP, |
| 102 | }, |
| 103 | }, |
| 104 | } |
| 105 | for _, tt := range tests { |
| 106 | t.Run(tt.name, func(t *testing.T) { |
| 107 | igp := &IgmpGroupPort{ |
| 108 | ExcludeList: []net.IP{ |
| 109 | AllSystemsMulticastGroupIP, |
| 110 | }, |
| 111 | IncludeList: []net.IP{ |
| 112 | AllSystemsMulticastGroupIP, |
| 113 | }, |
| 114 | } |
| 115 | switch tt.name { |
| 116 | case "DelExclSource": |
| 117 | igp.DelExclSource(tt.args.src) |
| 118 | case "AddExclSource": |
| 119 | igp.AddExclSource(tt.args.src) |
| 120 | case "DelInclSource": |
| 121 | igp.DelInclSource(tt.args.src) |
| 122 | case "AddInclSource": |
| 123 | igp.AddInclSource(tt.args.src) |
| 124 | case "InclSourceIsIn": |
| 125 | igp.InclSourceIsIn(tt.args.src) |
| 126 | case "ExclSourceIsIn": |
| 127 | igp.ExclSourceIsIn(tt.args.src) |
| 128 | } |
| 129 | }) |
| 130 | } |
| 131 | } |