show.cpp 2.0 KB
Newer Older
S
Shengliang Guan 已提交
1
/**
S
Shengliang Guan 已提交
2
 * @file show.cpp
S
Shengliang Guan 已提交
3
 * @author slguan (slguan@taosdata.com)
S
Shengliang Guan 已提交
4 5 6
 * @brief MNODE module show tests
 * @version 1.0
 * @date 2022-01-06
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2022
S
Shengliang Guan 已提交
9 10 11
 *
 */

S
Shengliang Guan 已提交
12
#include "sut.h"
S
Shengliang Guan 已提交
13

S
Shengliang Guan 已提交
14
class MndTestShow : public ::testing::Test {
S
Shengliang Guan 已提交
15
 protected:
S
Shengliang Guan 已提交
16
  static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); }
S
Shengliang Guan 已提交
17
  static void TearDownTestSuite() { test.Cleanup(); }
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
  static Testbase test;
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21 22 23 24
 public:
  void SetUp() override {}
  void TearDown() override {}
};
S
Shengliang Guan 已提交
25

S
Shengliang Guan 已提交
26
Testbase MndTestShow::test;
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
S
Shengliang Guan 已提交
29 30
  SShowReq showReq = {0};
  showReq.type = TSDB_MGMT_TABLE_MAX;
S
Shengliang Guan 已提交
31

S
Shengliang Guan 已提交
32 33 34 35
  int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSShowReq(pReq, contLen, &showReq);
  tFreeSShowReq(&showReq);
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
37
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
S
Shengliang Guan 已提交
38
  ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
39
  ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_MSG);
S
Shengliang Guan 已提交
40 41
}

S
Shengliang Guan 已提交
42
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
S
Shengliang Guan 已提交
43 44
  SShowReq showReq = {0};
  showReq.type = TSDB_MGMT_TABLE_START;
S
Shengliang Guan 已提交
45

S
Shengliang Guan 已提交
46 47 48 49
  int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSShowReq(pReq, contLen, &showReq);
  tFreeSShowReq(&showReq);
S
Shengliang Guan 已提交
50

S
Shengliang Guan 已提交
51
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
S
Shengliang Guan 已提交
52
  ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
53
  ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_MSG);
S
Shengliang Guan 已提交
54
}
S
Shengliang Guan 已提交
55

S
Shengliang Guan 已提交
56
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
S
Shengliang Guan 已提交
57 58 59 60
  SConnectReq connectReq = {0};
  connectReq.pid = 1234;
  strcpy(connectReq.app, "mnode_test_show");
  strcpy(connectReq.db, "");
S
Shengliang Guan 已提交
61

S
Shengliang Guan 已提交
62 63 64
  int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSConnectReq(pReq, contLen, &connectReq);
S
Shengliang Guan 已提交
65

S
Shengliang Guan 已提交
66 67 68
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
69

S
Shengliang Guan 已提交
70 71
  test.SendShowReq(TSDB_MGMT_TABLE_CONNS, "connections", "");
  // EXPECT_EQ(test.GetShowRows(), 1);
S
Shengliang Guan 已提交
72
}
S
Shengliang Guan 已提交
73 74

TEST_F(MndTestShow, 04_ShowMsg_Cluster) {
S
Shengliang Guan 已提交
75
  test.SendShowReq(TSDB_MGMT_TABLE_CLUSTER, "cluster", "");
S
Shengliang Guan 已提交
76 77
  EXPECT_EQ(test.GetShowRows(), 1);
}