summaryrefslogtreecommitdiff
path: root/ngx_stream_lua-0.0.16/t/033-ctx.t
blob: ec21aae7f42c2e8e6774b6b6c7f0e0811540ee3b (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua::Stream;

#worker_connections(1014);
#master_on();
#workers(2);
#log_level('warn');

repeat_each(2);

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

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

__DATA__

=== TEST 1: sanity
--- stream_server_config
    content_by_lua_block {
        ngx.ctx.foo = 32;
        ngx.say(ngx.ctx.foo)
    }
--- stream_response
32
--- no_error_log
[error]



=== TEST 2: rewrite, access, and content
TODO
--- stream_server_config
    rewrite_by_lua_block {
        print("foo = ", ngx.ctx.foo)
        ngx.ctx.foo = 76
    }
    access_by_lua_block {
        ngx.ctx.foo = ngx.ctx.foo + 3
    }
    content_by_lua_block {
        ngx.say(ngx.ctx.foo)
    }
--- stream_response
79
--- no_error_log
[error]
--- grep_error_log eval: qr/foo = [^,]+/
--- log_level: info
--- grep_error_log_out
foo = nil
--- SKIP



=== TEST 3: different requests have different ngx.ctx
--- stream_server_config
    content_by_lua_block {
        ngx.say(ngx.ctx.foo)
        ngx.ctx.foo = 32
        ngx.say(ngx.ctx.foo)
    }
--- stream_server_config2
    content_by_lua_block {
        ngx.say(ngx.ctx.foo)
    }
--- stream_response
nil
32
nil
--- no_error_log
[error]



=== TEST 4: overriding ctx
--- stream_server_config
    content_by_lua_block {
        ngx.ctx = { foo = 32, bar = 54 };
        ngx.say(ngx.ctx.foo)
        ngx.say(ngx.ctx.bar)

        ngx.ctx = { baz = 56  };
        ngx.say(ngx.ctx.foo)
        ngx.say(ngx.ctx.baz)
    }
--- stream_response
32
54
nil
56
--- no_error_log
[error]



=== TEST 5: ngx.ctx + ngx.exit(ngx.ERROR) + log_by_lua
TODO
--- stream_server_config
    rewrite_by_lua_block {
        ngx.ctx.foo = 32;
        ngx.exit(ngx.ERROR)
    }
    log_by_lua_block { ngx.log(ngx.WARN, "ngx.ctx = ", ngx.ctx.foo) }
--- stream_response
--- no_error_log
[error]
--- error_log
ngx.ctx = 32
--- SKIP



=== TEST 6: ngx.ctx + ngx.exit(200) + log_by_lua
TODO
--- stream_server_config
    rewrite_by_lua_block {
        ngx.ctx.foo = 32;
        ngx.say(ngx.ctx.foo)
        ngx.exit(200)
    }
    log_by_lua 'ngx.log(ngx.WARN, "ctx.foo = ", ngx.ctx.foo)';
--- stream_response
32
--- no_error_log
[error]
--- error_log
ctx.foo = 32
--- SKIP