diff --git a/t/plugin/openwhisk.t b/t/plugin/openwhisk.t index c19a8cfebbe14..a4703d591acd0 100644 --- a/t/plugin/openwhisk.t +++ b/t/plugin/openwhisk.t @@ -146,7 +146,59 @@ only support json request body -=== TEST 7: hit route (with POST and correct request body) +=== TEST 8: hit route (with POST) +--- request +POST /hello +{} +--- more_headers +Content-Type: application/json +--- response_body chomp +{"hello":"test"} +--- no_error_log +[error] + + + +=== TEST 9: setup route with plugin +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "openwhisk": { + "api_host": "http://127.0.0.1:3233", + "service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP", + "namespace": "guest", + "action": "test-params" + } + }, + "upstream": { + "nodes": {}, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 10: hit route (with POST and request body) --- request POST /hello {"name": "world"} @@ -159,7 +211,7 @@ Content-Type: application/json -=== TEST 8: reset route to non-existent action +=== TEST 11: reset route to non-existent action --- config location /t { content_by_lua_block { @@ -198,7 +250,7 @@ passed -=== TEST 9: hit route (with non-existent action) +=== TEST 12: hit route (with non-existent action) --- request POST /hello {"name": "world"} @@ -210,7 +262,7 @@ Content-Type: application/json -=== TEST 10: reset route to wrong api_host +=== TEST 13: reset route to wrong api_host --- config location /t { content_by_lua_block { @@ -249,7 +301,7 @@ passed -=== TEST 11: hit route (with wrong api_host) +=== TEST 14: hit route (with wrong api_host) --- request POST /hello {"name": "world"} @@ -258,3 +310,150 @@ Content-Type: application/json --- error_code: 503 --- error_log failed to process openwhisk action, err: + + + +=== TEST 15: reset route to packaged action +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "openwhisk": { + "api_host": "http://127.0.0.1:3233", + "service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP", + "namespace": "guest", + "package": "pkg", + "action": "testpkg" + } + }, + "upstream": { + "nodes": {}, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 16: hit route (with packaged action) +--- request +GET /hello +--- response_body chomp +{"hello":"world"} +--- no_error_log +[error] + + + +=== TEST 17: reset route to status code action +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "openwhisk": { + "api_host": "http://127.0.0.1:3233", + "service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP", + "namespace": "guest", + "action": "test-statuscode" + } + }, + "upstream": { + "nodes": {}, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 18: hit route (with packaged action) +--- request +GET /hello +--- error_code: 407 +--- no_error_log +[error] + + + +=== TEST 19: reset route to headers action +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "openwhisk": { + "api_host": "http://127.0.0.1:3233", + "service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP", + "namespace": "guest", + "action": "test-headers" + } + }, + "upstream": { + "nodes": {}, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 20: hit route (with headers action) +--- request +GET /hello +--- response_headers +test: header +--- no_error_log +[error]