Skip to content

Commit

Permalink
tests(plugins) ordering of plugins test suites
Browse files Browse the repository at this point in the history
Plugins are roughly ordered from the simplest to the hardest in term of
testability. Also improve the testing instance start/stop reliability.
  • Loading branch information
thibaultcha committed Jul 29, 2016
1 parent b4b78db commit ec5efbb
Show file tree
Hide file tree
Showing 64 changed files with 234 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe("Plugin: tcp-log (log)", function()
local client

setup(function()
assert(helpers.start_kong())
client = helpers.proxy_client()

local api1 = assert(helpers.dao.apis:insert {
request_host = "tcp_logging.com",
upstream_url = "http://mockbin.com",
Expand All @@ -17,7 +20,6 @@ describe("Plugin: tcp-log (log)", function()
upstream_url = "http://127.0.0.1:"..HTTP_DELAY_PORT,
})

-- plugin 1
assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "tcp-log",
Expand All @@ -26,7 +28,6 @@ describe("Plugin: tcp-log (log)", function()
port = TCP_PORT
},
})
-- plugin 2
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "tcp-log",
Expand All @@ -35,16 +36,10 @@ describe("Plugin: tcp-log (log)", function()
port = TCP_PORT
},
})

helpers.prepare_prefix()
assert(helpers.start_kong())
client = helpers.proxy_client()
end)

teardown(function()
if client then client:close() end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

it("logs to TCP", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe("Plugin: udp-log (log)", function()
local client

setup(function()
assert(helpers.start_kong())
client = helpers.proxy_client()

local api2 = assert(helpers.dao.apis:insert {
name = "tests-udp-logging2",
request_host = "udp_logging2.com",
Expand All @@ -20,7 +23,6 @@ describe("Plugin: udp-log (log)", function()
upstream_url = "http://mockbin.com",
})

-- plugin 2
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "udp-log",
Expand All @@ -29,7 +31,6 @@ describe("Plugin: udp-log (log)", function()
port = TCP_PORT
},
})
-- plugin 3
assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "udp-log",
Expand All @@ -38,16 +39,11 @@ describe("Plugin: udp-log (log)", function()
port = UDP_PORT
},
})

helpers.prepare_prefix()
assert(helpers.start_kong())
client = helpers.proxy_client()
end)

