mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-12 16:30:09 +01:00
[management] Fix policy tests (#3135)
- Add firewall rule isEqual method - Fix tests
This commit is contained in:
parent
18b049cd24
commit
03fd656344
@ -76,7 +76,7 @@ func TestAccount_getPeersByPolicy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"GroupWorkstations": {
|
"GroupWorkstations": {
|
||||||
ID: "GroupWorkstations",
|
ID: "GroupWorkstations",
|
||||||
Name: "All",
|
Name: "GroupWorkstations",
|
||||||
Peers: []string{
|
Peers: []string{
|
||||||
"peerB",
|
"peerB",
|
||||||
"peerA",
|
"peerA",
|
||||||
@ -280,10 +280,16 @@ func TestAccount_getPeersByPolicy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Len(t, firewallRules, len(epectedFirewallRules))
|
assert.Len(t, firewallRules, len(epectedFirewallRules))
|
||||||
slices.SortFunc(epectedFirewallRules, sortFunc())
|
|
||||||
slices.SortFunc(firewallRules, sortFunc())
|
for _, rule := range firewallRules {
|
||||||
for i := range firewallRules {
|
contains := false
|
||||||
assert.Equal(t, epectedFirewallRules[i], firewallRules[i])
|
for _, expectedRule := range epectedFirewallRules {
|
||||||
|
if rule.IsEqual(expectedRule) {
|
||||||
|
contains = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.True(t, contains, "rule not found in expected rules %#v", rule)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,15 @@ type FirewallRule struct {
|
|||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEqual checks if two firewall rules are equal.
|
||||||
|
func (r *FirewallRule) IsEqual(other *FirewallRule) bool {
|
||||||
|
return r.PeerIP == other.PeerIP &&
|
||||||
|
r.Direction == other.Direction &&
|
||||||
|
r.Action == other.Action &&
|
||||||
|
r.Protocol == other.Protocol &&
|
||||||
|
r.Port == other.Port
|
||||||
|
}
|
||||||
|
|
||||||
// generateRouteFirewallRules generates a list of firewall rules for a given route.
|
// generateRouteFirewallRules generates a list of firewall rules for a given route.
|
||||||
func generateRouteFirewallRules(ctx context.Context, route *nbroute.Route, rule *PolicyRule, groupPeers []*nbpeer.Peer, direction int) []*RouteFirewallRule {
|
func generateRouteFirewallRules(ctx context.Context, route *nbroute.Route, rule *PolicyRule, groupPeers []*nbpeer.Peer, direction int) []*RouteFirewallRule {
|
||||||
rulesExists := make(map[string]struct{})
|
rulesExists := make(map[string]struct{})
|
||||||
|
Loading…
Reference in New Issue
Block a user