我本来的目的是使用现成的conf文件,如果像你举的例子那样做,就违背了初衷了。不过可以写perl去批量读每个文件替换路径,但这就麻烦了
你用变量的思路提醒了我,可以用nginx本身的变量,set $test_path "../../.."; 然后用这个$test_path,或者使用环境变量,用set_by_lua 设个变量来用
但这种方法有一个缺陷,set和set_by_lua只能在server和location里使用,没法在http里使用,因此http下的init_by_lua_file的路径问题无法解决
On Wednesday, August 10, 2016 at 3:31:55 PM UTC+8, Zexuan Luo wrote:
一个思路是在拼配置字符串时使用perl变量。
举个例子:
my $pwd = cwd();
lua_package_path "$pwd/src/?.lua;;"; |
content_by_lua_file $pwd/src/increment_rank_api.lua; |
--- http_config eval: $::HttpConfig |
--- config eval: $::Config
这里 $pwd 是一个在测试运行时赋值的变量。
在 2016年8月9日星期二 UTC+8下午5:49:43,Celebi写道:
这个思路不错。
但如果我的app-core.conf里面如果有 include 或者 content_by_lua_file 使用了相对路径,就会导致错误
有什么办法可以避免Test::Nginx一套相对路径,
线上环境一套相对路径吗?只能用绝对路径了?
On Saturday, August 6, 2016 at 5:25:42 AM UTC+8, agentzh wrote:Hello!
2016-08-05 0:54 GMT-07:00 Celebi:
> 谢谢,我不写perl的,所以之前没想过看cpan上的这个文档,确实是不错的文档。
>
> 但我看过文档之后,如果我要用这种方法实现我的目的,我需要手动(或者写个工具)将现有的nginx.conf拆开,然后写到不同的section中去。还是有点麻烦。
或许你可以用 nginx 的 include 指令来加载核心的 nginx 配置?比如
=== TEST 1: App
--- config
include ../../../conf/app-core.conf;
--- request
GET /t
--- response_body
hello world
--- no_error_log
[error]
假设你的项目目录结构是这样的:
t/
└── a.t
conf/
└── app-core.conf
nginx.conf 的 boilter-plate 由 Test::Nginx 来自动生成是必要的,否则我们无法实现这里列举的
Test::Nginx 的各种高级测试模式:
https://openresty.gitbooks.io/programming-openresty/content/testing/test-modes.html
Regards,
-agentzh