Skip to content

Commit

Permalink
tests(plugins) use local upstream mock instead of httpbin/mockbin
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito authored and thibaultcha committed Aug 22, 2017
1 parent 218a69c commit 466b44c
Show file tree
Hide file tree
Showing 51 changed files with 2,232 additions and 2,075 deletions.
2 changes: 1 addition & 1 deletion spec/02-integration/01-helpers/00-helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe("helpers: assertions and modifiers", function()
path = "/request",
body = { hello = "world" },
headers = {
host = "mock_upstream",
host = "mock_upstream",
["Content-Type"] = "application/json",
},
})
Expand Down
4 changes: 2 additions & 2 deletions spec/02-integration/05-proxy/01-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ describe("Router", function()

local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equal("bar", json.args.foo)
assert.equal("world", json.args.hello)
assert.equal("bar", json.uri_args.foo)
assert.equal("world", json.uri_args.hello)
end)

it("does proxy an empty querystring if URI does not contain arguments", function()
Expand Down
2 changes: 1 addition & 1 deletion spec/02-integration/05-proxy/06-upstream_timeouts_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ dao_helpers.for_each_dao(function(kong_config)
})

-- do *not* use assert.res_status() here in case of
-- failure to avoid a 1MB long error log
-- failure to avoid a very large error log
assert.equal(504, res.status)
end)
end)
Expand Down
13 changes: 5 additions & 8 deletions spec/02-integration/05-proxy/07-uri_encoding_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe("URI encoding", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)

assert.equal("25", json.args.limit)
assert.equal([[{"or":[{"name":{"like":"%bac%"}}]}]], json.args.where)
assert.equal("25", json.uri_args.limit)
assert.equal([[{"or":[{"name":{"like":"%bac%"}}]}]], json.uri_args.where)
end)

it("issue #1480 does not percent-encode args unecessarily", function()
Expand All @@ -76,8 +76,7 @@ describe("URI encoding", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)

assert.equal(helpers.mock_upstream_protocol .. "://" ..
helpers.mock_upstream_host .. "/request?param=1.2.3", json.url)
assert.equal(helpers.mock_upstream_url .. "/request?param=1.2.3", json.url)
end)

it("issue #749 does not decode percent-encoded args", function()
Expand All @@ -94,8 +93,7 @@ describe("URI encoding", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)

assert.equal(helpers.mock_upstream_protocol .. "://" ..
helpers.mock_upstream_host .. "/request?param=abc%7Cdef", json.url)
assert.equal(helpers.mock_upstream_url .. "/request?param=abc%7Cdef", json.url)
end)

it("issue #688 does not percent-decode proxied URLs", function()
Expand All @@ -112,8 +110,7 @@ describe("URI encoding", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)

assert.equal(helpers.mock_upstream_protocol .. "://" ..
helpers.mock_upstream_host .. "/request/foo%2Fbar", json.url)
assert.equal(helpers.mock_upstream_url .. "/request/foo%2Fbar", json.url)
end)

it("issue #2512 does not double percent-encode upstream URLs", function()
Expand Down
45 changes: 15 additions & 30 deletions spec/03-plugins/01-tcp-log/01-tcp-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local cjson = require "cjson"
local helpers = require "spec.helpers"

local TCP_PORT = 35001
local HTTP_DELAY_PORT = 35003

describe("Plugin: tcp-log (log)", function()
local client
Expand All @@ -11,34 +10,23 @@ describe("Plugin: tcp-log (log)", function()
helpers.run_migrations()

local api1 = assert(helpers.dao.apis:insert {
name = "api-1",
hosts = { "tcp_logging.com" },
upstream_url = "http://mockbin.com",
})
local api2 = assert(helpers.dao.apis:insert {
name = "api-2",
hosts = { "tcp_logging2.com" },
upstream_url = "http://127.0.0.1:" .. HTTP_DELAY_PORT,
name = "api-1",
hosts = { "tcp_logging.com" },
upstream_url = helpers.mock_upstream_url,
})

assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "tcp-log",
config = {
host = "127.0.0.1",
port = TCP_PORT
},
})
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "tcp-log",
name = "tcp-log",
config = {
host = "127.0.0.1",
port = TCP_PORT
port = TCP_PORT,
},
})

assert(helpers.start_kong())
assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
client = helpers.proxy_client()
end)
teardown(function()
Expand All @@ -51,10 +39,10 @@ describe("Plugin: tcp-log (log)", function()

-- Making the request
local r = assert(client:send {
method = "GET",
path = "/request",
method = "GET",
path = "/request",
headers = {
host = "tcp_logging.com"
host = "tcp_logging.com",
},
})
assert.response(r).has.status(200)
Expand All @@ -70,16 +58,15 @@ describe("Plugin: tcp-log (log)", function()
end)

it("logs proper latencies", function()
local http_thread = helpers.http_server(HTTP_DELAY_PORT) -- Starting the mock TCP server
local tcp_thread = helpers.tcp_server(TCP_PORT) -- Starting the mock TCP server

-- Making the request
local r = assert(client:send {
method = "GET",
path = "/request/delay",
method = "GET",
path = "/delay/2",
headers = {
host = "tcp_logging2.com"
}
host = "tcp_logging.com",
},
})

assert.response(r).has.status(200)
Expand All @@ -93,7 +80,5 @@ describe("Plugin: tcp-log (log)", function()

assert.True(log_message.latencies.proxy < 3000)
assert.True(log_message.latencies.request >= log_message.latencies.kong + log_message.latencies.proxy)

http_thread:join()
end)
end)
52 changes: 18 additions & 34 deletions spec/03-plugins/02-udp-log/01-udp-log_spec.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
local cjson = require "cjson"
local helpers = require "spec.helpers"

local TCP_PORT = 35002
local UDP_PORT = 35001
local HTTP_DELAY_PORT = 35004

describe("Plugin: udp-log (log)", function()
local client

setup(function()
helpers.run_migrations()

local api2 = assert(helpers.dao.apis:insert {
name = "tests-udp-logging2",
hosts = { "udp_logging2.com" },
upstream_url = "http://127.0.0.1:" .. HTTP_DELAY_PORT,
})
local api3 = assert(helpers.dao.apis:insert {
name = "tests-udp-logging",
hosts = { "udp_logging.com" },
upstream_url = "http://mockbin.com",
local api1 = assert(helpers.dao.apis:insert {
name = "tests-udp-logging",
hosts = { "udp_logging.com" },
upstream_url = helpers.mock_upstream_url,
})

assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "udp-log",
config = {
host = "127.0.0.1",
port = TCP_PORT
},
})
assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "udp-log",
api_id = api1.id,
name = "udp-log",
config = {
host = "127.0.0.1",
port = UDP_PORT
},
})

assert(helpers.start_kong())
assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
client = helpers.proxy_client()
end)

