From 75833e0d5d1f6c1778072a710eb24a66c52646f9 Mon Sep 17 00:00:00 2001 From: Federico Paolinelli Date: Wed, 26 Jun 2024 17:04:43 +0200 Subject: [PATCH] Conversion unit tests: remove the empty fields from expected Now that we use EquateEmpty, the expected value can be shorter and more compact, making the tests easier to navigate and handle. Signed-off-by: Federico Paolinelli --- internal/controller/api_to_config_test.go | 282 +--------------------- 1 file changed, 12 insertions(+), 270 deletions(-) diff --git a/internal/controller/api_to_config_test.go b/internal/controller/api_to_config_test.go index d3b7eccd..f526f386 100644 --- a/internal/controller/api_to_config_test.go +++ b/internal/controller/api_to_config_test.go @@ -86,23 +86,11 @@ func TestConversion(t *testing.T) { HoldTime: ptr.To[uint64](40), ConnectTime: ptr.To(uint64(2)), DisableMP: true, - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, - VRF: "", IPV4Prefixes: []string{"192.0.2.0/24"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -158,23 +146,11 @@ func TestConversion(t *testing.T) { HoldTime: ptr.To[uint64](40), ConnectTime: ptr.To(uint64(2)), DisableMP: true, - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, - VRF: "", IPV4Prefixes: []string{"192.0.2.0/24"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -198,7 +174,6 @@ func TestConversion(t *testing.T) { Address: "192.0.2.7", }, }, - VRF: "", Prefixes: []string{"192.0.2.0/24"}, }, { @@ -230,35 +205,15 @@ func TestConversion(t *testing.T) { Name: "65011@192.0.2.6", ASN: 65011, Addr: "192.0.2.6", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv4, Name: "65012@192.0.2.7", ASN: 65012, Addr: "192.0.2.7", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, - VRF: "", IPV4Prefixes: []string{"192.0.2.0/24"}, - IPV6Prefixes: []string{}, }, { MyASN: 65013, @@ -270,23 +225,12 @@ func TestConversion(t *testing.T) { ASN: 65014, Addr: "2001:db8::4", VRFName: "vrf2", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "vrf2", - IPV4Prefixes: []string{}, IPV6Prefixes: []string{"2001:db8::/64"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -326,22 +270,12 @@ func TestConversion(t *testing.T) { Name: "65021@192.0.2.11", ASN: 65021, Addr: "192.0.2.11", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, IPV4Prefixes: []string{"192.0.2.0/24"}, IPV6Prefixes: []string{"2001:db8::/64"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -350,12 +284,9 @@ func TestConversion(t *testing.T) { fromK8s: []v1beta1.FRRConfiguration{ {}, }, - secrets: map[string]v1.Secret{}, - expected: &frr.Config{ - Routers: []*frr.RouterConfig{}, - BFDProfiles: []frr.BFDProfile{}, - }, - err: nil, + secrets: map[string]v1.Secret{}, + expected: &frr.Config{}, + err: nil, }, { name: "Non default VRF", @@ -394,23 +325,12 @@ func TestConversion(t *testing.T) { ASN: 65031, Addr: "192.0.2.16", VRFName: "vrf1", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "vrf1", IPV4Prefixes: []string{"192.0.2.0/24"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -462,20 +382,12 @@ func TestConversion(t *testing.T) { Prefix: "192.0.2.0/24", }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, IPV4Prefixes: []string{"192.0.2.0/24"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -540,13 +452,7 @@ func TestConversion(t *testing.T) { Prefix: "192.0.4.0/24", }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv4, @@ -575,18 +481,12 @@ func TestConversion(t *testing.T) { }, }, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, IPV4Prefixes: []string{"192.0.2.0/24", "192.0.3.0/24", "192.0.4.0/24"}, IPV6Prefixes: []string{"2001:db8::/64"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -708,13 +608,7 @@ func TestConversion(t *testing.T) { LocalPref: 100, }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv4, @@ -750,18 +644,12 @@ func TestConversion(t *testing.T) { }, }, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, IPV4Prefixes: []string{"192.0.2.0/24", "192.0.3.0/24", "192.0.4.0/24", "192.0.6.0/24"}, IPV6Prefixes: []string{"2001:db8::/64"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -984,31 +872,18 @@ func TestConversion(t *testing.T) { expected: &frr.Config{ Routers: []*frr.RouterConfig{ { - MyASN: 65040, - RouterID: "192.0.2.20", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + MyASN: 65040, + RouterID: "192.0.2.20", Neighbors: []*frr.NeighborConfig{ { IPFamily: ipfamily.IPv4, Name: "65041@192.0.2.21", ASN: 65041, Addr: "192.0.2.21", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - All: true, - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1058,10 +933,6 @@ func TestConversion(t *testing.T) { Name: "65041@192.0.2.21", ASN: 65041, Addr: "192.0.2.21", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, Incoming: frr.AllowedIn{ All: false, PrefixesV4: []frr.IncomingFilter{ @@ -1073,12 +944,10 @@ func TestConversion(t *testing.T) { {IPFamily: "ipv6", Prefix: "2001:db8::/64"}, }, }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1128,10 +997,6 @@ func TestConversion(t *testing.T) { Name: "65041@192.0.2.21", ASN: 65041, Addr: "192.0.2.21", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, Incoming: frr.AllowedIn{ All: false, PrefixesV4: []frr.IncomingFilter{ @@ -1143,7 +1008,6 @@ func TestConversion(t *testing.T) { {IPFamily: "ipv6", Prefix: "2001:db8::/64"}, }, }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, }, @@ -1288,7 +1152,6 @@ func TestConversion(t *testing.T) { Communities: []string{"10:101"}, }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, Incoming: frr.AllowedIn{ PrefixesV4: []frr.IncomingFilter{ @@ -1301,17 +1164,13 @@ func TestConversion(t *testing.T) { Prefix: "192.0.101.0/24", }, }, - PrefixesV6: []frr.IncomingFilter{}, }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "", IPV4Prefixes: []string{"192.0.2.10/32", "192.0.2.11/32"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1390,10 +1249,6 @@ func TestConversion(t *testing.T) { Name: "65012@192.0.2.7", ASN: 65012, Addr: "192.0.2.7", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, Incoming: frr.AllowedIn{ PrefixesV4: []frr.IncomingFilter{ { @@ -1424,17 +1279,13 @@ func TestConversion(t *testing.T) { GE: 26, }, }, - PrefixesV6: []frr.IncomingFilter{}, }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "", IPV4Prefixes: []string{"192.0.2.10/32", "192.0.2.11/32"}, - IPV6Prefixes: []string{}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1603,13 +1454,7 @@ func TestConversion(t *testing.T) { Prefix: "192.0.3.2/32", }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv4, @@ -1641,18 +1486,11 @@ func TestConversion(t *testing.T) { LocalPref: 200, }, }, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "", IPV4Prefixes: []string{"192.0.2.10/32", "192.0.2.11/32", "192.0.3.1/32", "192.0.3.2/32", "192.0.3.20/32", "192.0.3.21/32"}, - IPV6Prefixes: []string{}, }, { MyASN: 65013, @@ -1671,13 +1509,7 @@ func TestConversion(t *testing.T) { Prefix: "192.0.2.5/32", }, }, - PrefixesV6: []frr.OutgoingFilter{}, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv6, @@ -1703,11 +1535,6 @@ func TestConversion(t *testing.T) { }, }, }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, VRF: "vrf2", @@ -1715,7 +1542,6 @@ func TestConversion(t *testing.T) { IPV6Prefixes: []string{"2001:db8::/64", "2001:db9::/96"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1796,15 +1622,6 @@ func TestConversion(t *testing.T) { ASN: 65012, Addr: "192.0.2.7", Password: "password1", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv4, @@ -1812,20 +1629,9 @@ func TestConversion(t *testing.T) { ASN: 65012, Addr: "192.0.2.8", Password: "cleartext-password", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, - VRF: "", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + VRF: "", }, { MyASN: 65013, @@ -1837,15 +1643,6 @@ func TestConversion(t *testing.T) { ASN: 65017, Addr: "192.0.2.7", VRFName: "vrf2", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, { IPFamily: ipfamily.IPv6, @@ -1854,23 +1651,11 @@ func TestConversion(t *testing.T) { Addr: "2001:db8::4", VRFName: "vrf2", Password: "password2", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, - VRF: "vrf2", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + VRF: "vrf2", }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -1973,12 +1758,8 @@ func TestConversion(t *testing.T) { expected: &frr.Config{ Routers: []*frr.RouterConfig{ { - MyASN: 65001, - RouterID: "192.0.2.1", - Neighbors: []*frr.NeighborConfig{}, - VRF: "", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + MyASN: 65001, + RouterID: "192.0.2.1", }, }, BFDProfiles: []frr.BFDProfile{}, @@ -2030,15 +1811,10 @@ func TestConversion(t *testing.T) { expected: &frr.Config{ Routers: []*frr.RouterConfig{ { - MyASN: 65001, - RouterID: "192.0.2.1", - Neighbors: []*frr.NeighborConfig{}, - VRF: "", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + MyASN: 65001, + RouterID: "192.0.2.1", }, }, - BFDProfiles: []frr.BFDProfile{}, ExtraConfig: "bar\nfoo\nbar\nbaz\n", }, err: nil, @@ -2088,16 +1864,6 @@ func TestConversion(t *testing.T) { ASN: 65041, Addr: "192.0.2.21", BFDProfile: "bfd1", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - All: false, - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, - AlwaysBlock: []frr.IncomingFilter{}, }, }, }, @@ -2414,14 +2180,6 @@ func TestConversion(t *testing.T) { Name: "65011@192.0.2.6", ASN: 65011, Addr: "192.0.2.6", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, AlwaysBlock: []frr.IncomingFilter{ { IPFamily: ipfamily.IPv4, @@ -2435,9 +2193,6 @@ func TestConversion(t *testing.T) { }, }, }, - VRF: "", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, }, { MyASN: 65013, @@ -2449,14 +2204,6 @@ func TestConversion(t *testing.T) { ASN: 65014, Addr: "2001:db8::4", VRFName: "vrf2", - Outgoing: frr.AllowedOut{ - PrefixesV4: []frr.OutgoingFilter{}, - PrefixesV6: []frr.OutgoingFilter{}, - }, - Incoming: frr.AllowedIn{ - PrefixesV4: []frr.IncomingFilter{}, - PrefixesV6: []frr.IncomingFilter{}, - }, AlwaysBlock: []frr.IncomingFilter{ { IPFamily: ipfamily.IPv4, @@ -2470,12 +2217,9 @@ func TestConversion(t *testing.T) { }, }, }, - VRF: "vrf2", - IPV4Prefixes: []string{}, - IPV6Prefixes: []string{}, + VRF: "vrf2", }, }, - BFDProfiles: []frr.BFDProfile{}, }, err: nil, }, @@ -2634,9 +2378,7 @@ func TestConversion(t *testing.T) { IPV6Prefixes: []string{"2001:db9::/64"}, }, }, - BFDProfiles: []frr.BFDProfile{}, }, - secrets: map[string]v1.Secret{}, }, { name: "Multiple Routers import VRFs, advertise",