Skip to content

Commit cb43b52

Browse files
committed
Move common constatns to common.go and add v1alpha2 to client schema
1 parent 06adc0e commit cb43b52

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

tests/cel/clientsettingspolicy_test.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,6 @@ import (
1212
ngfHelpers "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers"
1313
)
1414

15-
const (
16-
GatewayKind = "Gateway"
17-
HTTPRouteKind = "HTTPRoute"
18-
GRPCRouteKind = "GRPCRoute"
19-
TCPRouteKind = "TCPRoute"
20-
InvalidKind = "InvalidKind"
21-
)
22-
23-
const (
24-
GatewayGroup = "gateway.networking.k8s.io"
25-
InvalidGroup = "invalid.networking.k8s.io"
26-
DiscoveryGroup = "discovery.k8s.io/v1"
27-
)
28-
29-
const (
30-
ExpectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
31-
ExpectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
32-
)
33-
34-
const (
35-
PolicyName = "test-policy"
36-
TargetRef = "targetRef-name"
37-
)
38-
3915
func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
4016
t.Parallel()
4117
tests := []struct {
@@ -155,7 +131,7 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
155131
t.Helper()
156132
g := NewWithT(t)
157133

158-
k8sClient, err := GetKubernetesClient()
134+
k8sClient, err := GetKubernetesClient(t)
159135

160136
g.Expect(err).ToNot(HaveOccurred())
161137

tests/cel/common.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
package cel
22

33
import (
4+
"testing"
5+
46
"k8s.io/apimachinery/pkg/runtime"
57
controllerruntime "sigs.k8s.io/controller-runtime"
68
"sigs.k8s.io/controller-runtime/pkg/client"
79

810
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
11+
ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2"
12+
)
13+
14+
const (
15+
GatewayKind = "Gateway"
16+
HTTPRouteKind = "HTTPRoute"
17+
GRPCRouteKind = "GRPCRoute"
18+
TCPRouteKind = "TCPRoute"
19+
InvalidKind = "InvalidKind"
20+
)
21+
22+
const (
23+
GatewayGroup = "gateway.networking.k8s.io"
24+
InvalidGroup = "invalid.networking.k8s.io"
25+
DiscoveryGroup = "discovery.k8s.io/v1"
26+
)
27+
28+
const (
29+
ExpectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
30+
ExpectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
31+
)
32+
33+
const (
34+
PolicyName = "test-policy"
35+
TargetRef = "targetRef-name"
936
)
1037

1138
// GetKubernetesClient returns a client connected to a real Kubernetes cluster.
12-
func GetKubernetesClient() (k8sClient client.Client, err error) {
39+
func GetKubernetesClient(t *testing.T) (k8sClient client.Client, err error) {
40+
t.Helper()
1341
// Use controller-runtime to get cluster connection
1442
k8sConfig, err := controllerruntime.GetConfig()
1543
if err != nil {
@@ -21,6 +49,9 @@ func GetKubernetesClient() (k8sClient client.Client, err error) {
2149
if err = ngfAPIv1alpha1.AddToScheme(scheme); err != nil {
2250
return nil, err
2351
}
52+
if err = ngfAPIv1alpha2.AddToScheme(scheme); err != nil {
53+
return nil, err
54+
}
2455
// Create a new client with the scheme and return it
2556
return client.New(k8sConfig, client.Options{Scheme: scheme})
2657
}

0 commit comments

Comments
 (0)