@@ -10,14 +10,17 @@ import (
10
10
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
11
11
12
12
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
13
+ "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers"
13
14
"github.com/nginx/nginx-gateway-fabric/v2/tests/framework"
14
15
)
15
16
16
17
func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
17
18
t .Parallel ()
18
19
g := NewWithT (t )
20
+
19
21
k8sClient , err := getKubernetesClient (t )
20
22
g .Expect (err ).ToNot (HaveOccurred ())
23
+
21
24
tests := []struct {
22
25
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
23
26
name string
@@ -83,8 +86,10 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
83
86
func TestClientSettingsPoliciesTargetRefGroup (t * testing.T ) {
84
87
t .Parallel ()
85
88
g := NewWithT (t )
89
+
86
90
k8sClient , err := getKubernetesClient (t )
87
91
g .Expect (err ).ToNot (HaveOccurred ())
92
+
88
93
tests := []struct {
89
94
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
90
95
name string
@@ -129,6 +134,68 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
129
134
}
130
135
}
131
136
137
+ func TestClientSettingsPoliciesKeepAliveTimeout (t * testing.T ) {
138
+ t .Parallel ()
139
+ g := NewWithT (t )
140
+
141
+ k8sClient , err := getKubernetesClient (t )
142
+ g .Expect (err ).ToNot (HaveOccurred ())
143
+
144
+ tests := []struct {
145
+ policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
146
+ name string
147
+ wantErrors []string
148
+ }{
149
+ {
150
+ name : "Validate KeepAliveTimeout is not set" ,
151
+ policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
152
+ TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
153
+ Kind : gatewayKind ,
154
+ Group : gatewayGroup ,
155
+ },
156
+ KeepAlive : nil ,
157
+ },
158
+ },
159
+ {
160
+ name : "Validate KeepAlive is set" ,
161
+ policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
162
+ TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
163
+ Kind : gatewayKind ,
164
+ Group : gatewayGroup ,
165
+ },
166
+ KeepAlive : & ngfAPIv1alpha1.ClientKeepAlive {
167
+ Timeout : & ngfAPIv1alpha1.ClientKeepAliveTimeout {
168
+ Server : helpers.GetPointer [ngfAPIv1alpha1.Duration ]("5s" ),
169
+ Header : helpers.GetPointer [ngfAPIv1alpha1.Duration ]("2s" ),
170
+ },
171
+ },
172
+ },
173
+ },
174
+ {
175
+ name : "Validate Header cannot be set without Server" ,
176
+ wantErrors : []string {expectedHeaderWithoutServerError },
177
+ policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
178
+ TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
179
+ Kind : gatewayKind ,
180
+ Group : gatewayGroup ,
181
+ },
182
+ KeepAlive : & ngfAPIv1alpha1.ClientKeepAlive {
183
+ Timeout : & ngfAPIv1alpha1.ClientKeepAliveTimeout {
184
+ Header : helpers.GetPointer [ngfAPIv1alpha1.Duration ]("2s" ),
185
+ },
186
+ },
187
+ },
188
+ },
189
+ }
190
+
191
+ for _ , tt := range tests {
192
+ t .Run (tt .name , func (t * testing.T ) {
193
+ t .Parallel ()
194
+ validateClientSettingsPolicy (t , tt , g , k8sClient )
195
+ })
196
+ }
197
+ }
198
+
132
199
func validateClientSettingsPolicy (t * testing.T , tt struct {
133
200
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
134
201
name string
0 commit comments