Skip to content

Commit a827fea

Browse files
edipascaleFrostman
authored andcommitted
chore: unit-test for dataplane config builder
Signed-off-by: Emanuele Di Pascale <[email protected]>
1 parent 75df44b commit a827fea

File tree

2 files changed

+453
-4
lines changed

2 files changed

+453
-4
lines changed

pkg/agent/dataplane.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package agent
55

66
import (
7+
"errors"
78
"fmt"
89
"net/netip"
910

@@ -18,6 +19,8 @@ const (
1819
IfVTEP = "vtep"
1920
)
2021

22+
var errInvalidDPConfig = errors.New("invalid dataplane config")
23+
2124
func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig, error) {
2225
protoIP, err := netip.ParsePrefix(ag.Spec.Gateway.ProtocolIP)
2326
if err != nil {
@@ -117,10 +120,10 @@ func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig,
117120
Rule: &dataplane.PeeringIPs_Cidr{Cidr: subnetCIDR},
118121
})
119122
} else {
120-
return nil, fmt.Errorf("unknown VPC subnet %s in peering %s / vpc %s", ipEntry.VPCSubnet, peeringName, vpcName) //nolint:goerr113
123+
return nil, fmt.Errorf("unknown VPC subnet %s in peering %s / vpc %s: %w", ipEntry.VPCSubnet, peeringName, vpcName, errInvalidDPConfig)
121124
}
122125
default:
123-
return nil, fmt.Errorf("invalid IP entry in peering %s / vpc %s: %v", peeringName, vpcName, ipEntry) //nolint:goerr113
126+
return nil, fmt.Errorf("invalid IP entry in peering %s / vpc %s: %v: %w", peeringName, vpcName, ipEntry, errInvalidDPConfig)
124127
}
125128
}
126129

@@ -136,7 +139,7 @@ func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig,
136139
Rule: &dataplane.PeeringAs_Not{Not: asEntry.Not},
137140
})
138141
default:
139-
return nil, fmt.Errorf("invalid IP entry in peering %s / vpc %s: %v", peeringName, vpcName, asEntry) //nolint:goerr113
142+
return nil, fmt.Errorf("invalid IP entry in peering %s / vpc %s: %v: %w", peeringName, vpcName, asEntry, errInvalidDPConfig)
140143
}
141144
}
142145

@@ -152,7 +155,7 @@ func buildDataplaneConfig(ag *gwintapi.GatewayAgent) (*dataplane.GatewayConfig,
152155

153156
if expose.NAT != nil {
154157
if expose.NAT.Stateful != nil && expose.NAT.Stateless != nil {
155-
return nil, fmt.Errorf("invalid NAT entry in peering %s / vpc %s: both Stateful and Stateless set", peeringName, vpcName) //nolint:goerr113
158+
return nil, fmt.Errorf("invalid NAT entry in peering %s / vpc %s: both Stateful and Stateless set: %w", peeringName, vpcName, errInvalidDPConfig)
156159
}
157160

158161
if expose.NAT.Stateful != nil {

0 commit comments

Comments
 (0)