add mongo test case: auth

This commit is contained in:
LiuYang
2018-08-30 11:38:08 +08:00
committed by 云风
parent 7e63080c03
commit ce0cdc7bd3
4 changed files with 52 additions and 1 deletions

View File

@@ -3,6 +3,11 @@ local mongo = require "skynet.db.mongo"
local bson = require "bson"
local host, port, db_name, username, password = ...
if port then
port = math.tointeger(port)
end
-- print(host, port, db_name, username, password)
local function _create_client()
return mongo.client(
@@ -14,6 +19,25 @@ local function _create_client()
)
end
function test_auth()
local c = mongo.client(
{
host = host, port = port,
}
)
db = c[db_name]
db:auth(username, password)
db.testdb:dropIndex("*")
db.testdb:drop()
local ok, err, ret = db.testdb:safe_insert({test_key = 1});
assert(ok and ret and ret.n == 1, err)
local ok, err, ret = db.testdb:safe_insert({test_key = 1});
assert(ok and ret and ret.n == 1, err)
end
function test_insert_without_index()
local db = _create_client()
db[db_name].testdb:dropIndex("*")
@@ -105,6 +129,10 @@ function test_expire_index()
end
skynet.start(function()
if username then
print("Test auth")
test_auth()
end
print("Test insert without index")
test_insert_without_index()
print("Test insert index")