Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dao) switch to lua-cassandra 0.4.0 #803

Merged
merged 8 commits into from
Dec 18, 2015
Prev Previous commit
Next Next commit
fix(dao) integration tests with new driver
  • Loading branch information
thibaultcha committed Dec 17, 2015
commit a0238fa144aabffc249d7201b0c72cb30cc16c83
3 changes: 3 additions & 0 deletions kong/dao/cassandra/factory.lua
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@
-- Also provides helper methods for preparing queries among the DAOs, migrating the
-- database and dropping it.

local log = require "cassandra.log"
log.set_lvl("ERR")

local constants = require "kong.constants"
local cassandra = require "cassandra"
local DaoError = require "kong.dao.error"
39 changes: 20 additions & 19 deletions spec/integration/dao/cassandra/base_dao_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
local log = require "cassandra.log"
log.set_lvl("ERR")

local spec_helper = require "spec.spec_helpers"
local cassandra = require "cassandra"
local spec_helper = require "spec.spec_helpers"
local constants = require "kong.constants"
local DaoError = require "kong.dao.error"
local utils = require "kong.tools.utils"
@@ -46,12 +43,11 @@ describe("Cassandra", function()

local cluster, err = cassandra.spawn_cluster {
shm = "factory_specs",
--keyspace = "kong_tests",
contact_points = configuration.dao_config.contact_points
}
assert.falsy(err)

session, err = cluster:spawn_session {keyspace = "kong_tests"}
session, err = cluster:spawn_session {keyspace = configuration.dao_config.keyspace}
assert.falsy(err)
end)

@@ -662,21 +658,26 @@ describe("Cassandra", function()
--

describe("plugins", function()
setup(function()
spec_helper.drop_db()
faker:insert_from_table {
api = {
{name = "tests-distinct-1", request_host = "foo.com", upstream_url = "http://mockbin.com"},
{name = "tests-distinct-2", request_host = "bar.com", upstream_url = "http://mockbin.com"}
},
plugin = {
{name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 1},
{name = "rate-limiting", config = { minute = 6}, __api = 1},
{name = "rate-limiting", config = { minute = 6}, __api = 2},
{name = "file-log", config = { path = "/tmp/spec.log" }, __api = 1}
}
}
end)
teardown(function()
spec_helper.drop_db()
end)
describe("find_distinct()", function()
it("should find distinct plugins configurations", function()
faker:insert_from_table {
api = {
{name = "tests-distinct-1", request_host = "foo.com", upstream_url = "http://mockbin.com"},
{name = "tests-distinct-2", request_host = "bar.com", upstream_url = "http://mockbin.com"}
},
plugin = {
{name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 1},
{name = "rate-limiting", config = { minute = 6}, __api = 1},
{name = "rate-limiting", config = { minute = 6}, __api = 2},
{name = "file-log", config = { path = "/tmp/spec.log" }, __api = 1}
}
}

local res, err = dao_factory.plugins:find_distinct()
assert.falsy(err)
assert.truthy(res)
22 changes: 13 additions & 9 deletions spec/integration/dao/cassandra/migrations_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local DAO = require "kong.dao.cassandra.factory"
local cassandra = require "cassandra"
local DAO = require "kong.dao.cassandra.factory"
local Migrations = require "kong.tools.migrations"
local spec_helper = require "spec.spec_helpers"

@@ -22,7 +22,18 @@ local test_cassandra_properties = test_configuration.dao_config
test_cassandra_properties.keyspace = FIXTURES.keyspace

local test_dao = DAO(test_cassandra_properties)
local session = cassandra:new()
local cluster, err = cassandra.spawn_cluster {
shm = "factory_specs",
contact_points = test_configuration.dao_config.contact_points
}
if err then
error(err)
end

local session, err = cluster:spawn_session {keyspace = test_configuration.dao_config.keyspace}
if err then
error(err)
end

local function has_table(state, arguments)
local rows, err = session:execute("SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = ?", {FIXTURES.keyspace})
@@ -109,13 +120,6 @@ assert:register("assertion", "has_migration", has_migration, "assertion.has_migr
describe("Migrations", function()
local migrations

setup(function()
local ok, err = session:connect(test_cassandra_properties.contact_points, test_cassandra_properties.port)
if not ok then
error(err)
end
end)

teardown(function()
session:execute("DROP KEYSPACE "..FIXTURES.keyspace)
end)
4 changes: 2 additions & 2 deletions spec/spec_helpers.lua
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
-- It supports other environments by passing a configuration file.

local IO = require "kong.tools.io"
local config = require "kong.tools.config_loader"
local dao = require "kong.tools.dao_loader"
local Faker = require "kong.tools.faker"
local Migrations = require "kong.tools.migrations"
local config = require "kong.tools.config_loader"
local Threads = require "llthreads2.ex"
local Migrations = require "kong.tools.migrations"

require "kong.tools.ngx_stub"