Skip to content

Commit 8453573

Browse files
committed
replace v1beta1 for referencegrant on tests
1 parent 06427d4 commit 8453573

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

pkg/gateway/referencegrant_test.go

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ import (
66

77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88
"k8s.io/apimachinery/pkg/labels"
9-
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
10-
gatewayv1beta1listers "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1beta1"
9+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
10+
gatewayv1listers "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1"
1111
)
1212

1313
// fakeReferenceGrantLister is a mock implementation of ReferenceGrantLister for testing.
1414
type fakeReferenceGrantLister struct {
15-
grants []*gatewayv1beta1.ReferenceGrant
15+
grants []*gatewayv1.ReferenceGrant
1616
err error
1717
}
1818

1919
// newFakeReferenceGrantLister creates a new fakeReferenceGrantLister.
20-
func newFakeReferenceGrantLister(grants []*gatewayv1beta1.ReferenceGrant, err error) gatewayv1beta1listers.ReferenceGrantLister {
20+
func newFakeReferenceGrantLister(grants []*gatewayv1.ReferenceGrant, err error) gatewayv1listers.ReferenceGrantLister {
2121
return &fakeReferenceGrantLister{grants: grants, err: err}
2222
}
2323

2424
// List returns the stored grants or an error.
25-
func (f *fakeReferenceGrantLister) List(selector labels.Selector) ([]*gatewayv1beta1.ReferenceGrant, error) {
25+
func (f *fakeReferenceGrantLister) List(selector labels.Selector) ([]*gatewayv1.ReferenceGrant, error) {
2626
if f.err != nil {
2727
return nil, f.err
2828
}
2929
return f.grants, nil
3030
}
3131

3232
// Get returns the grant with the given name or an error.
33-
func (f *fakeReferenceGrantLister) Get(name string) (*gatewayv1beta1.ReferenceGrant, error) {
33+
func (f *fakeReferenceGrantLister) Get(name string) (*gatewayv1.ReferenceGrant, error) {
3434
if f.err != nil {
3535
return nil, f.err
3636
}
@@ -43,49 +43,49 @@ func (f *fakeReferenceGrantLister) Get(name string) (*gatewayv1beta1.ReferenceGr
4343
}
4444

4545
// ReferenceGrants returns a lister for a specific namespace.
46-
func (f *fakeReferenceGrantLister) ReferenceGrants(namespace string) gatewayv1beta1listers.ReferenceGrantNamespaceLister {
46+
func (f *fakeReferenceGrantLister) ReferenceGrants(namespace string) gatewayv1listers.ReferenceGrantNamespaceLister {
4747
// For testing purposes, we can return the lister itself, as we don't use the namespace in the mock List.
4848
// A more sophisticated mock could filter by namespace here.
4949
return f
5050
}
5151

5252
func TestIsCrossNamespaceRefAllowed(t *testing.T) {
53-
serviceKind := gatewayv1beta1.Kind("Service")
54-
httpRouteKind := gatewayv1beta1.Kind("HTTPRoute")
55-
gatewayGroup := gatewayv1beta1.Group("gateway.networking.k8s.io")
56-
coreGroup := gatewayv1beta1.Group("")
53+
serviceKind := gatewayv1.Kind("Service")
54+
httpRouteKind := gatewayv1.Kind("HTTPRoute")
55+
gatewayGroup := gatewayv1.Group("gateway.networking.k8s.io")
56+
coreGroup := gatewayv1.Group("")
5757

58-
specificServiceName := gatewayv1beta1.ObjectName("specific-service")
58+
specificServiceName := gatewayv1.ObjectName("specific-service")
5959

6060
testCases := []struct {
6161
name string
62-
from gatewayv1beta1.ReferenceGrantFrom
63-
to gatewayv1beta1.ReferenceGrantTo
62+
from gatewayv1.ReferenceGrantFrom
63+
to gatewayv1.ReferenceGrantTo
6464
toNamespace string
65-
grants []*gatewayv1beta1.ReferenceGrant
65+
grants []*gatewayv1.ReferenceGrant
6666
listerError error
6767
expected bool
6868
}{
6969
{
7070
name: "allowed by grant",
71-
from: gatewayv1beta1.ReferenceGrantFrom{
71+
from: gatewayv1.ReferenceGrantFrom{
7272
Group: gatewayGroup,
7373
Kind: httpRouteKind,
7474
Namespace: "default",
7575
},
76-
to: gatewayv1beta1.ReferenceGrantTo{
76+
to: gatewayv1.ReferenceGrantTo{
7777
Group: coreGroup,
7878
Kind: serviceKind,
7979
},
8080
toNamespace: "backend-ns",
81-
grants: []*gatewayv1beta1.ReferenceGrant{
81+
grants: []*gatewayv1.ReferenceGrant{
8282
{
8383
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
84-
Spec: gatewayv1beta1.ReferenceGrantSpec{
85-
From: []gatewayv1beta1.ReferenceGrantFrom{
84+
Spec: gatewayv1.ReferenceGrantSpec{
85+
From: []gatewayv1.ReferenceGrantFrom{
8686
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
8787
},
88-
To: []gatewayv1beta1.ReferenceGrantTo{
88+
To: []gatewayv1.ReferenceGrantTo{
8989
{Group: coreGroup, Kind: serviceKind},
9090
},
9191
},
@@ -95,25 +95,25 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
9595
},
9696
{
9797
name: "allowed by grant with specific resource name",
98-
from: gatewayv1beta1.ReferenceGrantFrom{
98+
from: gatewayv1.ReferenceGrantFrom{
9999
Group: gatewayGroup,
100100
Kind: httpRouteKind,
101101
Namespace: "default",
102102
},
103-
to: gatewayv1beta1.ReferenceGrantTo{
103+
to: gatewayv1.ReferenceGrantTo{
104104
Group: coreGroup,
105105
Kind: serviceKind,
106106
Name: &specificServiceName,
107107
},
108108
toNamespace: "backend-ns",
109-
grants: []*gatewayv1beta1.ReferenceGrant{
109+
grants: []*gatewayv1.ReferenceGrant{
110110
{
111111
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
112-
Spec: gatewayv1beta1.ReferenceGrantSpec{
113-
From: []gatewayv1beta1.ReferenceGrantFrom{
112+
Spec: gatewayv1.ReferenceGrantSpec{
113+
From: []gatewayv1.ReferenceGrantFrom{
114114
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
115115
},
116-
To: []gatewayv1beta1.ReferenceGrantTo{
116+
To: []gatewayv1.ReferenceGrantTo{
117117
{Group: coreGroup, Kind: serviceKind, Name: &specificServiceName},
118118
},
119119
},
@@ -123,24 +123,24 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
123123
},
124124
{
125125
name: "denied because from namespace does not match",
126-
from: gatewayv1beta1.ReferenceGrantFrom{
126+
from: gatewayv1.ReferenceGrantFrom{
127127
Group: gatewayGroup,
128128
Kind: httpRouteKind,
129129
Namespace: "another-ns", // Mismatch
130130
},
131-
to: gatewayv1beta1.ReferenceGrantTo{
131+
to: gatewayv1.ReferenceGrantTo{
132132
Group: coreGroup,
133133
Kind: serviceKind,
134134
},
135135
toNamespace: "backend-ns",
136-
grants: []*gatewayv1beta1.ReferenceGrant{
136+
grants: []*gatewayv1.ReferenceGrant{
137137
{
138138
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
139-
Spec: gatewayv1beta1.ReferenceGrantSpec{
140-
From: []gatewayv1beta1.ReferenceGrantFrom{
139+
Spec: gatewayv1.ReferenceGrantSpec{
140+
From: []gatewayv1.ReferenceGrantFrom{
141141
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
142142
},
143-
To: []gatewayv1beta1.ReferenceGrantTo{
143+
To: []gatewayv1.ReferenceGrantTo{
144144
{Group: coreGroup, Kind: serviceKind},
145145
},
146146
},
@@ -150,24 +150,24 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
150150
},
151151
{
152152
name: "denied because to kind does not match",
153-
from: gatewayv1beta1.ReferenceGrantFrom{
153+
from: gatewayv1.ReferenceGrantFrom{
154154
Group: gatewayGroup,
155155
Kind: httpRouteKind,
156156
Namespace: "default",
157157
},
158-
to: gatewayv1beta1.ReferenceGrantTo{
158+
to: gatewayv1.ReferenceGrantTo{
159159
Group: coreGroup,
160160
Kind: "Secret", // Mismatch
161161
},
162162
toNamespace: "backend-ns",
163-
grants: []*gatewayv1beta1.ReferenceGrant{
163+
grants: []*gatewayv1.ReferenceGrant{
164164
{
165165
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
166-
Spec: gatewayv1beta1.ReferenceGrantSpec{
167-
From: []gatewayv1beta1.ReferenceGrantFrom{
166+
Spec: gatewayv1.ReferenceGrantSpec{
167+
From: []gatewayv1.ReferenceGrantFrom{
168168
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
169169
},
170-
To: []gatewayv1beta1.ReferenceGrantTo{
170+
To: []gatewayv1.ReferenceGrantTo{
171171
{Group: coreGroup, Kind: serviceKind},
172172
},
173173
},
@@ -177,25 +177,25 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
177177
},
178178
{
179179
name: "denied because specific resource name does not match",
180-
from: gatewayv1beta1.ReferenceGrantFrom{
180+
from: gatewayv1.ReferenceGrantFrom{
181181
Group: gatewayGroup,
182182
Kind: httpRouteKind,
183183
Namespace: "default",
184184
},
185-
to: gatewayv1beta1.ReferenceGrantTo{
185+
to: gatewayv1.ReferenceGrantTo{
186186
Group: coreGroup,
187187
Kind: serviceKind,
188-
Name: func() *gatewayv1beta1.ObjectName { s := gatewayv1beta1.ObjectName("other-service"); return &s }(),
188+
Name: func() *gatewayv1.ObjectName { s := gatewayv1.ObjectName("other-service"); return &s }(),
189189
},
190190
toNamespace: "backend-ns",
191-
grants: []*gatewayv1beta1.ReferenceGrant{
191+
grants: []*gatewayv1.ReferenceGrant{
192192
{
193193
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
194-
Spec: gatewayv1beta1.ReferenceGrantSpec{
195-
From: []gatewayv1beta1.ReferenceGrantFrom{
194+
Spec: gatewayv1.ReferenceGrantSpec{
195+
From: []gatewayv1.ReferenceGrantFrom{
196196
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
197197
},
198-
To: []gatewayv1beta1.ReferenceGrantTo{
198+
To: []gatewayv1.ReferenceGrantTo{
199199
{Group: coreGroup, Kind: serviceKind, Name: &specificServiceName},
200200
},
201201
},
@@ -205,27 +205,27 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
205205
},
206206
{
207207
name: "no grants in namespace",
208-
from: gatewayv1beta1.ReferenceGrantFrom{
208+
from: gatewayv1.ReferenceGrantFrom{
209209
Group: gatewayGroup,
210210
Kind: httpRouteKind,
211211
Namespace: "default",
212212
},
213-
to: gatewayv1beta1.ReferenceGrantTo{
213+
to: gatewayv1.ReferenceGrantTo{
214214
Group: coreGroup,
215215
Kind: serviceKind,
216216
},
217217
toNamespace: "backend-ns",
218-
grants: []*gatewayv1beta1.ReferenceGrant{},
218+
grants: []*gatewayv1.ReferenceGrant{},
219219
expected: false,
220220
},
221221
{
222222
name: "lister returns error",
223-
from: gatewayv1beta1.ReferenceGrantFrom{
223+
from: gatewayv1.ReferenceGrantFrom{
224224
Group: gatewayGroup,
225225
Kind: httpRouteKind,
226226
Namespace: "default",
227227
},
228-
to: gatewayv1beta1.ReferenceGrantTo{
228+
to: gatewayv1.ReferenceGrantTo{
229229
Group: coreGroup,
230230
Kind: serviceKind,
231231
},
@@ -236,35 +236,35 @@ func TestIsCrossNamespaceRefAllowed(t *testing.T) {
236236
},
237237
{
238238
name: "multiple grants, one allows",
239-
from: gatewayv1beta1.ReferenceGrantFrom{
239+
from: gatewayv1.ReferenceGrantFrom{
240240
Group: gatewayGroup,
241241
Kind: httpRouteKind,
242242
Namespace: "default",
243243
},
244-
to: gatewayv1beta1.ReferenceGrantTo{
244+
to: gatewayv1.ReferenceGrantTo{
245245
Group: coreGroup,
246246
Kind: serviceKind,
247247
},
248248
toNamespace: "backend-ns",
249-
grants: []*gatewayv1beta1.ReferenceGrant{
249+
grants: []*gatewayv1.ReferenceGrant{
250250
{ // This one doesn't match
251251
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
252-
Spec: gatewayv1beta1.ReferenceGrantSpec{
253-
From: []gatewayv1beta1.ReferenceGrantFrom{
252+
Spec: gatewayv1.ReferenceGrantSpec{
253+
From: []gatewayv1.ReferenceGrantFrom{
254254
{Group: gatewayGroup, Kind: "OtherKind", Namespace: "default"},
255255
},
256-
To: []gatewayv1beta1.ReferenceGrantTo{
256+
To: []gatewayv1.ReferenceGrantTo{
257257
{Group: coreGroup, Kind: serviceKind},
258258
},
259259
},
260260
},
261261
{ // This one matches
262262
ObjectMeta: metav1.ObjectMeta{Namespace: "backend-ns"},
263-
Spec: gatewayv1beta1.ReferenceGrantSpec{
264-
From: []gatewayv1beta1.ReferenceGrantFrom{
263+
Spec: gatewayv1.ReferenceGrantSpec{
264+
From: []gatewayv1.ReferenceGrantFrom{
265265
{Group: gatewayGroup, Kind: httpRouteKind, Namespace: "default"},
266266
},
267-
To: []gatewayv1beta1.ReferenceGrantTo{
267+
To: []gatewayv1.ReferenceGrantTo{
268268
{Group: coreGroup, Kind: serviceKind},
269269
},
270270
},

0 commit comments

Comments
 (0)