|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use Test::Nginx::Socket::Lua 'no_plan'; |
| 4 | + |
| 5 | +repeat_each(2); |
| 6 | +no_diff(); |
| 7 | +no_long_string(); |
| 8 | +log_level('info'); |
| 9 | + |
| 10 | +our $HttpConfig = <<"_EOC_"; |
| 11 | + resolver ipv6=off local=on; |
| 12 | +
|
| 13 | + lua_package_path "lib/?.lua;;"; |
| 14 | + init_by_lua_block { |
| 15 | + require "resty.core" |
| 16 | + package.loaded.mock = {} |
| 17 | + ngx.var = package.loaded.mock |
| 18 | + local var = require("resty.ngxvar") |
| 19 | + var.enable_patch(false) |
| 20 | + } |
| 21 | +_EOC_ |
| 22 | + |
| 23 | +add_block_preprocessor(sub { |
| 24 | + my ($block) = @_; |
| 25 | + |
| 26 | + if (!$block->http_config) { |
| 27 | + $block->set_value("http_config", $HttpConfig); |
| 28 | + } |
| 29 | + |
| 30 | + if (!$block->request) { |
| 31 | + $block->set_value("request", "GET /t"); |
| 32 | + } |
| 33 | + |
| 34 | + if (!$block->error_log && !$block->no_error_log) { |
| 35 | + $block->set_value("no_error_log", "[error]\n[alert]"); |
| 36 | + } |
| 37 | +}); |
| 38 | + |
| 39 | +run_tests(); |
| 40 | + |
| 41 | +__DATA__ |
| 42 | +
|
| 43 | +=== TEST 1: upstream_response_time |
| 44 | +--- config |
| 45 | + location /t { |
| 46 | + content_by_lua_block { |
| 47 | + package.loaded.mock.upstream_response_time = "102.023" |
| 48 | + local var = require("resty.ngxvar") |
| 49 | + ngx.say(var.fetch("upstream_response_time")) |
| 50 | + ngx.say(type(var.fetch("upstream_response_time"))) |
| 51 | +
|
| 52 | + package.loaded.mock.upstream_response_time = "102.023, 0.000" |
| 53 | + ngx.say(var.fetch("upstream_response_time")) |
| 54 | +
|
| 55 | + package.loaded.mock.upstream_response_time = "102.023 : 1.200" |
| 56 | + ngx.say(var.fetch("upstream_response_time")) |
| 57 | + } |
| 58 | + } |
| 59 | +--- response_body |
| 60 | +102.023 |
| 61 | +number |
| 62 | +102.023 |
| 63 | +103.223 |
| 64 | +
|
| 65 | +
|
| 66 | +
|
| 67 | +=== TEST 2: upstream_connect_time |
| 68 | +--- config |
| 69 | + location /t { |
| 70 | + content_by_lua_block { |
| 71 | + package.loaded.mock.upstream_connect_time = "102.023" |
| 72 | + local var = require("resty.ngxvar") |
| 73 | + ngx.say(var.fetch("upstream_connect_time")) |
| 74 | + ngx.say(type(var.fetch("upstream_connect_time"))) |
| 75 | +
|
| 76 | + package.loaded.mock.upstream_connect_time = "102.023, 0.000" |
| 77 | + ngx.say(var.fetch("upstream_connect_time")) |
| 78 | +
|
| 79 | + package.loaded.mock.upstream_connect_time = "102.023 : 1.200" |
| 80 | + ngx.say(var.fetch("upstream_connect_time")) |
| 81 | + } |
| 82 | + } |
| 83 | +--- response_body |
| 84 | +102.023 |
| 85 | +number |
| 86 | +102.023 |
| 87 | +103.223 |
| 88 | +
|
| 89 | +
|
| 90 | +
|
| 91 | +=== TEST 3: upstream_header_time |
| 92 | +--- config |
| 93 | + location /t { |
| 94 | + content_by_lua_block { |
| 95 | + package.loaded.mock.upstream_header_time = "102.023" |
| 96 | + local var = require("resty.ngxvar") |
| 97 | + ngx.say(var.fetch("upstream_header_time")) |
| 98 | + ngx.say(type(var.fetch("upstream_header_time"))) |
| 99 | +
|
| 100 | + package.loaded.mock.upstream_header_time = "102.023, 0.000" |
| 101 | + ngx.say(var.fetch("upstream_header_time")) |
| 102 | +
|
| 103 | + package.loaded.mock.upstream_header_time = "102.023 : 1.200" |
| 104 | + ngx.say(var.fetch("upstream_header_time")) |
| 105 | + } |
| 106 | + } |
| 107 | +--- response_body |
| 108 | +102.023 |
| 109 | +number |
| 110 | +102.023 |
| 111 | +103.223 |
0 commit comments