@@ -110,42 +110,48 @@ spec:
110110 }
111111
112112 Context ("Consumer plugins" , func () {
113- var keyAuthConsumer = `apiVersion: gateway.apisix.io/v1alpha1
113+ var limitCountConsumer = `
114+ apiVersion: gateway.apisix.io/v1alpha1
114115kind: Consumer
115116metadata:
116117 name: consumer-sample
117118spec:
118119 gatewayRef:
119120 name: api7ee
120- plugins:
121- - name: key-auth
121+ credentials:
122+ - type: key-auth
123+ name: key-auth-sample
122124 config:
123125 key: sample-key
126+ plugins:
127+ - name: limit-count
128+ config:
129+ count: 2
130+ time_window: 60
131+ rejected_code: 503
132+ key: remote_addr
124133`
125- var basicAuthConsumer = `apiVersion: gateway.apisix.io/v1alpha1
134+
135+ var unlimitConsumer = `
136+ apiVersion: gateway.apisix.io/v1alpha1
126137kind: Consumer
127138metadata:
128- name: consumer-sample
139+ name: consumer-sample2
129140spec:
130141 gatewayRef:
131142 name: api7ee
132- plugins:
133- - name: basic-auth
143+ credentials:
144+ - type: key-auth
145+ name: key-auth-sample
134146 config:
135- username: sample-user
136- password: sample-password
147+ key: sample-key2
137148`
138149
139150 BeforeEach (beforeEachHTTP )
140151
141- It ("key-auth" , func () {
142- s .ResourceApplied ("Consumer" , "consumer-sample" , keyAuthConsumer , 1 )
143-
144- s .NewAPISIXClient ().
145- GET ("/get" ).
146- WithHost ("httpbin.org" ).
147- Expect ().
148- Status (401 )
152+ It ("limit-count plugin" , func () {
153+ s .ResourceApplied ("Consumer" , "consumer-sample" , limitCountConsumer , 1 )
154+ s .ResourceApplied ("Consumer" , "consumer-sample2" , unlimitConsumer , 1 )
149155
150156 s .NewAPISIXClient ().
151157 GET ("/get" ).
@@ -154,46 +160,29 @@ spec:
154160 Expect ().
155161 Status (200 )
156162
157- By ("delete Consumer" )
158- err := s .DeleteResourceFromString (keyAuthConsumer )
159- Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
160- time .Sleep (5 * time .Second )
161-
162163 s .NewAPISIXClient ().
163164 GET ("/get" ).
164165 WithHeader ("apikey" , "sample-key" ).
165166 WithHost ("httpbin.org" ).
166167 Expect ().
167- Status (401 )
168- })
169-
170- It ("basic-auth" , func () {
171- s .ResourceApplied ("Consumer" , "consumer-sample" , basicAuthConsumer , 1 )
172-
173- s .NewAPISIXClient ().
174- GET ("/get" ).
175- WithHost ("httpbin.org" ).
176- Expect ().
177- Status (401 )
178-
179- s .NewAPISIXClient ().
180- GET ("/get" ).
181- WithBasicAuth ("sample-user" , "sample-password" ).
182- WithHost ("httpbin.org" ).
183- Expect ().
184168 Status (200 )
185169
186- By ("delete Consumer" )
187- err := s .DeleteResourceFromString (basicAuthConsumer )
188- Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
189- time .Sleep (5 * time .Second )
190-
170+ By ("trigger limit-count" )
191171 s .NewAPISIXClient ().
192172 GET ("/get" ).
193- WithBasicAuth ( "sample-user " , "sample-password " ).
173+ WithHeader ( "apikey " , "sample-key " ).
194174 WithHost ("httpbin.org" ).
195175 Expect ().
196- Status (401 )
176+ Status (503 )
177+
178+ for i := 0 ; i < 10 ; i ++ {
179+ s .NewAPISIXClient ().
180+ GET ("/get" ).
181+ WithHeader ("apikey" , "sample-key2" ).
182+ WithHost ("httpbin.org" ).
183+ Expect ().
184+ Status (200 )
185+ }
197186 })
198187 })
199188
0 commit comments