Expand All @@ -49,16 +36,15 @@ describe("Plugin: udp-log (log)", function()
end)

it("logs proper latencies", function()
local http_thread = helpers.http_server(HTTP_DELAY_PORT)
local udp_thread = helpers.udp_server(TCP_PORT)
local udp_thread = helpers.udp_server(UDP_PORT)

-- Making the request
local r = assert(client:send {
method = "GET",
path = "/request/delay",
method = "GET",
path = "/delay/2",
headers = {
host = "udp_logging2.com"
}
host = "udp_logging.com",
},
})

assert.response(r).has.status(200)
Expand All @@ -72,20 +58,18 @@ describe("Plugin: udp-log (log)", function()

assert.True(log_message.latencies.proxy < 3000)
assert.True(log_message.latencies.request >= log_message.latencies.kong + log_message.latencies.proxy)

http_thread:join()
end)

it("logs to UDP", function()
local thread = helpers.udp_server(UDP_PORT) -- Starting the mock UDP server

-- Making the request
local res = assert(client:send {
method = "GET",
path = "/request",
method = "GET",
path = "/request",
headers = {
host = "udp_logging.com"
}
host = "udp_logging.com",
},
})
assert.response(res).has.status(200)

Expand Down
18 changes: 10 additions & 8 deletions spec/03-plugins/04-file-log/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ describe("Plugin: file-log (log)", function()
helpers.run_migrations()

local api1 = assert(helpers.dao.apis:insert {
name = "api-1",
hosts = { "file_logging.com" },
upstream_url = "http://mockbin.com"
name = "api-1",
hosts = { "file_logging.com" },
upstream_url = helpers.mock_upstream_url,
})

assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "file-log",
name = "file-log",
config = {
path = FILE_LOG_PATH,
path = FILE_LOG_PATH,
reopen = true,
}
},
})

assert(helpers.start_kong())
assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
end)
teardown(function()
helpers.stop_kong()
Expand Down Expand Up @@ -65,7 +67,7 @@ describe("Plugin: file-log (log)", function()
assert.same("127.0.0.1", log_message.client_ip)
assert.same(uuid, log_message.request.headers["file-log-uuid"])
end)

it("reopens file on each request", function()
local uuid1 = utils.uuid()

Expand Down
52 changes: 27 additions & 25 deletions spec/03-plugins/05-syslog/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,59 @@ describe("#ci Plugin: syslog (log)", function()
helpers.run_migrations()

local api1 = assert(helpers.dao.apis:insert {
name = "api-1",
hosts = { "logging.com" },
upstream_url = "http://mockbin.com"
name = "api-1",
hosts = { "logging.com" },
upstream_url = helpers.mock_upstream_url,
})
local api2 = assert(helpers.dao.apis:insert {
name = "api-2",
hosts = { "logging2.com" },
upstream_url = "http://mockbin.com"
name = "api-2",
hosts = { "logging2.com" },
upstream_url = helpers.mock_upstream_url,
})
local api3 = assert(helpers.dao.apis:insert {
name = "api-3",
hosts = { "logging3.com" },
upstream_url = "http://mockbin.com"
name = "api-3",
hosts = { "logging3.com" },
upstream_url = helpers.mock_upstream_url,
})

assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "syslog",
name = "syslog",
config = {
log_level = "info",
successful_severity = "warning",
log_level = "info",
successful_severity = "warning",
client_errors_severity = "warning",
server_errors_severity = "warning"
}
server_errors_severity = "warning",
},
})
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "syslog",
name = "syslog",
config = {
log_level = "err",
successful_severity = "warning",
log_level = "err",
successful_severity = "warning",
client_errors_severity = "warning",
server_errors_severity = "warning"
}
server_errors_severity = "warning",
},
})
assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "syslog",
name = "syslog",
config = {
log_level = "warning",
successful_severity = "warning",
log_level = "warning",
successful_severity = "warning",
client_errors_severity = "warning",
server_errors_severity = "warning"
}
server_errors_severity = "warning",
},
})

local ok, _, stdout = helpers.execute("uname")
assert(ok, "failed to retrieve platform name")
platform = pl_stringx.strip(stdout)

assert(helpers.start_kong())
assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
end)
teardown(function()
helpers.stop_kong()
Expand Down
Loading

0 comments on commit 466b44c

Please sign in to comment.