File: utils.t

package info (click to toggle)
lua-resty-core 0.1.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,176 kB
  • sloc: perl: 143; sh: 59; makefile: 26
file content (115 lines) | stat: -rw-r--r-- 2,573 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# vim:set ft= ts=4 sw=4 et fdm=marker:
use lib '.';
use t::TestCore;

plan tests => repeat_each() * blocks() * 3;

add_block_preprocessor(sub {
    my $block = shift;

    if (!defined $block->error_log) {
        $block->set_value("no_error_log", "[error]");
    }

    if (!defined $block->request) {
        $block->set_value("request", "GET /t");
    }
});

no_diff();
no_long_string();
run_tests();

__DATA__

=== TEST 1: utils.str_replace_char() sanity (replaces a single character)
--- config
    location /t {
        content_by_lua_block {
            local utils = require "resty.core.utils"

            local strings = {
                "Header_Name",
                "_Header_Name_",
                "Header__Name",
                "Header-Name",
                "Hello world",
            }

            for i = 1, #strings do
                ngx.say(utils.str_replace_char(strings[i], "_", "-"))
            end
        }
    }
--- response_body
Header-Name
-Header-Name-
Header--Name
Header-Name
Hello world



=== TEST 2: utils.str_replace_char() JIT compiles when match
--- config
    location /t {
        content_by_lua_block {
            local utils = require "resty.core.utils"

            for i = 1, $TEST_NGINX_HOTLOOP * 10 do
                utils.str_replace_char("Header_Name", "_", "-")
            end
        }
    }
--- ignore_response_body
--- error_log eval
qr/\[TRACE\s+\d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/,
--- no_error_log
[error]



=== TEST 3: utils.str_replace_char() JIT compiles when no match
--- config
    location /t {
        content_by_lua_block {
            local utils = require "resty.core.utils"

            for i = 1, $TEST_NGINX_HOTLOOP * 10 do
                utils.str_replace_char("Header_Name", "-", "_")
            end
        }
    }
--- ignore_response_body
--- error_log eval
qr/\[TRACE\s+\d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/,
--- no_error_log
[error]



=== TEST 4: utils.str_replace_char() replacing more than one character is not supported
--- config
    location /t {
        content_by_lua_block {
            local utils = require "resty.core.utils"

            local strings = {
                "Header01Name",
                "01Header01Name01",
                "Header0Name",
                "Header1Name",
                "Hello world",
            }

            for i = 1, #strings do
                ngx.say(utils.str_replace_char(strings[i], "02", "02"))
            end
        }
    }
--- response_body
Header01Name
01Header01Name01
Header0Name
Header1Name
Hello world