Skip to content

Commit 93cb3f3

Browse files
authored
chore(tests): add CommonRouteSpec mock to reduce parser tests length (#3109)
1 parent 318e60f commit 93cb3f3

File tree

1 file changed

+21
-73
lines changed

1 file changed

+21
-73
lines changed

internal/dataplane/parser/translate_httproute_test.go

Lines changed: 21 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
6363
Namespace: corev1.NamespaceDefault,
6464
},
6565
Spec: gatewayv1beta1.HTTPRouteSpec{
66-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
67-
ParentRefs: []gatewayv1beta1.ParentReference{{
68-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
69-
}},
70-
},
66+
CommonRouteSpec: commonRouteSpecMock("fake-gateway-1"),
7167
Hostnames: []gatewayv1beta1.Hostname{
7268
"konghq.com",
7369
"www.konghq.com",
@@ -126,11 +122,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
126122
Namespace: corev1.NamespaceDefault,
127123
},
128124
Spec: gatewayv1beta1.HTTPRouteSpec{
129-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
130-
ParentRefs: []gatewayv1beta1.ParentReference{{
131-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
132-
}},
133-
},
125+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
134126
// no hostnames present
135127
Rules: []gatewayv1beta1.HTTPRouteRule{{
136128
// no match rules present
@@ -158,11 +150,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
158150
Namespace: corev1.NamespaceDefault,
159151
},
160152
Spec: gatewayv1beta1.HTTPRouteSpec{
161-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
162-
ParentRefs: []gatewayv1beta1.ParentReference{{
163-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
164-
}},
165-
},
153+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
166154
Rules: []gatewayv1beta1.HTTPRouteRule{{
167155
Matches: []gatewayv1beta1.HTTPRouteMatch{{
168156
Path: &gatewayv1beta1.HTTPPathMatch{
@@ -223,11 +211,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
223211
Namespace: corev1.NamespaceDefault,
224212
},
225213
Spec: gatewayv1beta1.HTTPRouteSpec{
226-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
227-
ParentRefs: []gatewayv1beta1.ParentReference{{
228-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
229-
}},
230-
},
214+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
231215
},
232216
}},
233217
expected: func(routes []*gatewayv1beta1.HTTPRoute) ingressRules {
@@ -248,11 +232,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
248232
Namespace: corev1.NamespaceDefault,
249233
},
250234
Spec: gatewayv1beta1.HTTPRouteSpec{
251-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
252-
ParentRefs: []gatewayv1beta1.ParentReference{{
253-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
254-
}},
255-
},
235+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
256236
Rules: []gatewayv1beta1.HTTPRouteRule{{
257237
Matches: []gatewayv1beta1.HTTPRouteMatch{{
258238
QueryParams: []gatewayv1beta1.HTTPQueryParamMatch{{
@@ -285,11 +265,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
285265
Namespace: corev1.NamespaceDefault,
286266
},
287267
Spec: gatewayv1beta1.HTTPRouteSpec{
288-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
289-
ParentRefs: []gatewayv1beta1.ParentReference{{
290-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
291-
}},
292-
},
268+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
293269
Rules: []gatewayv1beta1.HTTPRouteRule{{
294270
Matches: []gatewayv1beta1.HTTPRouteMatch{{
295271
Path: &gatewayv1beta1.HTTPPathMatch{
@@ -350,11 +326,7 @@ func getIngressRulesFromHTTPRoutesCommonTestCases() []testCaseIngressRulesFromHT
350326
Namespace: corev1.NamespaceDefault,
351327
},
352328
Spec: gatewayv1beta1.HTTPRouteSpec{
353-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
354-
ParentRefs: []gatewayv1beta1.ParentReference{{
355-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
356-
}},
357-
},
329+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
358330
Rules: []gatewayv1beta1.HTTPRouteRule{{
359331
Matches: []gatewayv1beta1.HTTPRouteMatch{{
360332
Path: &gatewayv1beta1.HTTPPathMatch{
@@ -423,11 +395,7 @@ func getIngressRulesFromHTTPRoutesCombinedRoutesTestCases() []testCaseIngressRul
423395
Namespace: corev1.NamespaceDefault,
424396
},
425397
Spec: gatewayv1beta1.HTTPRouteSpec{
426-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
427-
ParentRefs: []gatewayv1beta1.ParentReference{{
428-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
429-
}},
430-
},
398+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
431399
Rules: []gatewayv1beta1.HTTPRouteRule{{
432400
Matches: []gatewayv1beta1.HTTPRouteMatch{{
433401
Path: &gatewayv1beta1.HTTPPathMatch{
@@ -518,13 +486,7 @@ func getIngressRulesFromHTTPRoutesCombinedRoutesTestCases() []testCaseIngressRul
518486
Namespace: corev1.NamespaceDefault,
519487
},
520488
Spec: gatewayv1beta1.HTTPRouteSpec{
521-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
522-
ParentRefs: []gatewayv1beta1.ParentReference{
523-
{
524-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
525-
},
526-
},
527-
},
489+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
528490
Rules: []gatewayv1beta1.HTTPRouteRule{
529491
{
530492
Matches: []gatewayv1beta1.HTTPRouteMatch{
@@ -591,13 +553,7 @@ func getIngressRulesFromHTTPRoutesCombinedRoutesTestCases() []testCaseIngressRul
591553
}},
592554
Parent: &gatewayv1beta1.HTTPRoute{
593555
Spec: gatewayv1beta1.HTTPRouteSpec{
594-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
595-
ParentRefs: []gatewayv1beta1.ParentReference{
596-
{
597-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
598-
},
599-
},
600-
},
556+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
601557
Rules: []gatewayv1beta1.HTTPRouteRule{
602558
{
603559
Matches: []gatewayv1beta1.HTTPRouteMatch{
@@ -699,13 +655,7 @@ func getIngressRulesFromHTTPRoutesCombinedRoutesTestCases() []testCaseIngressRul
699655
Namespace: corev1.NamespaceDefault,
700656
},
701657
Spec: gatewayv1beta1.HTTPRouteSpec{
702-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
703-
ParentRefs: []gatewayv1beta1.ParentReference{
704-
{
705-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
706-
},
707-
},
708-
},
658+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
709659
Rules: []gatewayv1beta1.HTTPRouteRule{
710660
{
711661
Matches: []gatewayv1beta1.HTTPRouteMatch{
@@ -804,13 +754,7 @@ func getIngressRulesFromHTTPRoutesCombinedRoutesTestCases() []testCaseIngressRul
804754
},
805755
Parent: &gatewayv1beta1.HTTPRoute{
806756
Spec: gatewayv1beta1.HTTPRouteSpec{
807-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
808-
ParentRefs: []gatewayv1beta1.ParentReference{
809-
{
810-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
811-
},
812-
},
813-
},
757+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
814758
Rules: []gatewayv1beta1.HTTPRouteRule{
815759
{
816760
Matches: []gatewayv1beta1.HTTPRouteMatch{
@@ -1096,11 +1040,7 @@ func TestIngressRulesFromHTTPRoutes_RegexPrefix(t *testing.T) {
10961040
Namespace: corev1.NamespaceDefault,
10971041
},
10981042
Spec: gatewayv1beta1.HTTPRouteSpec{
1099-
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
1100-
ParentRefs: []gatewayv1beta1.ParentReference{{
1101-
Name: gatewayv1beta1.ObjectName("fake-gateway"),
1102-
}},
1103-
},
1043+
CommonRouteSpec: commonRouteSpecMock("fake-gateway"),
11041044
Rules: []gatewayv1beta1.HTTPRouteRule{{
11051045
Matches: []gatewayv1beta1.HTTPRouteMatch{{
11061046
Path: &gatewayv1beta1.HTTPPathMatch{
@@ -1216,3 +1156,11 @@ func k8sObjectInfoOfHTTPRoute(route *gatewayv1beta1.HTTPRoute) util.K8sObjectInf
12161156
},
12171157
}
12181158
}
1159+
1160+
func commonRouteSpecMock(parentReferentName string) gatewayv1beta1.CommonRouteSpec {
1161+
return gatewayv1beta1.CommonRouteSpec{
1162+
ParentRefs: []gatewayv1beta1.ParentReference{{
1163+
Name: gatewayv1beta1.ObjectName(parentReferentName),
1164+
}},
1165+
}
1166+
}

0 commit comments

Comments
 (0)