teardown(function()
if client then client:close() end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

it("logs proper latencies", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ local mock_bin_https = create_mock_bin()
describe("Plugin: http-log (log)", function()
local client
setup(function()
assert(helpers.start_kong())

local api1 = assert(helpers.dao.apis:insert {
request_host = "http_logging.com",
upstream_url = "http://mockbin.com"
Expand All @@ -49,13 +51,9 @@ describe("Plugin: http-log (log)", function()
http_endpoint = "https://mockbin.org/bin/"..mock_bin_https
}
})

helpers.prepare_prefix()
assert(helpers.start_kong())
end)
teardown(function()
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

before_each(function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local FILE_LOG_PATH = os.tmpname()
describe("Plugin: file-log (log)", function()
local client
setup(function()
helpers.prepare_prefix()
assert(helpers.start_kong())

local api1 = assert(helpers.dao.apis:insert {
Expand All @@ -26,8 +25,7 @@ describe("Plugin: file-log (log)", function()
})
end)
teardown(function()
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

before_each(function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local pl_stringx = require "pl.stringx"
describe("Plugin: syslog (log)", function()
local client, platform
setup(function()
assert(helpers.start_kong())

local api1 = assert(helpers.dao.apis:insert {
request_host = "logging.com",
upstream_url = "http://mockbin.com"
Expand All @@ -29,7 +31,6 @@ describe("Plugin: syslog (log)", function()
server_errors_severity = "warning"
}
})

assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "syslog",
Expand All @@ -40,7 +41,6 @@ describe("Plugin: syslog (log)", function()
server_errors_severity = "warning"
}
})

assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "syslog",
Expand All @@ -55,12 +55,9 @@ describe("Plugin: syslog (log)", function()
local ok, _, stdout = helpers.execute("uname")
assert(ok, "failed to retrieve platform name")
platform = pl_stringx.strip(stdout)

helpers.prepare_prefix()
assert(helpers.start_kong())
end)
teardown(function()
assert(helpers.stop_kong())
helpers.stop_kong()
end)

before_each(function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ local UDP_PORT = 20000
describe("Plugin: statsd (log)", function()
local client
setup(function()
assert(helpers.start_kong())
client = helpers.proxy_client()

local api1 = assert(helpers.dao.apis:insert {
request_host = "logging1.com",
upstream_url = "http://mockbin.com"
Expand All @@ -29,7 +32,6 @@ describe("Plugin: statsd (log)", function()
upstream_url = "http://mockbin.com"
})

-- plugin 1
assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "statsd",
Expand All @@ -38,7 +40,6 @@ describe("Plugin: statsd (log)", function()
port = UDP_PORT
}
})
-- plugin 2
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "statsd",
Expand All @@ -48,7 +49,6 @@ describe("Plugin: statsd (log)", function()
metrics = {"latency"}
}
})
-- plugin 3
assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "statsd",
Expand All @@ -58,7 +58,6 @@ describe("Plugin: statsd (log)", function()
metrics = {"status_count"}
}
})
-- plugin 4
assert(helpers.dao.plugins:insert {
api_id = api4.id,
name = "statsd",
Expand All @@ -68,7 +67,6 @@ describe("Plugin: statsd (log)", function()
metrics = {"request_size"}
}
})
-- plugin 5
assert(helpers.dao.plugins:insert {
api_id = api5.id,
name = "statsd",
Expand All @@ -78,7 +76,6 @@ describe("Plugin: statsd (log)", function()
metrics = {"request_count"}
}
})
-- plugin 6
assert(helpers.dao.plugins:insert {
api_id = api6.id,
name = "statsd",
Expand All @@ -88,15 +85,11 @@ describe("Plugin: statsd (log)", function()
metrics = {"response_size"}
}
})

helpers.prepare_prefix()
assert(helpers.start_kong())
client = assert(helpers.http_client("127.0.0.1", helpers.test_conf.proxy_port))
end)

teardown(function()
if client then client:close() end
assert(helpers.stop_kong())
helpers.stop_kong()
end)

it("logs over UDP with default metrics", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local UDP_PORT = 20000
describe("Plugin: loggly (log)", function()
local client
setup(function()
assert(helpers.start_kong())

local api1 = assert(helpers.dao.apis:insert {
request_host = "logging.com",
upstream_url = "http://mockbin.com"
Expand All @@ -23,7 +25,6 @@ describe("Plugin: loggly (log)", function()
upstream_url = "http://mockbin.com"
})

-- plugin 1
assert(helpers.dao.plugins:insert {
api_id = api1.id,
name = "loggly",
Expand All @@ -35,7 +36,6 @@ describe("Plugin: loggly (log)", function()
successful_severity = "warning"
}
})
-- plugin 2
assert(helpers.dao.plugins:insert {
api_id = api2.id,
name = "loggly",
Expand All @@ -48,7 +48,6 @@ describe("Plugin: loggly (log)", function()
successful_severity = "info"
}
})
-- plugin 3
assert(helpers.dao.plugins:insert {
api_id = api3.id,
name = "loggly",
Expand All @@ -61,7 +60,6 @@ describe("Plugin: loggly (log)", function()
client_errors_severity = "warning"
}
})
-- plugin 4
assert(helpers.dao.plugins:insert {
api_id = api4.id,
name = "loggly",
Expand All @@ -71,12 +69,9 @@ describe("Plugin: loggly (log)", function()
key = "123456789"
}
})

helpers.prepare_prefix()
assert(helpers.start_kong())
end)
teardown(function()
assert(helpers.stop_kong())
helpers.stop_kong()
end)

before_each(function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ local threads = require "llthreads2.ex"
describe("Plugin: datadog (log)", function()
local client
setup(function()
assert(helpers.start_kong())
client = helpers.proxy_client()

local api1 = assert(helpers.dao.apis:insert {request_host = "datadog1.com", upstream_url = "http://mockbin.com"})
local api2 = assert(helpers.dao.apis:insert {request_host = "datadog2.com", upstream_url = "http://mockbin.com"})

Expand All @@ -24,16 +27,10 @@ describe("Plugin: datadog (log)", function()
metrics = "request_count,status_count"
}
})

helpers.prepare_prefix()
assert(helpers.start_kong())
client = helpers.proxy_client()
end)

teardown(function()
if client then client:close() end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

it("logs metrics over UDP", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ local helpers = require "spec.helpers"
describe("Plugin: basic-auth (API)", function()
local consumer, admin_client
setup(function()
helpers.prepare_prefix()
assert(helpers.start_kong())

admin_client = helpers.admin_client()
end)
teardown(function()
if admin_client then admin_client:close() end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

describe("/consumers/:consumer/basic-auth/", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ local meta = require "kong.meta"
describe("Plugin: basic-auth (access)", function()
local client
setup(function()
assert(helpers.start_kong())
client = helpers.proxy_client()

local api1 = assert(helpers.dao.apis:insert {
request_host = "basic-auth1.com",
upstream_url = "http://mockbin.com"
Expand Down Expand Up @@ -34,15 +37,10 @@ describe("Plugin: basic-auth (access)", function()
password = "kong",
consumer_id = consumer.id
})

helpers.prepare_prefix()
assert(helpers.start_kong())
client = helpers.proxy_client()
end)
teardown(function()
if client then client:close() end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

describe("Unauthorized", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ local cjson = require "cjson"
describe("Plugin: basic-auth (hooks)", function()
local admin_client, proxy_client
setup(function()
helpers.prepare_prefix()
assert(helpers.start_kong())

proxy_client = helpers.proxy_client()
admin_client = helpers.admin_client()
end)
Expand All @@ -16,8 +14,7 @@ describe("Plugin: basic-auth (hooks)", function()
admin_client:close()
proxy_client:close()
end
assert(helpers.stop_kong())
helpers.clean_prefix()
helpers.stop_kong()
end)

before_each(function()
Expand Down
Loading

0 comments on commit ec5efbb

Please sign in to comment.