Skip to content

Commit

Permalink
test: change sanity to TDT
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Dec 10, 2021
1 parent bfc84a5 commit c8d99a9
Showing 1 changed file with 16 additions and 38 deletions.
54 changes: 16 additions & 38 deletions t/plugin/opa.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,35 @@ run_tests();

__DATA__
=== TEST 1: sanity check with minimal valid configuration
=== TEST 1: sanity
--- config
location /t {
content_by_lua_block {
local testcase = {
{host = "http://127.0.0.1:8181", policy = "example/allow"},
{host = "http://127.0.0.1:8181"},
{host = 3233, policy = "example/allow"}
}
local plugin = require("apisix.plugins.opa")
local ok, err = plugin.check_schema({host = "http://127.0.0.1:8181", policy = "example/allow"})
if not ok then
ngx.say(err)
end
ngx.say("done")
}
}
--- response_body
done
for _, v in ipairs(a) do
local ok, err = plugin.check_schema(v)
if not ok then
ngx.say(err)
end
=== TEST 2: missing `policy`
--- config
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.opa")
local ok, err = plugin.check_schema({host = "http://127.0.0.1:8181"})
if not ok then
ngx.say(err)
ngx.say("done")
end
}
}
--- response_body
done
property "policy" is required
=== TEST 3: wrong type for `host`
--- config
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.opa")
local ok, err = plugin.check_schema({host = 3233, policy = "example/allow"})
if not ok then
ngx.say(err)
end
}
}
--- response_body
property "host" validation failed: wrong type: expected string, got number
=== TEST 4: setup route with plugin
=== TEST 2: setup route with plugin
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -121,7 +99,7 @@ passed
=== TEST 5: hit route (with wrong header request)
=== TEST 3: hit route (with wrong header request)
--- request
GET /hello
--- more_headers
Expand All @@ -130,7 +108,7 @@ test-header: not-for-test
=== TEST 6: hit route (with correct request)
=== TEST 4: hit route (with correct request)
--- request
GET /hello
--- more_headers
Expand Down

0 comments on commit c8d99a9

Please sign in to comment.