|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use t::RX 'no_plan'; |
| 4 | + |
| 5 | +repeat_each(1); |
| 6 | +run_tests(); |
| 7 | + |
| 8 | +__DATA__ |
| 9 | + |
| 10 | +=== TEST 1: uri args |
| 11 | +--- config |
| 12 | + location /t { |
| 13 | + content_by_lua_block { |
| 14 | + local radix = require("resty.radixtree") |
| 15 | + local rx = radix.new({ |
| 16 | + { |
| 17 | + path = "/aa", |
| 18 | + metadata = "metadata /aa", |
| 19 | + vars = {"arg_k", "v"}, |
| 20 | + } |
| 21 | + }) |
| 22 | +
|
| 23 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 24 | + } |
| 25 | + } |
| 26 | +--- request |
| 27 | +GET /t?k=v |
| 28 | +--- no_error_log |
| 29 | +[error] |
| 30 | +--- response_body |
| 31 | +metadata /aa |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +=== TEST 2: uri args(not hit) |
| 36 | +--- config |
| 37 | + location /t { |
| 38 | + content_by_lua_block { |
| 39 | + local radix = require("resty.radixtree") |
| 40 | + local rx = radix.new({ |
| 41 | + { |
| 42 | + path = "/aa", |
| 43 | + metadata = "metadata /aa", |
| 44 | + vars = {"arg_k", "v"}, |
| 45 | + } |
| 46 | + }) |
| 47 | +
|
| 48 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 49 | + } |
| 50 | + } |
| 51 | +--- request |
| 52 | +GET /t?k=not_hit |
| 53 | +--- no_error_log |
| 54 | +[error] |
| 55 | +--- response_body |
| 56 | +nil |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +=== TEST 3: http header |
| 61 | +--- config |
| 62 | + location /t { |
| 63 | + content_by_lua_block { |
| 64 | + local radix = require("resty.radixtree") |
| 65 | + local rx = radix.new({ |
| 66 | + { |
| 67 | + path = "/aa", |
| 68 | + metadata = "metadata /aa", |
| 69 | + vars = {"http_test", "v"}, |
| 70 | + } |
| 71 | + }) |
| 72 | +
|
| 73 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 74 | + } |
| 75 | + } |
| 76 | +--- more_headers |
| 77 | +test: v |
| 78 | +--- request |
| 79 | +GET /t |
| 80 | +--- no_error_log |
| 81 | +[error] |
| 82 | +--- response_body |
| 83 | +metadata /aa |
| 84 | +
|
| 85 | +
|
| 86 | +
|
| 87 | +=== TEST 4: http header(not hit) |
| 88 | +--- config |
| 89 | + location /t { |
| 90 | + content_by_lua_block { |
| 91 | + local radix = require("resty.radixtree") |
| 92 | + local rx = radix.new({ |
| 93 | + { |
| 94 | + path = "/aa", |
| 95 | + metadata = "metadata /aa", |
| 96 | + vars = {"http_test", "v"}, |
| 97 | + } |
| 98 | + }) |
| 99 | +
|
| 100 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 101 | + } |
| 102 | + } |
| 103 | +--- more_headers |
| 104 | +test: not-hit |
| 105 | +--- request |
| 106 | +GET /t |
| 107 | +--- no_error_log |
| 108 | +[error] |
| 109 | +--- response_body |
| 110 | +nil |
| 111 | +
|
| 112 | +
|
| 113 | +
|
| 114 | +=== TEST 5: uri args + header + server_port |
| 115 | +--- config |
| 116 | + location /t { |
| 117 | + content_by_lua_block { |
| 118 | + local radix = require("resty.radixtree") |
| 119 | + local rx = radix.new({ |
| 120 | + { |
| 121 | + path = "/aa", |
| 122 | + metadata = "metadata /aa", |
| 123 | + vars = {"arg_k", "v", |
| 124 | + "host", "localhost", |
| 125 | + "server_port", "1984"}, |
| 126 | + } |
| 127 | + }) |
| 128 | +
|
| 129 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 130 | + } |
| 131 | + } |
| 132 | +--- request |
| 133 | +GET /t?k=v |
| 134 | +--- no_error_log |
| 135 | +[error] |
| 136 | +--- response_body |
| 137 | +metadata /aa |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +=== TEST 6: uri args + header + server_port (not hit) |
| 142 | +--- config |
| 143 | + location /t { |
| 144 | + content_by_lua_block { |
| 145 | + local radix = require("resty.radixtree") |
| 146 | + local rx = radix.new({ |
| 147 | + { |
| 148 | + path = "/aa", |
| 149 | + metadata = "metadata /aa", |
| 150 | + vars = {"arg_k", "v", |
| 151 | + "host", "localhost", |
| 152 | + "server_port", "1984-not"}, |
| 153 | + } |
| 154 | + }) |
| 155 | +
|
| 156 | + ngx.say(rx:match("/aa", {vars = ngx.var})) |
| 157 | + } |
| 158 | + } |
| 159 | +--- request |
| 160 | +GET /t?k=v |
| 161 | +--- no_error_log |
| 162 | +[error] |
| 163 | +--- response_body |
| 164 | +nil |
0 commit comments