Skip to content

Commit 41fc619

Browse files
committed
update test case
1 parent c35be6d commit 41fc619

File tree

4 files changed

+95
-29
lines changed

4 files changed

+95
-29
lines changed

build_test_resources/cfuntest.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ int is_service_on = 0;
1111
void ngx_http_c_func_init(ngx_http_c_func_ctx_t* ctx) {
1212
ngx_http_c_func_log(info, ctx, "%s", "Starting The Application");
1313

14+
char* my_cache_value = ngx_http_c_func_cache_new(ctx->shared_mem, "key", sizeof("This is cache value") + 1);
1415

16+
if (my_cache_value) {
17+
memset(my_cache_value, 0, sizeof("This is cache value") + 1 );
18+
strcpy(my_cache_value, "This is cache value");
19+
}
20+
1521
is_service_on = 1;
22+
1623
}
1724

1825

@@ -122,7 +129,21 @@ void my_app_simple_post(ngx_http_c_func_ctx_t *ctx) {
122129
}
123130
}
124131

132+
void my_app_simple_get_cache(ngx_http_c_func_ctx_t *ctx) {
133+
ngx_http_c_func_log_info(ctx, "logged from my_app_simple_get_cache");
125134

135+
char* my_cache_value = ngx_http_c_func_cache_get(ctx->shared_mem, "key");
136+
137+
if (my_cache_value) {
138+
ngx_http_c_func_write_resp(
139+
ctx,
140+
200,
141+
"200 OK",
142+
"text/plain",
143+
(char*)my_cache_value
144+
);
145+
}
146+
}
126147

127148
void my_app_simple_get_no_resp(ngx_http_c_func_ctx_t *ctx) {
128149
ngx_http_c_func_log_info(ctx, "Calling back and log from my_app_simple_get_no_resp");
@@ -132,6 +153,9 @@ void my_app_simple_get_no_resp(ngx_http_c_func_ctx_t *ctx) {
132153

133154

134155
void ngx_http_c_func_exit(ngx_http_c_func_ctx_t* ctx) {
156+
157+
ngx_http_c_func_cache_remove(ctx->shared_mem, "key");
158+
135159
ngx_http_c_func_log(info, ctx, "%s\n", "Shutting down The Application");
136160

137161
is_service_on = 0;

build_test_resources/sanity_test_raw_parse.t

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,18 @@ greeting=enjoy-http-c-function-testing
114114
Content-Type: text/plain
115115
--- response_body_like eval
116116
qr/greeting=enjoy-http-c-function-testing$/
117+
118+
119+
=== TEST 8: Set C_FUNC_TEST_CACHE
120+
--- config
121+
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
122+
location = /testCFunGetCache {
123+
ngx_http_c_func_call "my_app_simple_get_cache";
124+
}
125+
--- request
126+
POST /testCFunGetCache
127+
--- error_code: 200
128+
--- response_headers
129+
Content-Type: text/plain
130+
--- response_body_like eval
131+
qr/This is cache value$/

t/libcfuntest.so

240 Bytes
Binary file not shown.

t/sanity.t

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test Suite to parse the relevant variable the sanity.t once built
22

3-
use lib 'inc';
4-
use lib 'lib';
3+
use lib '/home/dispatch/testMap/c-lib/test-nginx/inc';
4+
use lib '/home/dispatch/testMap/c-lib/test-nginx/lib';
55
use Test::Nginx::Socket 'no_plan';
66

77
no_long_string();
@@ -14,7 +14,7 @@ __DATA__
1414

1515
=== TEST 1: Set C_FUNC_TEST_1
1616
--- config
17-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
17+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
1818
location = /testCFunGreeting {
1919
ngx_http_c_func_call "my_app_simple_get_greeting";
2020
}
@@ -28,7 +28,7 @@ qr/greeting from ngx_http_c_func testing$/
2828

2929
=== TEST 2: Set C_FUNC_TEST_ARGS
3030
--- config
31-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
31+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
3232
location = /testCFunARGS {
3333
ngx_http_c_func_call "my_app_simple_get_args";
3434
}
@@ -41,12 +41,9 @@ Content-Type: text/plain
4141
qr/greeting=hello_nginx\?id=129310923$/
4242

4343

44-
45-
46-
4744
=== TEST 3: Set C_FUNC_TEST_POST_NONE
4845
--- config
49-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
46+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
5047
location = /testCFunPOSTBody {
5148
ngx_http_c_func_call "my_app_simple_post";
5249
}
@@ -60,25 +57,9 @@ Content-Type: text/plain
6057
qr/\s/
6158

6259

63-
=== TEST 4: Set C_FUNC_TEST_POST_BODY
60+
=== TEST 4: Set C_FUNC_TEST_GET_TOKEN
6461
--- config
65-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
66-
location = /testCFunPOSTBody {
67-
ngx_http_c_func_call "my_app_simple_post";
68-
}
69-
--- request
70-
POST /testCFunPOSTBody
71-
greeting=enjoy-http-c-function-testing
72-
--- error_code: 202
73-
--- response_headers
74-
Content-Type: text/plain
75-
--- response_body_like eval
76-
qr/greeting=enjoy-http-c-function-testing$/
77-
78-
79-
=== TEST 5: Set C_FUNC_TEST_GET_TOKEN
80-
--- config
81-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
62+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
8263
location = /testCFunCVerifyToken {
8364
ngx_http_c_func_call "my_app_simple_get_token_args";
8465
}
@@ -91,14 +72,60 @@ Content-Type: text/plain
9172
qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==$/
9273

9374

94-
=== TEST 6: Set C_FUNC_TEST_GET_ERROR_RESP
75+
=== TEST 5: Set C_FUNC_TEST_GET_ERROR_RESP
9576
--- config
96-
ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
77+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
9778
location = /testCFUNCERRORRESP {
9879
ngx_http_c_func_call "my_app_simple_get_no_resp";
9980
}
10081
--- request
10182
GET /testCFUNCERRORRESP?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==
10283
--- error_code: 500
10384
--- response_headers
104-
Content-Type: text/html
85+
Content-Type: text/html
86+
87+
88+
=== TEST 6: Set C_FUNC_TEST_GET_CALLOC_FROM_POOL
89+
--- config
90+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
91+
location = /testCFUNCCallocFromPool {
92+
ngx_http_c_func_call "my_app_simple_get_calloc_from_pool";
93+
}
94+
--- request
95+
GET /testCFUNCCallocFromPool
96+
--- error_code: 200
97+
--- response_headers
98+
Content-Type: text/plain
99+
--- response_body_like eval
100+
qr/This is the message calloc from pool$/
101+
102+
103+
=== TEST 7: Set C_FUNC_TEST_POST_BODY
104+
--- config
105+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
106+
location = /testCFunPOSTBody {
107+
ngx_http_c_func_call "my_app_simple_post";
108+
}
109+
--- request
110+
POST /testCFunPOSTBody
111+
greeting=enjoy-http-c-function-testing
112+
--- error_code: 202
113+
--- response_headers
114+
Content-Type: text/plain
115+
--- response_body_like eval
116+
qr/greeting=enjoy-http-c-function-testing$/
117+
118+
119+
=== TEST 8: Set C_FUNC_TEST_CACHE
120+
--- config
121+
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
122+
location = /testCFunGetCache {
123+
ngx_http_c_func_call "my_app_simple_get_cache";
124+
}
125+
--- request
126+
POST /testCFunGetCache
127+
--- error_code: 200
128+
--- response_headers
129+
Content-Type: text/plain
130+
--- response_body_like eval
131+
qr/This is cache value$/

0 commit comments

Comments
 (0)