@@ -6,10 +6,11 @@ import (
66 "fmt"
77 "testing"
88
9- "github.com/aws/aws-sdk-go/service/vpclattice"
109 "github.com/golang/mock/gomock"
1110 "github.com/stretchr/testify/assert"
1211
12+ "github.com/aws/aws-sdk-go/service/vpclattice"
13+
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415 gateway_api "sigs.k8s.io/gateway-api/apis/v1beta1"
1516
@@ -30,26 +31,42 @@ func Test_RuleModelBuild(t *testing.T) {
3031 var serviceimportKind gateway_api.Kind = "ServiceImport"
3132 var weight1 = int32 (10 )
3233 var weight2 = int32 (90 )
33- var namespace = gateway_api .Namespace ("default" )
34+ var namespace = gateway_api .Namespace ("testnamespace" )
35+ var namespace2 = gateway_api .Namespace ("testnamespace2" )
3436 var path1 = string ("/ver1" )
3537 var path2 = string ("/ver2" )
38+ var path3 = string ("/ver3" )
3639 var k8sPathMatchExactType = gateway_api .PathMatchExact
3740 var backendRef1 = gateway_api.BackendRef {
3841 BackendObjectReference : gateway_api.BackendObjectReference {
39- Name : "targetgroup1" ,
40- Namespace : & namespace ,
41- Kind : & serviceKind ,
42+ Name : "targetgroup1" ,
43+ Kind : & serviceKind ,
4244 },
4345 Weight : & weight1 ,
4446 }
4547 var backendRef2 = gateway_api.BackendRef {
48+ BackendObjectReference : gateway_api.BackendObjectReference {
49+ Name : "targetgroup2" ,
50+ Kind : & serviceimportKind ,
51+ },
52+ Weight : & weight2 ,
53+ }
54+ var backendRef1Namespace1 = gateway_api.BackendRef {
4655 BackendObjectReference : gateway_api.BackendObjectReference {
4756 Name : "targetgroup2" ,
4857 Namespace : & namespace ,
4958 Kind : & serviceimportKind ,
5059 },
5160 Weight : & weight2 ,
5261 }
62+ var backendRef1Namespace2 = gateway_api.BackendRef {
63+ BackendObjectReference : gateway_api.BackendObjectReference {
64+ Name : "targetgroup2" ,
65+ Namespace : & namespace2 ,
66+ Kind : & serviceimportKind ,
67+ },
68+ Weight : & weight2 ,
69+ }
5370 var backendServiceImportRef = gateway_api.BackendRef {
5471 BackendObjectReference : gateway_api.BackendObjectReference {
5572 Name : "targetgroup1" ,
@@ -221,6 +238,73 @@ func Test_RuleModelBuild(t *testing.T) {
221238 },
222239 },
223240 },
241+ {
242+ name : "rule, different namespace combination" ,
243+ gwListenerPort : * PortNumberPtr (80 ),
244+ wantErrIsNil : true ,
245+ k8sGetGatewayCall : true ,
246+ k8sGatewayReturnOK : true ,
247+ httpRoute : & gateway_api.HTTPRoute {
248+ ObjectMeta : metav1.ObjectMeta {
249+ Name : "service1" ,
250+ Namespace : "non-default" ,
251+ },
252+ Spec : gateway_api.HTTPRouteSpec {
253+ CommonRouteSpec : gateway_api.CommonRouteSpec {
254+ ParentRefs : []gateway_api.ParentReference {
255+ {
256+ Name : "mesh1" ,
257+ SectionName : & httpSectionName ,
258+ },
259+ },
260+ },
261+ Rules : []gateway_api.HTTPRouteRule {
262+ {
263+ Matches : []gateway_api.HTTPRouteMatch {
264+ {
265+ Path : & gateway_api.HTTPPathMatch {
266+ Value : & path1 ,
267+ },
268+ },
269+ },
270+ BackendRefs : []gateway_api.HTTPBackendRef {
271+ {
272+ BackendRef : backendRef1 ,
273+ },
274+ },
275+ },
276+ {
277+ Matches : []gateway_api.HTTPRouteMatch {
278+ {
279+ Path : & gateway_api.HTTPPathMatch {
280+ Value : & path2 ,
281+ },
282+ },
283+ },
284+ BackendRefs : []gateway_api.HTTPBackendRef {
285+ {
286+ BackendRef : backendRef1Namespace1 ,
287+ },
288+ },
289+ },
290+ {
291+ Matches : []gateway_api.HTTPRouteMatch {
292+ {
293+ Path : & gateway_api.HTTPPathMatch {
294+ Value : & path3 ,
295+ },
296+ },
297+ },
298+ BackendRefs : []gateway_api.HTTPBackendRef {
299+ {
300+ BackendRef : backendRef1Namespace2 ,
301+ },
302+ },
303+ },
304+ },
305+ },
306+ },
307+ },
224308 }
225309 for _ , tt := range tests {
226310 fmt .Printf ("Testing >>> %v\n " , tt .name )
@@ -288,6 +372,8 @@ func Test_RuleModelBuild(t *testing.T) {
288372 assert .Equal (t , gateway_api .ObjectName (tg .Name ), tt .httpRoute .Spec .Rules [i - 1 ].BackendRefs [j ].Name )
289373 if tt .httpRoute .Spec .Rules [i - 1 ].BackendRefs [j ].Namespace != nil {
290374 assert .Equal (t , gateway_api .Namespace (tg .Namespace ), * tt .httpRoute .Spec .Rules [i - 1 ].BackendRefs [j ].Namespace )
375+ } else {
376+ assert .Equal (t , tg .Namespace , tt .httpRoute .Namespace )
291377 }
292378
293379 if * tt .httpRoute .Spec .Rules [i - 1 ].BackendRefs [j ].Kind == "ServiceImport" {
0 commit comments