@@ -18,6 +18,7 @@ package workload
1818
1919import (
2020 "net/netip"
21+ "strings"
2122 "testing"
2223
2324 service_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
@@ -170,6 +171,21 @@ func Test_handleWorkload(t *testing.T) {
170171 hashNameClean (p )
171172}
172173
174+ func Test_handleServiceWithWaypoint (t * testing.T ) {
175+ // Mainly used to test whether processor can correctly handle
176+ // different types of waypoint address without panic.
177+ workloadMap := bpfcache .NewFakeWorkloadMap (t )
178+ p := newProcessor (workloadMap )
179+
180+ // Waypoint with network address.
181+ svc1 := createFakeService ("svc1" , "10.240.10.1" , "10.240.10.200" )
182+ // Waypoint with hostname.
183+ svc2 := createFakeService ("svc2" , "10.240.10.1" , "gateway.example.com/default" )
184+
185+ assert .NoError (t , p .handleService (svc1 ))
186+ assert .NoError (t , p .handleService (svc2 ))
187+ }
188+
173189func Test_hostnameNetworkMode (t * testing.T ) {
174190 workloadMap := bpfcache .NewFakeWorkloadMap (t )
175191 p := newProcessor (workloadMap )
@@ -378,6 +394,29 @@ func createFakeWorkload(ip string, networkMode workloadapi.NetworkMode) *workloa
378394}
379395
380396func createFakeService (name , ip , waypoint string ) * workloadapi.Service {
397+ var w * workloadapi.GatewayAddress
398+ res := strings .Split (waypoint , "/" )
399+ if len (res ) == 2 {
400+ w = & workloadapi.GatewayAddress {
401+ Destination : & workloadapi.GatewayAddress_Hostname {
402+ Hostname : & workloadapi.NamespacedHostname {
403+ Namespace : res [1 ],
404+ Hostname : res [0 ],
405+ },
406+ },
407+ HboneMtlsPort : 15008 ,
408+ }
409+ } else {
410+ w = & workloadapi.GatewayAddress {
411+ Destination : & workloadapi.GatewayAddress_Address {
412+ Address : & workloadapi.NetworkAddress {
413+ Address : netip .MustParseAddr (waypoint ).AsSlice (),
414+ },
415+ },
416+ HboneMtlsPort : 15008 ,
417+ }
418+ }
419+
381420 return & workloadapi.Service {
382421 Name : name ,
383422 Namespace : "default" ,
@@ -401,14 +440,7 @@ func createFakeService(name, ip, waypoint string) *workloadapi.Service {
401440 TargetPort : 82 ,
402441 },
403442 },
404- Waypoint : & workloadapi.GatewayAddress {
405- Destination : & workloadapi.GatewayAddress_Address {
406- Address : & workloadapi.NetworkAddress {
407- Address : netip .MustParseAddr (waypoint ).AsSlice (),
408- },
409- },
410- HboneMtlsPort : 15008 ,
411- },
443+ Waypoint : w ,
412444 }
413445}
414446
0 commit comments