Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions t/lib/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1327,4 +1327,15 @@ function _M.plugin_proxy_rewrite_multi_header()
end


-- mock of Lago's batch events endpoint (POST /api/v1/events/batch); logs the
-- Authorization header and request body so lago.t can assert on what the plugin
-- actually sent, then answers 200 with an empty batch like Lago does
function _M.api_v1_events_batch()
ngx.req.read_body()
ngx.log(ngx.WARN, "lago auth: ", ngx.req.get_headers()["Authorization"] or "")
ngx.log(ngx.WARN, "lago body: ", ngx.req.get_body_data() or "")
ngx.say('{"events": []}')
end


return _M
69 changes: 56 additions & 13 deletions t/plugin/lago.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX;

# This test cannot be executed normally at the moment, so it will be temporarily skipped and fixed in a later PR.
plan(skip_all => 'skip test case');
use t::APISIX 'no_plan';

repeat_each(1);
no_long_string();
Expand Down Expand Up @@ -69,12 +66,58 @@ property "event_properties" validation failed: wrong type: expected object, got



=== TEST 2: test
--- timeout: 302
--- max_size: 2048000
--- exec
cd t && pnpm test plugin/lago.spec.mts 2>&1
--- no_error_log
failed to execute the script with status
--- response_body eval
qr/PASS plugin\/lago.spec.mts/
=== TEST 2: set up a route whose lago plugin sends events to the mock endpoint
--- 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": {
"lago": {
"endpoint_addrs": ["http://127.0.0.1:1980"],
"token": "test-token",
"event_transaction_id": "txn-${request_id}",
"event_subscription_id": "sub-1",
"event_code": "test",
"event_properties": {
"tier": "normal",
"status": "${status}"
},
"batch_max_size": 1
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 3: hitting the route batches one event and sends it to the mock
--- request
GET /hello
--- wait: 2
--- response_body
hello world
--- error_log
lago auth: Bearer test-token
"code":"test"
"external_subscription_id":"sub-1"
"transaction_id":"txn-
"tier":"normal"
"status":"200"
Loading