@@ -215,6 +215,39 @@ func TestParseRateLimitAnnotations(t *testing.T) {
215215}, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) == 0 {
216216t .Error ("No Errors when parsing invalid log level" )
217217}
218+
219+ if errors := parseRateLimitAnnotations (map [string ]string {
220+ "nginx.org/limit-req-rate" : "1r/s" ,
221+ }, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) != 2 {
222+ t .Errorf ("Expected 2 errors for missing mandatory annotations, got %d" , len (errors ))
223+ }
224+
225+ if errors := parseRateLimitAnnotations (map [string ]string {
226+ "nginx.org/limit-req-rate" : "1r/s" ,
227+ "nginx.org/limit-req-key" : "${binary_remote_addr}" ,
228+ }, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) != 1 {
229+ t .Errorf ("Expected 1 error for missing mandatory annotation, got %d" , len (errors ))
230+ }
231+
232+ if errors := parseRateLimitAnnotations (map [string ]string {
233+ "nginx.org/limit-req-burst" : "10" ,
234+ }, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) != 3 {
235+ t .Errorf ("Expected 3 errors for missing all mandatory annotations, got %d" , len (errors ))
236+ }
237+
238+ if errors := parseRateLimitAnnotations (map [string ]string {
239+ "nginx.org/proxy-connect-timeout" : "30s" ,
240+ }, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) != 0 {
241+ t .Errorf ("Expected 0 errors for non rate-limiting annotations, got %d" , len (errors ))
242+ }
243+
244+ if errors := parseRateLimitAnnotations (map [string ]string {
245+ "nginx.org/limit-req-rate" : "1r/s" ,
246+ "nginx.org/limit-req-key" : "${binary_remote_addr}" ,
247+ "nginx.org/limit-req-zone-size" : "10m" ,
248+ }, NewDefaultConfigParams (context .Background (), false ), ctx ); len (errors ) != 0 {
249+ t .Errorf ("Expected 0 errors for complete mandatory annotations, got %d" , len (errors ))
250+ }
218251}
219252
220253func BenchmarkParseRewrites (b * testing.B ) {
0 commit comments