-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy path11-db_transformations_spec.lua
71 lines (53 loc) · 2.09 KB
/
11-db_transformations_spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local helpers = require "spec.helpers"
local fmt = string.format
for _, strategy in helpers.each_strategy() do
describe("kong.db [#" .. strategy .. "]", function()
local _, db
lazy_setup(function()
_, db = helpers.get_db_utils(strategy, {
"transformations",
}, {
"transformations"
})
local env = {}
env.database = strategy
env.plugins = env.plugins or "transformations"
local lua_path = [[ KONG_LUA_PATH_OVERRIDE="./spec/fixtures/migrations/?.lua;]] ..
[[./spec/fixtures/migrations/?/init.lua;]] ..
[[./spec/fixtures/custom_plugins/?.lua;]] ..
[[./spec/fixtures/custom_plugins/?/init.lua;" ]]
local cmdline = "migrations up -c " .. helpers.test_conf_path
local _, code, _, stderr = helpers.kong_exec(cmdline, env, true, lua_path)
assert.same(0, code)
assert.equal("", stderr)
end)
describe("Transformations", function()
describe(":update()", function()
local errmsg = fmt("[%s] schema violation (all or none of these fields must be set: 'hash_secret', 'secret')",
strategy)
it("updating secret requires hash_secret", function()
local dao = assert(db.transformations:insert({
name = "test"
}))
local newdao, err = db.transformations:update({ id = dao.id }, {
secret = "dog",
})
assert.equal(nil, newdao)
assert.equal(errmsg, err)
assert(db.transformations:delete({ id = dao.id }))
end)
it("updating hash_secret requires secret", function()
local dao = assert(db.transformations:insert({
name = "test"
}))
local newdao, err = db.transformations:update({ id = dao.id }, {
hash_secret = true,
})
assert.equal(nil, newdao)
assert.equal(errmsg, err)
assert(db.transformations:delete({ id = dao.id }))
end)
end)
end)
end) -- kong.db [strategy]
end