|
1 | 1 | // Copyright (c) 2023 Cisco and/or its affiliates.
|
2 | 2 | //
|
| 3 | +// Copyright (c) 2024 Nordix Foundation. |
| 4 | +// |
3 | 5 | // SPDX-License-Identifier: Apache-2.0
|
4 | 6 | //
|
5 | 7 | // Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -99,3 +101,161 @@ func TestMonitorScopeSelector(t *testing.T) {
|
99 | 101 | })
|
100 | 102 | }
|
101 | 103 | }
|
| 104 | + |
| 105 | +// nolint: funlen |
| 106 | +func TestNetworkServiceMonitorScopeSelector(t *testing.T) { |
| 107 | + cases := []struct { |
| 108 | + testname string |
| 109 | + conn *networkservice.Connection |
| 110 | + selector *networkservice.MonitorScopeSelector |
| 111 | + matches bool |
| 112 | + }{ |
| 113 | + { |
| 114 | + testname: "EmptySelector", |
| 115 | + conn: &networkservice.Connection{ |
| 116 | + Path: &networkservice.Path{ |
| 117 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 118 | + }, |
| 119 | + NetworkService: "ns1", |
| 120 | + }, |
| 121 | + selector: &networkservice.MonitorScopeSelector{}, |
| 122 | + matches: true, |
| 123 | + }, |
| 124 | + { |
| 125 | + testname: "IdenticalPathsAndNetworkService", |
| 126 | + conn: &networkservice.Connection{ |
| 127 | + Path: &networkservice.Path{ |
| 128 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 129 | + }, |
| 130 | + NetworkService: "ns1", |
| 131 | + }, |
| 132 | + selector: &networkservice.MonitorScopeSelector{ |
| 133 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 134 | + NetworkServices: []string{"ns1"}, |
| 135 | + }, |
| 136 | + matches: true, |
| 137 | + }, |
| 138 | + { |
| 139 | + testname: "IdenticalPathsAndDifferentNetworkService", |
| 140 | + conn: &networkservice.Connection{ |
| 141 | + Path: &networkservice.Path{ |
| 142 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 143 | + }, |
| 144 | + NetworkService: "ns1", |
| 145 | + }, |
| 146 | + selector: &networkservice.MonitorScopeSelector{ |
| 147 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 148 | + NetworkServices: []string{"ns2"}, |
| 149 | + }, |
| 150 | + matches: false, |
| 151 | + }, |
| 152 | + { |
| 153 | + testname: "IdenticalPathsAndMatchingNetworkServiceList", |
| 154 | + conn: &networkservice.Connection{ |
| 155 | + Path: &networkservice.Path{ |
| 156 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 157 | + }, |
| 158 | + NetworkService: "ns1", |
| 159 | + }, |
| 160 | + selector: &networkservice.MonitorScopeSelector{ |
| 161 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 162 | + NetworkServices: []string{"ns2", "ns1", "ns3"}, |
| 163 | + }, |
| 164 | + matches: true, |
| 165 | + }, |
| 166 | + { |
| 167 | + testname: "IdenticalPathsAndNonMatchingNetworkServiceList", |
| 168 | + conn: &networkservice.Connection{ |
| 169 | + Path: &networkservice.Path{ |
| 170 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 171 | + }, |
| 172 | + NetworkService: "ns1", |
| 173 | + }, |
| 174 | + selector: &networkservice.MonitorScopeSelector{ |
| 175 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 176 | + NetworkServices: []string{"ns2", "ns3", "ns0"}, |
| 177 | + }, |
| 178 | + matches: false, |
| 179 | + }, |
| 180 | + { |
| 181 | + testname: "IdenticalNetworkService", |
| 182 | + conn: &networkservice.Connection{ |
| 183 | + Path: &networkservice.Path{ |
| 184 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 185 | + }, |
| 186 | + NetworkService: "ns1", |
| 187 | + }, |
| 188 | + selector: &networkservice.MonitorScopeSelector{ |
| 189 | + NetworkServices: []string{"ns1"}, |
| 190 | + }, |
| 191 | + matches: true, |
| 192 | + }, |
| 193 | + { |
| 194 | + testname: "IdenticalNetworkServiceEmptyConnectionPath", |
| 195 | + conn: &networkservice.Connection{ |
| 196 | + NetworkService: "ns1", |
| 197 | + }, |
| 198 | + selector: &networkservice.MonitorScopeSelector{ |
| 199 | + NetworkServices: []string{"ns1"}, |
| 200 | + }, |
| 201 | + matches: true, |
| 202 | + }, |
| 203 | + { |
| 204 | + testname: "DifferentNetworkService", |
| 205 | + conn: &networkservice.Connection{ |
| 206 | + Path: &networkservice.Path{ |
| 207 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 208 | + }, |
| 209 | + NetworkService: "ns1", |
| 210 | + }, |
| 211 | + selector: &networkservice.MonitorScopeSelector{ |
| 212 | + NetworkServices: []string{"ns2"}, |
| 213 | + }, |
| 214 | + matches: false, |
| 215 | + }, |
| 216 | + { |
| 217 | + testname: "DifferentNetworkServiceEmptyConnectionPath", |
| 218 | + conn: &networkservice.Connection{ |
| 219 | + NetworkService: "ns1", |
| 220 | + }, |
| 221 | + selector: &networkservice.MonitorScopeSelector{ |
| 222 | + NetworkServices: []string{"ns2"}, |
| 223 | + }, |
| 224 | + matches: false, |
| 225 | + }, |
| 226 | + { |
| 227 | + testname: "MatchingNetworkServiceList", |
| 228 | + conn: &networkservice.Connection{ |
| 229 | + Path: &networkservice.Path{ |
| 230 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 231 | + }, |
| 232 | + NetworkService: "ns1", |
| 233 | + }, |
| 234 | + selector: &networkservice.MonitorScopeSelector{ |
| 235 | + NetworkServices: []string{"ns2", "ns1", "ns3"}, |
| 236 | + }, |
| 237 | + matches: true, |
| 238 | + }, |
| 239 | + { |
| 240 | + testname: "NonMatchingNetworkServiceList", |
| 241 | + conn: &networkservice.Connection{ |
| 242 | + Path: &networkservice.Path{ |
| 243 | + PathSegments: []*networkservice.PathSegment{{Name: "s1", Id: "id1", Token: "t1"}, {Name: "s2", Id: "id2", Token: "t2"}}, |
| 244 | + }, |
| 245 | + NetworkService: "ns1", |
| 246 | + }, |
| 247 | + selector: &networkservice.MonitorScopeSelector{ |
| 248 | + NetworkServices: []string{"ns2", "ns3", "ns0"}, |
| 249 | + }, |
| 250 | + matches: false, |
| 251 | + }, |
| 252 | + } |
| 253 | + |
| 254 | + for _, testCase := range cases { |
| 255 | + c := testCase |
| 256 | + t.Run(c.testname, func(t *testing.T) { |
| 257 | + |
| 258 | + require.Equal(t, c.conn.MatchesMonitorScopeSelector(c.selector), c.matches) |
| 259 | + }) |
| 260 | + } |
| 261 | +} |
0 commit comments