parInitialDTest.cpp 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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 "parTestUtil.h"

using namespace std;

namespace ParserTest {

X
Xiaoyu Wang 已提交
22
class ParserInitialDTest : public ParserDdlTest {};
23 24 25 26

// todo delete
// todo desc
// todo describe
X
Xiaoyu Wang 已提交
27
// todo DROP account
28 29 30 31

TEST_F(ParserInitialDTest, dropBnode) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
32 33 34
  run("DROP BNODE ON DNODE 1");
}

35
// DROP CONSUMER GROUP [ IF EXISTS ] cgroup_name ON topic_name
X
Xiaoyu Wang 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
TEST_F(ParserInitialDTest, dropCGroup) {
  useDb("root", "test");

  SMDropCgroupReq expect = {0};

  auto setDropCgroupReqFunc = [&](const char* pTopicName, const char* pCGroupName, int8_t igNotExists = 0) {
    memset(&expect, 0, sizeof(SMDropCgroupReq));
    snprintf(expect.topic, sizeof(expect.topic), "0.%s", pTopicName);
    strcpy(expect.cgroup, pCGroupName);
    expect.igNotExists = igNotExists;
  };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_DROP_CGROUP_STMT);
    SMDropCgroupReq req = {0};
    ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSMDropCgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));

    ASSERT_EQ(std::string(req.topic), std::string(expect.topic));
    ASSERT_EQ(std::string(req.cgroup), std::string(expect.cgroup));
    ASSERT_EQ(req.igNotExists, expect.igNotExists);
  });

  setDropCgroupReqFunc("tp1", "cg1");
59
  run("DROP CONSUMER GROUP cg1 ON tp1");
X
Xiaoyu Wang 已提交
60 61

  setDropCgroupReqFunc("tp1", "cg1", 1);
62
  run("DROP CONSUMER GROUP IF EXISTS cg1 ON tp1");
63 64
}

X
Xiaoyu Wang 已提交
65 66 67
// todo DROP database
// todo DROP dnode
// todo DROP function
68 69 70 71

TEST_F(ParserInitialDTest, dropIndex) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
72
  run("DROP index index1 on t1");
73 74 75 76 77
}

TEST_F(ParserInitialDTest, dropMnode) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
78
  run("DROP mnode on dnode 1");
79 80 81 82 83
}

TEST_F(ParserInitialDTest, dropQnode) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
84
  run("DROP qnode on dnode 1");
85 86 87 88 89
}

TEST_F(ParserInitialDTest, dropSnode) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
90
  run("DROP snode on dnode 1");
91 92
}

X
Xiaoyu Wang 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105
TEST_F(ParserInitialDTest, dropSTable) {
  useDb("root", "test");

  run("DROP STABLE st1");
}

// todo DROP stream

TEST_F(ParserInitialDTest, dropTable) {
  useDb("root", "test");

  run("DROP TABLE t1");
}
106 107 108 109

TEST_F(ParserInitialDTest, dropTopic) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
110
  run("DROP topic tp1");
111

X
Xiaoyu Wang 已提交
112
  run("DROP topic if exists tp1");
113 114 115
}

TEST_F(ParserInitialDTest, dropUser) {
116
  login("root");
117 118
  useDb("root", "test");

X
Xiaoyu Wang 已提交
119
  run("DROP user wxy");
120 121 122
}

}  // namespace ParserTest