acct.cpp 2.8 KB
Newer Older
S
Shengliang Guan 已提交
1
/**
S
Shengliang Guan 已提交
2
 * @file acct.cpp
S
Shengliang Guan 已提交
3
 * @author slguan (slguan@taosdata.com)
S
Shengliang Guan 已提交
4
 * @brief DNODE module acct-msg tests
S
Shengliang Guan 已提交
5 6
 * @version 0.1
 * @date 2021-12-15
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2021
S
Shengliang Guan 已提交
9 10 11 12 13 14 15
 *
 */

#include "deploy.h"

class DndTestAcct : public ::testing::Test {
 protected:
S
Shengliang Guan 已提交
16 17 18 19 20
   static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
    SServer* pServer = createServer(path, fqdn, port, firstEp);
    ASSERT(pServer);
    return pServer;
  }
S
Shengliang Guan 已提交
21 22

  static void SetUpTestSuite() {
S
Shengliang Guan 已提交
23
    initLog("/tmp/tdlog");
S
Shengliang Guan 已提交
24

S
Shengliang Guan 已提交
25 26 27 28 29
    const char* fqdn = "localhost";
    const char* firstEp = "localhost:9012";
    pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9012, firstEp);
    pClient = createClient("root", "taosdata", fqdn, 9012);
    taosMsleep(300);
S
Shengliang Guan 已提交
30 31 32
  }

  static void TearDownTestSuite() {
S
Shengliang Guan 已提交
33
    stopServer(pServer);
S
Shengliang Guan 已提交
34
    dropClient(pClient);
S
Shengliang Guan 已提交
35 36
    pServer = NULL;
    pClient = NULL;
S
Shengliang Guan 已提交
37 38 39 40 41 42 43 44 45 46 47
  }

  static SServer* pServer;
  static SClient* pClient;
  static int32_t  connId;
};

SServer* DndTestAcct::pServer;
SClient* DndTestAcct::pClient;
int32_t  DndTestAcct::connId;

S
Shengliang Guan 已提交
48
TEST_F(DndTestAcct, 01_CreateAcct) {
S
Shengliang Guan 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  ASSERT_NE(pClient, nullptr);

  SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(sizeof(SCreateAcctMsg));

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SCreateAcctMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_ACCT;

  sendMsg(pClient, &rpcMsg);
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
  ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
}

S
Shengliang Guan 已提交
64
TEST_F(DndTestAcct, 02_AlterAcct) {
S
Shengliang Guan 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  ASSERT_NE(pClient, nullptr);

  SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(sizeof(SAlterAcctMsg));

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SAlterAcctMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_ACCT;

  sendMsg(pClient, &rpcMsg);
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
  ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
}

S
Shengliang Guan 已提交
80
TEST_F(DndTestAcct, 03_DropAcct) {
S
Shengliang Guan 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  ASSERT_NE(pClient, nullptr);

  SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(sizeof(SDropAcctMsg));

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SDropAcctMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_DROP_ACCT;

  sendMsg(pClient, &rpcMsg);
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
  ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
}

S
Shengliang Guan 已提交
96
TEST_F(DndTestAcct, 04_ShowAcct) {
S
Shengliang Guan 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  ASSERT_NE(pClient, nullptr);

  SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
  pReq->type = TSDB_MGMT_TABLE_ACCT;

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SShowMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;

  sendMsg(pClient, &rpcMsg);
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
  ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
}