# Copyright 2023 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Preparation.
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> DBGInvoke __drop_tidb_table(default, t1)
=> DBGInvoke __drop_tidb_table(default, t2)
=> DBGInvoke __drop_tidb_table(default, t3)
=> DBGInvoke __refresh_schemas()



# create table and insert some rows
=> DBGInvoke __mock_tidb_db(default)
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __create_tidb_tables(default, t1, t2, t3)
=> DBGInvoke __refresh_mapped_table_schema(default, t1)
=> DBGInvoke __refresh_mapped_table_schema(default, t2)
=> DBGInvoke __refresh_mapped_table_schema(default, t3)

=> DBGInvoke query_mapped('select tidb_database,tidb_name,engine from system.tables where database=''\$d'' and name=''\$t''', default, t1)
┌─tidb_database─┬─tidb_name─┬─engine─────┐
│ default       │ t1        │ DeltaMerge │
└───────────────┴───────────┴────────────┘

=> DBGInvoke query_mapped('select tidb_database,tidb_name,engine from system.tables where database=''\$d'' and name=''\$t''', default, t2)
┌─tidb_database─┬─tidb_name─┬─engine─────┐
│ default       │ t2        │ DeltaMerge │
└───────────────┴───────────┴────────────┘

=> DBGInvoke query_mapped('select tidb_database,tidb_name,engine from system.tables where database=''\$d'' and name=''\$t''', default, t3)
┌─tidb_database─┬─tidb_name─┬─engine─────┐
│ default       │ t3        │ DeltaMerge │
└───────────────┴───────────┴────────────┘

# clean
=> DBGInvoke __drop_tidb_table(default, test)
=> DBGInvoke __drop_tidb_table(default, t1)
=> DBGInvoke __drop_tidb_table(default, t2)
=> DBGInvoke __drop_tidb_table(default, t3)
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __enable_schema_sync_service('true')
