Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 87 additions & 30 deletions spec/daemon_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for _,info in ipairs(addresses_to_test) do
return
end
family_done[info.family] = true

describe(
'A daemon with address '..info.addr..' and family '..info.family,
function()
Expand All @@ -41,15 +41,15 @@ for _,info in ipairs(addresses_to_test) do
interface = info.addr,
}
end)

it(
'provides the correct interface',
function()
assert.is_true(type(daemon) == 'table')
assert.is_true(type(daemon.start) == 'function')
assert.is_true(type(daemon.stop) == 'function')
end)

it(
'can be started',
function()
Expand All @@ -58,7 +58,7 @@ for _,info in ipairs(addresses_to_test) do
daemon:start()
end)
end)

it(
'can be stopped',
function()
Expand All @@ -67,35 +67,35 @@ for _,info in ipairs(addresses_to_test) do
daemon:stop()
end)
end)

describe(
'once started',
function()
setup(
function()
daemon:start()
end)

teardown(
function()
daemon:stop()
end)

local sock

before_each(function()
if info.family == 'inet6' then
sock = socket.tcp6()
else
sock = socket.tcp()
end
end)

after_each(function()
sock:shutdown()
sock:close()
end)

it(
'listens on specified port',
function(done)
Expand All @@ -110,12 +110,12 @@ for _,info in ipairs(addresses_to_test) do
end),sock:getfd(),ev.WRITE):start(loop)
sock:connect(info.addr,port)
end)

it(
'adding and removing states does not leak memory (may take a while...)',
function(done)
settimeout(100)

local add_msg = cjson.encode({
method = 'add',
params = {
Expand Down Expand Up @@ -161,7 +161,7 @@ for _,info in ipairs(addresses_to_test) do
end
end))
end)

it(
'sending an Invalid Request is reported correctly',
function(done)
Expand All @@ -182,7 +182,7 @@ for _,info in ipairs(addresses_to_test) do
end))
message_socket:send('123')
end)

it(
'sending an Invalid JSON is reported correctly',
function(done)
Expand All @@ -203,7 +203,7 @@ for _,info in ipairs(addresses_to_test) do
end))
message_socket:send('this is no json')
end)

local req_resp_test = function(desc)
local requests = desc.requests
local responses = desc.responses
Expand All @@ -212,7 +212,7 @@ for _,info in ipairs(addresses_to_test) do
function(done)
sock:connect(info.addr,port)
local message_socket = jetsocket.wrap(sock)

local count = 0
message_socket:on_message(
async(
Expand All @@ -229,7 +229,7 @@ for _,info in ipairs(addresses_to_test) do
end
end)
end

req_resp_test({
title = 'adding a state twice fails and "pathAlreadyExists" is reported',
requests = {
Expand Down Expand Up @@ -266,7 +266,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
}})

req_resp_test({
title = 'adding a state twice fails and "pathAlreadyExists" is reported / variant with less message ids',
requests = {
Expand Down Expand Up @@ -298,7 +298,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
}})

req_resp_test({
title = 'add / change / remove',
requests = {
Expand Down Expand Up @@ -341,7 +341,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'removing a not existing path gives error "pathNotExists"',
requests = {
Expand All @@ -366,7 +366,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'calling add without a path gives an error',
requests = {
Expand Down Expand Up @@ -394,7 +394,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'fetch with path matching works',
requests = {
Expand Down Expand Up @@ -442,7 +442,64 @@ for _,info in ipairs(addresses_to_test) do
}
}
})







req_resp_test({
title = 'fetch with path matching and numeric fetch id works',
requests = {
{
method = 'add',
params = {
path = 'a',
value = 123,
},
},
{
method = 'add',
params = {
path = 'b',
value = 456,
},
},
{
method = 'add',
params = {
path = 'c',
value = 789,
},
},
{
method = 'fetch',
params = {
path = {
unequalsAllOf = {'A','^C$'},
caseInsensitive = true,
contains = 'B'
},
id = 6
},
}
},
responses = {
{
method = 6,
params = {
event = 'add',
path = 'b',
value = 456
}
}
}
})





req_resp_test({
title = 'fetch with valueField array works',
requests = {
Expand Down Expand Up @@ -502,7 +559,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'fetch with sort by value works',
requests = {
Expand Down Expand Up @@ -563,7 +620,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'fetch with sort by valueField works',
requests = {
Expand Down Expand Up @@ -632,7 +689,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
})

req_resp_test({
title = 'calling an invalid service reports error',
requests = {
Expand All @@ -651,7 +708,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
}})

req_resp_test({
title = 'sending non jsonrpc JSON gives error with id',
requests = {
Expand All @@ -673,7 +730,7 @@ for _,info in ipairs(addresses_to_test) do
}
}
}})

req_resp_test({
title = 'sending non jsonrpc JSON gives error without id',
requests = {
Expand All @@ -692,8 +749,8 @@ for _,info in ipairs(addresses_to_test) do
}
}
}})

end)
end)

end
8 changes: 4 additions & 4 deletions spec/module_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ describe(
jet = require'jet'
end)
end)

it(
'jet.daemon is exposed',
function()
assert.is.equal(jet.daemon,require'jet.daemon')
assert.is.equal(type(jet.daemon.new),'function')
end)

it(
'jet.peer is exposed',
function()
assert.is.equal(jet.peer,require'jet.peer')
assert.is.equal(type(jet.peer.new),'function')
assert.is.same(jet.peer.new,require'jet.peer'.new)
end)

it(
'jet.new equals jet.peer.new',
function()
assert.is.same(jet.new,require'jet.peer'.new)
end)

end)
Loading