Skip to content

Commit f30f117

Browse files
committed
unexport consnts and functions in cel common file
1 parent 9217339 commit f30f117

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

tests/Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,3 @@ test-cel-validation:
198198
echo "Running test: $(CEL_TEST_TARGET) in ./cel"; \
199199
go test -v ./cel -run "$(CEL_TEST_TARGET)"; \
200200
fi
201-
202-
203-
# Set up a kind cluster, install NGF CRDs, and run CEL validation tests
204-
.PHONY: setup-and-test-cel-validation
205-
setup-and-test-cel-validation:
206-
kind create cluster --name $(CLUSTER_NAME) || true
207-
kubectl kustomize ../config/crd | kubectl apply -f -
208-
$(MAKE) test-cel-validation

tests/cel/clientsettingspolicy_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,46 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
2222
name: "Validate TargetRef of kind Gateway is allowed",
2323
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
2424
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
25-
Kind: GatewayKind,
26-
Group: GatewayGroup,
25+
Kind: gatewayKind,
26+
Group: gatewayGroup,
2727
},
2828
},
2929
},
3030
{
3131
name: "Validate TargetRef of kind HTTPRoute is allowed",
3232
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
3333
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
34-
Kind: HTTPRouteKind,
35-
Group: GatewayGroup,
34+
Kind: httpRouteKind,
35+
Group: gatewayGroup,
3636
},
3737
},
3838
},
3939
{
4040
name: "Validate TargetRef of kind GRPCRoute is allowed",
4141
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
4242
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
43-
Kind: GRPCRouteKind,
44-
Group: GatewayGroup,
43+
Kind: grpcRouteKind,
44+
Group: gatewayGroup,
4545
},
4646
},
4747
},
4848
{
4949
name: "Validate Invalid TargetRef Kind is not allowed",
50-
wantErrors: []string{ExpectedTargetRefKindError},
50+
wantErrors: []string{expectedTargetRefKindError},
5151
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
5252
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
53-
Kind: InvalidKind,
54-
Group: GatewayGroup,
53+
Kind: invalidKind,
54+
Group: gatewayGroup,
5555
},
5656
},
5757
},
5858
{
5959
name: "Validate TCPRoute TargetRef Kind is not allowed",
60-
wantErrors: []string{ExpectedTargetRefKindError},
60+
wantErrors: []string{expectedTargetRefKindError},
6161
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
6262
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
63-
Kind: TCPRouteKind,
64-
Group: GatewayGroup,
63+
Kind: tcpRouteKind,
64+
Group: gatewayGroup,
6565
},
6666
},
6767
},
@@ -86,28 +86,28 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
8686
name: "Validate gateway.networking.k8s.io TargetRef Group is allowed",
8787
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
8888
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
89-
Kind: GatewayKind,
90-
Group: GatewayGroup,
89+
Kind: gatewayKind,
90+
Group: gatewayGroup,
9191
},
9292
},
9393
},
9494
{
9595
name: "Validate invalid.networking.k8s.io TargetRef Group is not allowed",
96-
wantErrors: []string{ExpectedTargetRefGroupError},
96+
wantErrors: []string{expectedTargetRefGroupError},
9797
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
9898
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
99-
Kind: GatewayKind,
100-
Group: InvalidGroup,
99+
Kind: gatewayKind,
100+
Group: invalidGroup,
101101
},
102102
},
103103
},
104104
{
105105
name: "Validate discovery.k8s.io/v1 TargetRef Group is not allowed",
106-
wantErrors: []string{ExpectedTargetRefGroupError},
106+
wantErrors: []string{expectedTargetRefGroupError},
107107
policySpec: ngfAPIv1alpha1.ClientSettingsPolicySpec{
108108
TargetRef: gatewayv1alpha2.LocalPolicyTargetReference{
109-
Kind: GatewayKind,
110-
Group: DiscoveryGroup,
109+
Kind: gatewayKind,
110+
Group: discoveryGroup,
111111
},
112112
},
113113
},
@@ -130,19 +130,19 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
130130
t.Helper()
131131
g := NewWithT(t)
132132

133-
k8sClient, err := GetKubernetesClient(t)
133+
k8sClient, err := getKubernetesClient(t)
134134

135135
g.Expect(err).ToNot(HaveOccurred())
136136

137137
g.Expect(err).ToNot(HaveOccurred())
138138
policySpec := tt.policySpec
139-
policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(UniqueResourceName(TargetRef))
140-
policyName := UniqueResourceName(PolicyName)
139+
policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(UniqueResourceName(testTargetRefName))
140+
policyName := UniqueResourceName(testPolicyName)
141141

142142
clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{
143143
ObjectMeta: controllerruntime.ObjectMeta{
144144
Name: policyName,
145-
Namespace: "default",
145+
Namespace: defaultNamespace,
146146
},
147147
Spec: policySpec,
148148
}

tests/cel/common.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,35 @@ import (
1414
)
1515

1616
const (
17-
GatewayKind = "Gateway"
18-
HTTPRouteKind = "HTTPRoute"
19-
GRPCRouteKind = "GRPCRoute"
20-
TCPRouteKind = "TCPRoute"
21-
InvalidKind = "InvalidKind"
17+
gatewayKind = "Gateway"
18+
httpRouteKind = "HTTPRoute"
19+
grpcRouteKind = "GRPCRoute"
20+
tcpRouteKind = "TCPRoute"
21+
invalidKind = "InvalidKind"
2222
)
2323

2424
const (
25-
GatewayGroup = "gateway.networking.k8s.io"
26-
InvalidGroup = "invalid.networking.k8s.io"
27-
DiscoveryGroup = "discovery.k8s.io/v1"
25+
gatewayGroup = "gateway.networking.k8s.io"
26+
invalidGroup = "invalid.networking.k8s.io"
27+
discoveryGroup = "discovery.k8s.io/v1"
2828
)
2929

3030
const (
31-
ExpectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
32-
ExpectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
31+
expectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
32+
expectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
3333
)
3434

3535
const (
36-
PolicyName = "test-policy"
37-
TargetRef = "targetRef-name"
36+
defaultNamespace = "default"
37+
)
38+
39+
const (
40+
testPolicyName = "test-policy"
41+
testTargetRefName = "test-targetRef"
3842
)
3943

4044
// GetKubernetesClient returns a client connected to a real Kubernetes cluster.
41-
func GetKubernetesClient(t *testing.T) (k8sClient client.Client, err error) {
45+
func getKubernetesClient(t *testing.T) (k8sClient client.Client, err error) {
4246
t.Helper()
4347
// Use controller-runtime to get cluster connection
4448
k8sConfig, err := controllerruntime.GetConfig()

0 commit comments

Comments
 (0)