Skip to content

Commit b1da498

Browse files
committed
Move expected error strings to common.go
1 parent 82f84a1 commit b1da498

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

tests/cel/common.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ const (
3131
)
3232

3333
const (
34-
expectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
35-
expectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
36-
expectedHeaderWithoutServerError = `header can only be specified if server is specified`
34+
expectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
35+
expectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
36+
expectedHeaderWithoutServerError = `header can only be specified if server is specified`
37+
expectedOneOfDeploymentOrDaemonSetError = `only one of deployment or daemonSet can be set`
38+
expectedIfModeSetTrustedAddressesError = `if mode is set, trustedAddresses is a required field`
3739
)
3840

3941
const (

tests/cel/nginxproxy_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ func TestNginxProxyKubernetes(t *testing.T) {
2424
}{
2525
{
2626
name: "Validate NginxProxy with both Deployment and DaemonSet is invalid",
27-
wantErrors: []string{"only one of deployment or daemonSet can be set"},
27+
wantErrors: []string{expectedOneOfDeploymentOrDaemonSetError},
2828
policySpec: ngfAPIv1alpha2.NginxProxySpec{
2929
Kubernetes: &ngfAPIv1alpha2.KubernetesSpec{
30-
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
31-
Replicas: helpers.GetPointer[int32](3),
32-
},
33-
DaemonSet: &ngfAPIv1alpha2.DaemonSetSpec{},
30+
Deployment: &ngfAPIv1alpha2.DeploymentSpec{},
31+
DaemonSet: &ngfAPIv1alpha2.DaemonSetSpec{},
3432
},
3533
},
3634
},
3735
{
3836
name: "Validate NginxProxy with Deployment only is valid",
3937
policySpec: ngfAPIv1alpha2.NginxProxySpec{
4038
Kubernetes: &ngfAPIv1alpha2.KubernetesSpec{
41-
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
42-
Replicas: helpers.GetPointer[int32](3),
43-
},
39+
Deployment: &ngfAPIv1alpha2.DeploymentSpec{},
4440
},
4541
},
4642
},
@@ -86,7 +82,7 @@ func TestNginxProxyRewriteClientIP(t *testing.T) {
8682
}{
8783
{
8884
name: "Validate NginxProxy is invalid when trustedAddresses is not set and mode is set",
89-
wantErrors: []string{"if mode is set, trustedAddresses is a required field"},
85+
wantErrors: []string{expectedIfModeSetTrustedAddressesError},
9086
policySpec: ngfAPIv1alpha2.NginxProxySpec{
9187
RewriteClientIP: &ngfAPIv1alpha2.RewriteClientIP{
9288
Mode: helpers.GetPointer[ngfAPIv1alpha2.RewriteClientIPModeType]("XForwardedFor"),

0 commit comments

Comments
 (0)