提交 46af79b9 编写于 作者: S Shengliang Guan

test: add unitest for sdb

上级 04c4135a
...@@ -23,6 +23,12 @@ class MndTestSdb : public ::testing::Test { ...@@ -23,6 +23,12 @@ class MndTestSdb : public ::testing::Test {
void TearDown() override {} void TearDown() override {}
}; };
typedef struct SMnode {
int32_t v100;
int32_t v200;
SSdb *pSdb;
} SMnode;
typedef struct SStrObj { typedef struct SStrObj {
char key[24]; char key[24];
int8_t v8; int8_t v8;
...@@ -95,8 +101,39 @@ SSdbRaw *strDecode(SStrObj *pObj) { ...@@ -95,8 +101,39 @@ SSdbRaw *strDecode(SStrObj *pObj) {
return pRaw; return pRaw;
} }
int32_t strInsert(SSdb *pSdb, SStrObj *pObj) { return 0; }
int32_t strDelete(SSdb *pSdb, SStrObj *pObj, bool callFunc) { return 0; }
int32_t strUpdate(SSdb *pSdb, SStrObj *pOld, SStrObj *pNew) {
pOld->v8 = pNew->v8;
pOld->v16 = pNew->v16;
pOld->v32 = pNew->v32;
pOld->v64 = pNew->v64;
return 0;
}
int32_t strDefault(SMnode *pMnode) {
SStrObj strObj = {0};
strcpy(strObj.key, "k1000");
strObj.v8 = 1;
strObj.v16 = 1;
strObj.v32 = 1000;
strObj.v64 = 1000;
strcpy(strObj.vstr, "v1000");
SSdbRaw *pRaw = strEncode(&strObj);
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
return sdbWrite(pMnode->pSdb, pRaw);
}
TEST_F(MndTestSdb, 01_Basic) { TEST_F(MndTestSdb, 01_Basic) {
SMnode mnode;
mnode.v100 = 100;
mnode.v200 = 200;
SSdbOpt opt = {0}; SSdbOpt opt = {0};
opt.pMnode = &mnode;
opt.path = "/tmp/mnode_test_sdb"; opt.path = "/tmp/mnode_test_sdb";
SSdb *pSdb = sdbInit(&opt); SSdb *pSdb = sdbInit(&opt);
...@@ -106,11 +143,11 @@ TEST_F(MndTestSdb, 01_Basic) { ...@@ -106,11 +143,11 @@ TEST_F(MndTestSdb, 01_Basic) {
.sdbType = SDB_USER, .sdbType = SDB_USER,
.keyType = SDB_KEY_BINARY, .keyType = SDB_KEY_BINARY,
.deployFp = (SdbDeployFp)strEncode, .deployFp = (SdbDeployFp)strEncode,
.encodeFp = (SdbEncodeFp)strDecode, .encodeFp = (SdbEncodeFp)strEncode,
.decodeFp = (SdbDecodeFp)NULL, .decodeFp = (SdbDecodeFp)strDecode,
.insertFp = (SdbInsertFp)NULL, .insertFp = (SdbInsertFp)strInsert,
.updateFp = (SdbUpdateFp)NULL, .updateFp = (SdbUpdateFp)strDelete,
.deleteFp = (SdbDeleteFp)NULL, .deleteFp = (SdbDeleteFp)strUpdate,
}; };
sdbSetTable(pSdb, strTable); sdbSetTable(pSdb, strTable);
......
...@@ -141,7 +141,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { ...@@ -141,7 +141,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
} }
static int32_t sdbCreateDir(SSdb *pSdb) { static int32_t sdbCreateDir(SSdb *pSdb) {
if (taosMkDir(pSdb->currDir) != 0) { if (taosMulMkDir(pSdb->currDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册