summaryrefslogtreecommitdiff
path: root/ngx_stream_lua-0.0.16/t/141-add-variable.t
blob: 4798d215f4b3948ac452b1ebb002f7a4ad407d02 (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
# 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() * 4 + 1);

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

__DATA__

=== TEST 1: sanity
--- stream_config
    lua_add_variable $foo;
--- stream_server_config
    content_by_lua_block {
        ngx.say(ngx.var.foo)
        ngx.var.foo = "bar"
        ngx.say(ngx.var.foo)
    }
--- stream_response
nil
bar
--- no_error_log
[warn]
[error]



=== TEST 2: works with C code
--- stream_config
    lua_add_variable $foo;
--- stream_server_config
    preread_by_lua_block {
        ngx.var.foo = "bar"
    }

    return $foo\n;
--- stream_response
bar
--- no_error_log
[warn]
[error]



=== TEST 3: multiple add with same name works
--- stream_config
    lua_add_variable $foo;
    lua_add_variable $foo;
--- stream_server_config
    preread_by_lua_block {
        ngx.var.foo = "bar"
    }

    return $foo\n;
--- stream_response
bar
--- no_error_log
[warn]
[error]



=== TEST 4: accessible in log phase
--- stream_config
    lua_add_variable $foo;

    log_format test "access log: $foo";
    access_log logs/error.log test;
--- stream_server_config
    preread_by_lua_block {
        ngx.var.foo = "bar"
    }

    return $foo\n;
--- stream_response
bar
--- no_error_log
[warn]
[error]
--- error_log
access log: bar