From 4f315eff6c268ab506275ec5d13155d242afd8d1 Mon Sep 17 00:00:00 2001 From: sshniro Date: Sat, 18 Jan 2020 06:17:04 +0100 Subject: [PATCH 1/3] Added additional information and refactoring sentences. --- doc/plugin-develop.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/plugin-develop.md b/doc/plugin-develop.md index 72f78164dc94..62cc78f4566e 100644 --- a/doc/plugin-develop.md +++ b/doc/plugin-develop.md @@ -121,7 +121,7 @@ at its schema description : } ``` -at the same time, we need to implement the __check_schema(conf)__ method to complete the specification verification . +At the same time, we need to implement the __check_schema(conf)__ method to complete the specification verification . ```lua function _M.check_schema(conf) @@ -134,21 +134,29 @@ verification . ## choose phase to run -determine which phase to run , generally access or rewrite . if you don't know the Openresty life cycle , it's -recommended to know it in advance . key-auth is an authentication plugin , as long as the authentication is completed -before the business response after the request comes in . The plugin can be executed in the rewrite and access phases , -in the project, the authentication logic is implemented in the rewrite phase . Generally, IP access and interface +Determine which phase to run , generally access or rewrite . If you don't know the [Openresty life cycle](https://openresty-reference.readthedocs.io/en/latest/Directives/) , it's +recommended to know it in advance . For example key-auth is an authentication plugin , thus the authentication should be completed +before forwarding the request to any upstream service. Therefore, the plugin can be executed in the rewrite and access phases. +In APISIX, the authentication logic is implemented in the rewrite phase . Generally, IP access and interface permission are completed in the access phase . +The following code snippet can be used to implement any logic in the Openresty log phase. + +```lua +function _M.log(conf) +-- Implement logic here +end +``` + ## implement the logic Write the logic of the plugin in the corresponding phase . ## write test case -for functions , write and improve the test cases of various dimensions , do a comprehensive test for your plugin ! The -test cases of plugins are all in the "__t/plugin__" directory. You can go ahead to find out . the test framework -[****test-nginx****](https://github.com/openresty/test-nginx) adopted by the project. a test case, .t file is usually +For functions , write and improve the test cases of various dimensions , do a comprehensive test for your plugin ! The +test cases of plugins are all in the "__t/plugin__" directory. You can go ahead to find out. APISIX uses +[****test-nginx****](https://github.com/openresty/test-nginx) as the test framework. A test case, .t file is usually divided into prologue and data parts by \__data\__ . Here we will briefly introduce the data part, that is, the part of the real test case . For example, the key-auth plugin : @@ -174,14 +182,17 @@ done [error] ``` -a test case consists of three parts : +A test case consists of three parts : - __Program code__ : configuration content of Nginx location - __Input__ : http request information - __Output check__ : status, header, body, error log check -when we request __/t__ , which config in the configuration file , the Nginx will call "__content_by_lua_block__" instruction to +When we request __/t__ , which config in the configuration file , the Nginx will call "__content_by_lua_block__" instruction to complete the Lua script, and finally return. The assertion of the use case is response_body return "done", -"__no_error_log__" means to check the "__error.log__" of Nginx. There must be no ERROR level record . +"__no_error_log__" means to check the "__error.log__" of Nginx. There must be no ERROR level record. The log files for the unit test +are located in the following folder: 't/servroot/logs'. + +Refer the following [document](how-to-build.md#test) to setup the testing framework. ### Attach the test-nginx execution process: From e4d56b8ea8cdcee233e86ecaa48173e04a14da9e Mon Sep 17 00:00:00 2001 From: sshniro Date: Sat, 18 Jan 2020 06:21:06 +0100 Subject: [PATCH 2/3] Added additional information and refactoring sentences. --- doc/plugin-develop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/plugin-develop.md b/doc/plugin-develop.md index 62cc78f4566e..06e0f133cf70 100644 --- a/doc/plugin-develop.md +++ b/doc/plugin-develop.md @@ -140,7 +140,7 @@ before forwarding the request to any upstream service. Therefore, the plugin can In APISIX, the authentication logic is implemented in the rewrite phase . Generally, IP access and interface permission are completed in the access phase . -The following code snippet can be used to implement any logic in the Openresty log phase. +The following code snippet shows how to implement any logic relevant to the plugin in the Openresty log phase. ```lua function _M.log(conf) From 6b3feacd55f3489c027fc2f370f65969084d53a7 Mon Sep 17 00:00:00 2001 From: sshniro Date: Sat, 18 Jan 2020 06:42:41 +0100 Subject: [PATCH 3/3] removing white space --- doc/plugin-develop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/plugin-develop.md b/doc/plugin-develop.md index 06e0f133cf70..fc22f5014b1d 100644 --- a/doc/plugin-develop.md +++ b/doc/plugin-develop.md @@ -144,7 +144,7 @@ The following code snippet shows how to implement any logic relevant to the plug ```lua function _M.log(conf) --- Implement logic here +-- Implement logic here end ``` @@ -155,7 +155,7 @@ Write the logic of the plugin in the corresponding phase . ## write test case For functions , write and improve the test cases of various dimensions , do a comprehensive test for your plugin ! The -test cases of plugins are all in the "__t/plugin__" directory. You can go ahead to find out. APISIX uses +test cases of plugins are all in the "__t/plugin__" directory. You can go ahead to find out. APISIX uses [****test-nginx****](https://github.com/openresty/test-nginx) as the test framework. A test case, .t file is usually divided into prologue and data parts by \__data\__ . Here we will briefly introduce the data part, that is, the part of the real test case . For example, the key-auth plugin :