add_block_preprocessor()
为每个测试块注册一个预处理回调函数。
用法
add_block_preprocessor 允许你在每个测试块执行前修改其内容。回调函数接收测试块对象作为参数:
perl
1use Test::Nginx::Socket::Lua;23add_block_preprocessor(sub {4 my $block = shift;56 # 如果没有指定 request,默认添加 GET /t7 if (!defined $block->request) {8 $block->set_value("request", "GET /t");9 }1011 # 默认检查无错误日志12 if (!defined $block->no_error_log) {13 $block->set_value("no_error_log", "[error]");14 }15});1617run_tests();add_block_preprocessor 是减少测试代码重复的利器。你可以设置公共默认值,让每个测试块只需要声明其特有的部分。