Skip to content

Commit

Permalink
fix(upstream) make Kong and DB schemas consistent
Browse files Browse the repository at this point in the history
Neither cassandra nor postgres' primary key values were a compound
of id and name, so the kong schema's needn't be, either.
  • Loading branch information
p0pr0ck5 committed Apr 25, 2017
1 parent 1ef44e8 commit 13167c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 50 deletions.
2 changes: 1 addition & 1 deletion kong/dao/schemas/upstreams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local SLOTS_MSG = "number of slots must be between "..SLOTS_MIN.." and "..SLOTS_

return {
table = "upstreams",
primary_key = {"id", "name"},
primary_key = {"id"},
fields = {
id = {
type = "id",
Expand Down
85 changes: 36 additions & 49 deletions spec/02-integration/03-admin_api/08-upstreams_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dao_helpers.for_each_dao(function(kong_config)

describe("Admin API", function()
local client
local config_db
local dao

setup(function()
Expand Down Expand Up @@ -481,61 +480,49 @@ if content_type == "application/x-www-form-urlencoded" then return end
end)

describe("DELETE", function()
do
-- DELETE is currently broken when using cassandra
-- because the schema defines the primary key as {id, name}
-- but both postgres and cassandra schemas actually define
-- their PK with id. this causes failures because cassandra
-- tries to delete against a non PK column. see #2358
local test = it
if kong_config.database == "cassandra" then
test = pending
end

test("by id", function(content_type)
local res = assert(client:send {
method = "POST",
path = "/upstreams",
body = {
name = "my-upstream",
slots = 100,
},
headers = { ["Content-Type"] = "application/json" }
})
it("by id", function(content_type)
local res = assert(client:send {
method = "POST",
path = "/upstreams",
body = {
name = "my-upstream",
slots = 100,
},
headers = { ["Content-Type"] = "application/json" }
})

assert.response(res).has.status(201)
local json = assert.response(res).has.jsonbody()
assert.response(res).has.status(201)
local json = assert.response(res).has.jsonbody()

res = assert(client:send {
method = "DELETE",
path = "/upstreams/" .. json.id,
})
res = assert(client:send {
method = "DELETE",
path = "/upstreams/" .. json.id,
})

assert.response(res).has.status(204)
end)
assert.response(res).has.status(204)
end)

test("by name", function(content_type)
local res = assert(client:send {
method = "POST",
path = "/upstreams",
body = {
name = "my-upstream",
slots = 100,
},
headers = { ["Content-Type"] = "application/json" }
})
it("by name", function(content_type)
local res = assert(client:send {
method = "POST",
path = "/upstreams",
body = {
name = "my-upstream",
slots = 100,
},
headers = { ["Content-Type"] = "application/json" }
})

assert.response(res).has.status(201)
local json = assert.response(res).has.jsonbody()
assert.response(res).has.status(201)
local json = assert.response(res).has.jsonbody()

res = assert(client:send {
method = "DELETE",
path = "/upstreams/" .. json.name,
})
res = assert(client:send {
method = "DELETE",
path = "/upstreams/" .. json.name,
})

assert.response(res).has.status(204)
end)
end
assert.response(res).has.status(204)
end)
end)

it("returns 405 on invalid method", function()
Expand Down

0 comments on commit 13167c3

Please sign in to comment.