Skip to content

Commit

Permalink
feat: plugin limit-count move unit tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-flury committed Apr 18, 2023
1 parent 7159de9 commit c9157ff
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
64 changes: 62 additions & 2 deletions t/plugin/limit-count-redis.t
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ passed
=== TEST 16: request for TEST 17
=== TEST 16: request for TEST 15
--- request
GET /hello
--- error_code eval
Expand All @@ -452,7 +452,67 @@ failed to limit count: WRONGPASS invalid username-password pair or user is disab
=== TEST 17: restore redis password to ''
=== TEST 17: set route, with redis host, port and right username and password
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis_host": "127.0.0.1",
"redis_port": 6379,
"redis_timeout": 1001,
"redis_username": "alice",
"redis_password": "somepassword"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 18: up the limit
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503, 503]
=== TEST 19: up the limit
--- pipelined_requests eval
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
--- error_code eval
[404, 503, 404, 503, 503]
=== TEST 20: restore redis password to ''
--- config
location /t {
content_by_lua_block {
Expand Down
60 changes: 0 additions & 60 deletions t/plugin/limit-count-redis3.t
Original file line number Diff line number Diff line change
Expand Up @@ -186,63 +186,3 @@ passed
}
--- response_body
["1","0","0"]
=== TEST 5: set route, with redis host, port and right username and password
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis_host": "127.0.0.1",
"redis_port": 6379,
"redis_timeout": 1001,
"redis_username": "alice",
"redis_password": "somepassword"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 6: up the limit
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503, 503]
=== TEST 7: up the limit
--- pipelined_requests eval
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
--- error_code eval
[404, 503, 404, 503, 503]

0 comments on commit c9157ff

Please sign in to comment.