acct.cpp 3.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "deploy.h"

class DndTestAcct : public ::testing::Test {
 protected:
S
Shengliang Guan 已提交
20 21 22 23 24
   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 已提交
25 26

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

S
Shengliang Guan 已提交
29 30 31 32 33
    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 已提交
34 35 36
  }

  static void TearDownTestSuite() {
S
Shengliang Guan 已提交
37
    stopServer(pServer);
S
Shengliang Guan 已提交
38
    dropClient(pClient);
S
Shengliang Guan 已提交
39 40
    pServer = NULL;
    pClient = NULL;
S
Shengliang Guan 已提交
41 42 43 44 45 46 47 48 49 50 51
  }

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

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

S
Shengliang Guan 已提交
52
TEST_F(DndTestAcct, 01_CreateAcct) {
S
Shengliang Guan 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  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 已提交
68
TEST_F(DndTestAcct, 02_AlterAcct) {
S
Shengliang Guan 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  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 已提交
84
TEST_F(DndTestAcct, 03_DropAcct) {
S
Shengliang Guan 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  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 已提交
100
TEST_F(DndTestAcct, 04_ShowAcct) {
S
Shengliang Guan 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  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);
}