Skip to content

Commit

Permalink
fix(api) allow to delete APIs and Consumers by name
Browse files Browse the repository at this point in the history
Cassandra from 3 to 2 during an update and a delete, it removed the
possibility of updating and deleting APIs and Consumers by their name,
because that change made it so the base_dao's underlying `delete()` and
`update()` were directly used instead of first querying the entity.
Querying the entity first allowed to retrieve its PRIMARY KEY fields,
and hence `delete()` and `update()` never complained. But by removing
this initial retrieving, we removed this feature, and **there were not
tests** for it!

- This adds test for PATCH/DELETE APIs and Consumers by name/username
- Adds an argument to the base_dao `update()` and `delete()` to select
  by any field rather than only the PRIMARY KEY fields.
  • Loading branch information
thibaultcha authored and subnetmarco committed Jan 21, 2016
1 parent 32b9945 commit 5feacd1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kong/dao/cassandra/base_dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function BaseDao:update(t, full, where_t)
end

-- Extract primary key from the entity
local t_primary_key, t_no_primary_key = extract_primary_key(t, self._primary_key, self._clustering_key)
local t_primary_key, t_no_primary_key = extract_primary_key(old_entity, self._primary_key, self._clustering_key)

-- If full, add CQL `null` to the SET part of the query for nil columns
if full then
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/admin_api/apis_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,4 @@ describe("Admin API", function()
end)
end)
end)
end)
end)
54 changes: 48 additions & 6 deletions spec/integration/dao/cassandra/base_dao_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,6 @@ describe("Cassandra", function()
local ok, err = dao_factory.plugins:delete(rows[1])
assert.falsy(err)
assert.True(ok)

rows, err = session:execute("SELECT * FROM plugins WHERE id = ?", {cassandra.uuid(rows[1].id)})
assert.falsy(err)
assert.truthy(rows)
assert.equal(0, #rows)
end)
it("should delete an entity when it can be found without its primay key", function()
local ok, err = dao_factory.consumers:delete(nil, {
Expand Down Expand Up @@ -786,6 +781,53 @@ describe("Cassandra", function()
end)
end)

--
-- Nodes tests
--

describe("Nodes", function()

setup(function()
spec_helper.drop_db()
spec_helper.seed_db(100)
end)

describe(":insert()", function()
local node, err = dao_factory.nodes:insert({
cluster_listening_address = "wot.hello.com:1111",
name = "wot"
})
assert.falsy(err)
assert.truthy(node)
assert.equal("wot.hello.com:1111", node.cluster_listening_address)
end)

describe(":find_by_keys() and :delete()", function()
local nodes, err = dao_factory.nodes:find_by_keys({
cluster_listening_address = "wot.hello.com:1111"
})

assert.falsy(err)
assert.truthy(nodes)
assert.equal(1, #nodes)

local ok, err = dao_factory.nodes:delete({
name = table.remove(nodes, 1).name
})

assert.True(ok)
assert.falsy(err)
end)

describe(":find_all()", function()
local nodes, err = dao_factory.nodes:find_all()
assert.falsy(err)
assert.truthy(nodes)
assert.equal(100, #nodes)
end)

end)

--
-- Plugins configuration additional behaviour
--
Expand Down Expand Up @@ -899,4 +941,4 @@ describe("Cassandra", function()
end)
end) -- describe plugins configurations
end) -- describe Base DAO
end) -- describe Cassandra
end) -- describe Cassandra

0 comments on commit 5feacd1

Please sign in to comment.