Skip to content

Commit

Permalink
fix(plugins/bk-traffic-label.lua): if the weight = 0, should not chan…
Browse files Browse the repository at this point in the history
…ge to 1
  • Loading branch information
wklken committed Nov 7, 2024
1 parent b2a71e0 commit 6954909
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/apisix/plugins/bk-traffic-label.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function _M.check_schema(conf)
-- Calculate total weight of all actions and preprocess actions to set default weight
local total_weight = 0
for _, action in ipairs(rule.actions) do
if action.weight == nil or action.weight <= 0 then
if action.weight == nil or action.weight < 0 then
action.weight = 1
end
total_weight = total_weight + action.weight
Expand Down
12 changes: 6 additions & 6 deletions src/apisix/t/bk-traffic-label.t
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ GET /t
--- response_body
passed

=== TEST 6: match hit set_headers
=== TEST 8: match hit set_headers
--- request
GET /hello?env=prod
--- response_body
Expand All @@ -240,7 +240,7 @@ host: localhost
x-real-ip: 127.0.0.1
x-test-header: test2

=== TEST 7: only the action with non-zero weight is applied, but do nothing
=== TEST 9: only the action with non-zero weight is applied, but do nothing
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -287,15 +287,15 @@ GET /t
--- response_body
passed

=== TEST 8: match hit set_headers
=== TEST 10: match hit set_headers
--- request
GET /hello?env=prod
--- response_body
uri: /uri/plugin_proxy_rewrite
host: localhost
x-real-ip: 127.0.0.1

=== TEST 9: multiple matches, all hit
=== TEST 11: multiple matches, all hit
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -349,7 +349,7 @@ GET /t
--- response_body
passed

=== TEST 10: multiple matches, only hit one
=== TEST 12: multiple matches, only hit one
--- request
GET /hello?env=dev&type=foo
--- response_body
Expand All @@ -358,7 +358,7 @@ host: localhost
x-real-ip: 127.0.0.1
x-test-header-2: test2

=== TEST 10: multiple matches, hit both
=== TEST 13: multiple matches, hit both
--- request
GET /hello?env=prod&type=foo
--- response_body
Expand Down

0 comments on commit 6954909

Please sign in to comment.