| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package l2topology |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/require" |
| 9 | ) |
| 10 | |
| 11 | func TestBuildFDBCandidates_KeepsDistinctVLANScopedCandidates(t *testing.T) { |
| 12 | candidates := buildFDBCandidates([]FDBObservation{ |
| 13 | { |
| 14 | MAC: "70:49:a2:65:72:cd", |
| 15 | BridgePort: "7", |
| 16 | Status: "learned", |
| 17 | VLANID: "100", |
| 18 | }, |
| 19 | { |
| 20 | MAC: "70:49:a2:65:72:cd", |
| 21 | BridgePort: "7", |
| 22 | Status: "learned", |
| 23 | VLANID: "100\x00vlan:200", |
| 24 | }, |
| 25 | }, nil) |
| 26 | |
| 27 | require.Len(t, candidates, 2) |
| 28 | require.Equal(t, "100", candidates[0].vlanID) |
| 29 | require.Equal(t, "100\x00vlan:200", candidates[1].vlanID) |
| 30 | } |
| 31 | |
| 32 | func TestBuildFDBCandidates_DoesNotReintroduceDuplicateEndpoint(t *testing.T) { |
| 33 | candidates := buildFDBCandidates([]FDBObservation{ |
| 34 | { |
| 35 | MAC: "70:49:a2:65:72:cd", |
| 36 | BridgePort: "1", |
| 37 | Status: "learned", |
| 38 | }, |
| 39 | { |
| 40 | MAC: "70:49:a2:65:72:cd", |
| 41 | BridgePort: "2", |
| 42 | Status: "learned", |
| 43 | }, |
| 44 | { |
| 45 | MAC: "70:49:a2:65:72:cd", |
| 46 | BridgePort: "3", |
| 47 | Status: "learned", |
| 48 | }, |
| 49 | }, map[string]int{ |
| 50 | "1": 1, |
| 51 | "2": 2, |
| 52 | "3": 3, |
| 53 | }) |
| 54 | |
| 55 | require.Empty(t, candidates) |
| 56 | } |