go.ligato.io/vpp-agent/v3@v3.5.0/plugins/configurator/notify_test.go (about) 1 // Copyright (c) 2020 Cisco and/or its affiliates. 2 // 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 package configurator 16 17 import ( 18 "testing" 19 20 pb "go.ligato.io/vpp-agent/v3/proto/ligato/configurator" 21 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp" 22 vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 23 ) 24 25 func TestFilters(t *testing.T) { 26 type args struct { 27 n *pb.Notification 28 filters []*pb.Notification 29 } 30 tests := []struct { 31 name string 32 args args 33 want bool 34 }{ 35 { 36 name: "interface name", 37 args: args{ 38 n: &pb.Notification{ 39 Notification: &pb.Notification_VppNotification{ 40 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 41 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 42 State: &vpp_interfaces.InterfaceState{ 43 Name: "LOOP1", 44 InternalName: "loop1", 45 Type: vpp_interfaces.Interface_SOFTWARE_LOOPBACK, 46 IfIndex: 1, 47 AdminStatus: vpp_interfaces.InterfaceState_UP, 48 OperStatus: vpp_interfaces.InterfaceState_UP, 49 }, 50 }}, 51 }, 52 }, 53 filters: []*pb.Notification{ 54 { 55 Notification: &pb.Notification_VppNotification{ 56 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 57 State: &vpp_interfaces.InterfaceState{ 58 Name: "LOOP1", 59 }, 60 }}, 61 }, 62 }, 63 }}, 64 want: true, 65 }, 66 { 67 name: "interface notification type", 68 args: args{ 69 n: &pb.Notification{ 70 Notification: &pb.Notification_VppNotification{ 71 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 72 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 73 State: &vpp_interfaces.InterfaceState{ 74 Name: "LOOP1", 75 InternalName: "loop1", 76 Type: vpp_interfaces.Interface_SOFTWARE_LOOPBACK, 77 IfIndex: 1, 78 AdminStatus: vpp_interfaces.InterfaceState_UP, 79 OperStatus: vpp_interfaces.InterfaceState_UP, 80 }, 81 }}, 82 }, 83 }, 84 filters: []*pb.Notification{ 85 { 86 Notification: &pb.Notification_VppNotification{ 87 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 88 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 89 }}, 90 }, 91 }, 92 }}, 93 want: true, 94 }, 95 { 96 name: "interface name and notification type", 97 args: args{ 98 n: &pb.Notification{ 99 Notification: &pb.Notification_VppNotification{ 100 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 101 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 102 State: &vpp_interfaces.InterfaceState{ 103 Name: "LOOP1", 104 InternalName: "loop1", 105 Type: vpp_interfaces.Interface_SOFTWARE_LOOPBACK, 106 IfIndex: 1, 107 AdminStatus: vpp_interfaces.InterfaceState_UP, 108 OperStatus: vpp_interfaces.InterfaceState_UP, 109 }, 110 }}, 111 }, 112 }, 113 filters: []*pb.Notification{ 114 { 115 Notification: &pb.Notification_VppNotification{ 116 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 117 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 118 State: &vpp_interfaces.InterfaceState{ 119 Name: "LOOP1", 120 }, 121 }}, 122 }, 123 }, 124 }}, 125 want: true, 126 }, 127 128 { 129 name: "wrong notification type", 130 args: args{ 131 n: &pb.Notification{ 132 Notification: &pb.Notification_VppNotification{ 133 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 134 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 135 State: &vpp_interfaces.InterfaceState{ 136 Name: "LOOP1", 137 InternalName: "loop1", 138 Type: vpp_interfaces.Interface_SOFTWARE_LOOPBACK, 139 IfIndex: 1, 140 AdminStatus: vpp_interfaces.InterfaceState_UP, 141 OperStatus: vpp_interfaces.InterfaceState_UP, 142 }, 143 }}, 144 }, 145 }, 146 filters: []*pb.Notification{ 147 { 148 Notification: &pb.Notification_VppNotification{ 149 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 150 Type: vpp_interfaces.InterfaceNotification_COUNTERS, 151 }}, 152 }, 153 }, 154 }}, 155 want: false, 156 }, 157 158 { 159 name: "", 160 args: args{ 161 n: &pb.Notification{ 162 Notification: &pb.Notification_VppNotification{ 163 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 164 Type: vpp_interfaces.InterfaceNotification_UPDOWN, 165 State: &vpp_interfaces.InterfaceState{ 166 Name: "LOOP1", 167 InternalName: "loop1", 168 Type: vpp_interfaces.Interface_SOFTWARE_LOOPBACK, 169 IfIndex: 1, 170 AdminStatus: vpp_interfaces.InterfaceState_UP, 171 OperStatus: vpp_interfaces.InterfaceState_UP, 172 }, 173 }}, 174 }, 175 }, 176 filters: []*pb.Notification{ 177 { 178 Notification: &pb.Notification_VppNotification{ 179 VppNotification: &vpp.Notification{Interface: &vpp_interfaces.InterfaceNotification{ 180 State: &vpp_interfaces.InterfaceState{ 181 Name: "LOOP1", 182 }, 183 }}, 184 }, 185 }, 186 }}, 187 want: true, 188 }, 189 } 190 for _, tt := range tests { 191 t.Run(tt.name, func(t *testing.T) { 192 if got := isFilter(tt.args.n, tt.args.filters); got != tt.want { 193 t.Errorf("isFilter() = %v, want %v", got, tt.want) 194 } 195 }) 196 } 197 }