YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/pgwrapper/pg_wrapper_test_base.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_YQL_PGWRAPPER_PG_WRAPPER_TEST_BASE_H
15
#define YB_YQL_PGWRAPPER_PG_WRAPPER_TEST_BASE_H
16
17
#include "yb/integration-tests/external_mini_cluster.h"
18
#include "yb/integration-tests/yb_mini_cluster_test_base.h"
19
20
namespace yb {
21
namespace pgwrapper {
22
23
class PgWrapperTestBase : public MiniClusterTestWithClient<ExternalMiniCluster> {
24
 protected:
25
  void SetUp() override;
26
27
95
  virtual int GetNumMasters() const { return 1; }
28
29
95
  virtual int GetNumTabletServers() const {
30
    // Test that we can start PostgreSQL servers on non-colliding ports within each tablet server.
31
95
    return 3;
32
95
  }
33
34
48
  virtual void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) {}
35
36
  // Tablet server to use to perform PostgreSQL operations.
37
  ExternalTabletServer* pg_ts = nullptr;
38
};
39
40
class PgCommandTestBase : public PgWrapperTestBase {
41
 protected:
42
  PgCommandTestBase(bool auth, bool encrypted)
43
      : use_auth_(auth), encrypt_connection_(encrypted) {}
44
45
0
  void SetDbName(const std::string& db_name) {
46
0
    db_name_ = db_name;
47
0
  }
48
49
  void RunPsqlCommand(const std::string &statement, const std::string &expected_output);
50
51
  void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) override;
52
53
  void CreateTable(const std::string &statement) {
54
    RunPsqlCommand(statement, "CREATE TABLE");
55
  }
56
57
0
  void CreateType(const std::string &statement) {
58
0
    RunPsqlCommand(statement, "CREATE TYPE");
59
0
  }
60
61
0
  void CreateIndex(const std::string &statement) {
62
0
    RunPsqlCommand(statement, "CREATE INDEX");
63
0
  }
64
65
0
  void CreateView(const std::string &statement) {
66
0
    RunPsqlCommand(statement, "CREATE VIEW");
67
0
  }
68
69
0
  void CreateProcedure(const std::string &statement) {
70
0
    RunPsqlCommand(statement, "CREATE PROCEDURE");
71
0
  }
72
73
0
  void CreateSchema(const std::string &statement) {
74
0
    RunPsqlCommand(statement, "CREATE SCHEMA");
75
0
  }
76
77
0
  void Call(const std::string &statement) {
78
0
    RunPsqlCommand(statement, "CALL");
79
0
  }
80
81
  void InsertRows(const std::string& statement, size_t expected_rows) {
82
    RunPsqlCommand(statement, Format("INSERT 0 $0", expected_rows));
83
  }
84
85
  void InsertOneRow(const std::string& statement) {
86
    InsertRows(statement, /* expected_rows */ 1);
87
  }
88
89
0
  void UpdateOneRow(const std::string &statement) {
90
0
    RunPsqlCommand(statement, "UPDATE 1");
91
0
  }
92
93
 private:
94
  const bool use_auth_;
95
  const bool encrypt_connection_;
96
97
  std::string db_name_;
98
};
99
100
} // namespace pgwrapper
101
} // namespace yb
102
103
#endif // YB_YQL_PGWRAPPER_PG_WRAPPER_TEST_BASE_H