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
8 changes: 4 additions & 4 deletions lib/resty/mongol/bson.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ local function read_document ( get , numerical )
end

if numerical then
t [ tonumber ( e_name ) ] = v
t [ tonumber ( e_name ) + 1 ] = v
else
t [ e_name ] = v
end
Expand Down Expand Up @@ -140,7 +140,7 @@ local function pack ( k , v )
elseif mt == utc_date then
return "\9" .. k .. "\0" .. num_to_le_int(v.v, 8)
elseif mt == binary_mt then
return "\5" .. k .. "\0" .. num_to_le_uint(string.len(v.v)) ..
return "\5" .. k .. "\0" .. num_to_le_uint(string.len(v.v)) ..
v.st .. v.v
elseif ot == "table" then
local doc , array = to_bson(v)
Expand Down Expand Up @@ -186,10 +186,10 @@ function to_bson(ob)
elseif onlyarray then
local r = { }

local low = 0
local low = 1
--if seen_n [ 0 ] then low = 0 end
for i=low , high_n do
r [ i ] = pack ( i , seen_n [ i ] )
r [ i ] = pack ( i - 1 , seen_n [ i ] )
end

m = t_concat ( r , "" , low , high_n )
Expand Down
60 changes: 30 additions & 30 deletions t/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plan tests => repeat_each() * (3 * blocks());
my $pwd = cwd();

our $HttpConfig = qq{
lua_package_path "$pwd/lib/?/init.lua;;";
lua_package_path "$pwd/lib/?.lua;$pwd/lib/?/init.lua;;";
};

$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
Expand All @@ -23,14 +23,14 @@ run_tests();

__DATA__

=== TEST 1: col insert
=== TEST 1: col insert
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -49,7 +49,7 @@ __DATA__
r, err = col:delete({}, nil, true)
if not r then ngx.say("delete failed: "..err) end

r, err = col:insert({{name="dog",n=10,m=20}, {name="cat"}},
r, err = col:insert({{name="dog",n=10,m=20}, {name="cat"}},
nil, true)
if not r then ngx.say("insert failed: "..err) end
ngx.say(r)
Expand All @@ -75,7 +75,7 @@ dog
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)
ok, err = conn:connect("127.0.0.1", 27016)

if not ok then
Expand All @@ -97,7 +97,7 @@ connect failed: connection refused
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -133,7 +133,7 @@ GET /t
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -171,7 +171,7 @@ GET /t
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

local r, err = conn:connect("127.0.0.1")
if not r then ngx.say("connect failed: "..err) end
Expand Down Expand Up @@ -249,7 +249,7 @@ cat
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -292,7 +292,7 @@ GET /t
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -351,7 +351,7 @@ nil
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(1000)
conn:set_timeout(1000)

ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -398,7 +398,7 @@ ns not found
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)

local ok, err = conn:connect("127.0.0.1",27017)
if not ok then
Expand Down Expand Up @@ -426,13 +426,13 @@ ns not found
if not r then
ngx.say("not found")
end
ngx.say(r["n"])
ngx.say(r["n"])

r = col:find_one({name="puppy"}, {n=0})
if not r then
ngx.say("not found")
end
ngx.say(r["n"])
ngx.say(r["n"])

r = col:find_one({name="p"})
if not r then
Expand All @@ -449,14 +449,14 @@ not found
--- no_error_log
[error]

=== TEST 15: col delete safe
=== TEST 15: col delete safe
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)

local ok, err = conn:connect("127.0.0.1")
if not ok then
Expand Down Expand Up @@ -529,7 +529,7 @@ delete failed: need to login
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -553,7 +553,7 @@ delete failed: need to login
t2[2]="a20"
t2[3] = "a21"
t2[4] = "a22"

r, err = col:insert({{name="dog",n="10",tab=t,tab1=t1,tab2=t2}}, nil, true)
if not r then ngx.say("insert failed: "..err) end
ngx.say(r)
Expand Down Expand Up @@ -596,7 +596,7 @@ a20
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -613,7 +613,7 @@ a20
if not r then ngx.say("delete failed: "..err) end

local t = {0}

r, err = col:insert({{name="dog",n="10",tab=t}}, nil, true)
if not r then ngx.say("insert failed: "..err) end
ngx.say(r)
Expand Down Expand Up @@ -646,7 +646,7 @@ nil
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -670,7 +670,7 @@ nil
t2[2] = "a22"
t2[3] = "a23"
t2[4] = "a24"

r, err = col:insert({{name="dog",n="10",tab=t,tab1=t1,tab2=t2}}, nil, true)
if not r then ngx.say("insert failed: "..err) end
ngx.say(r)
Expand Down Expand Up @@ -715,7 +715,7 @@ a25
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -732,7 +732,7 @@ a25
if not r then ngx.say("delete failed: "..err) end

local t = {a=1,b=2}

r, err = col:insert({{name="dog",n="10",tab=t}}, nil, true)
if not r then ngx.say("insert failed: "..err) end
ngx.say(r)
Expand Down Expand Up @@ -764,7 +764,7 @@ GET /t
access_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -781,7 +781,7 @@ GET /t
if not r then ngx.say("delete failed: "..err) end

local t = {a=1,b=2}

r, err = col:insert({{name="dog",n="10"},tab=t}, nil, true)
if not r then ngx.say("insert failed: "..err) end

Expand All @@ -807,7 +807,7 @@ GET /t
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -824,7 +824,7 @@ GET /t
if not r then ngx.say("delete failed: "..err) end

local t = {a=1,b=2}

for i = 1, 10 do
col:insert({{name="puppy"}})
end
Expand Down Expand Up @@ -854,7 +854,7 @@ GET /t
content_by_lua '
local mongo = require "resty.mongol"
conn = mongo:new()
conn:set_timeout(10000)
conn:set_timeout(10000)
ok, err = conn:connect("127.0.0.1")

if not ok then
Expand All @@ -871,7 +871,7 @@ GET /t
if not r then ngx.say("delete failed: "..err) end

col:insert({ {photos={"1","2"} } })

r = col:find_one({})
for i , v in pairs(r["photos"]) do
ngx.say(i)
Expand Down