vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletserver/schema/schematest/schematest.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package schematest provides support for testing packages
    18  // that depend on schema
    19  package schematest
    20  
    21  import (
    22  	"vitess.io/vitess/go/mysql"
    23  	"vitess.io/vitess/go/mysql/fakesqldb"
    24  	"vitess.io/vitess/go/sqltypes"
    25  
    26  	querypb "vitess.io/vitess/go/vt/proto/query"
    27  )
    28  
    29  // AddDefaultQueries returns a default set of queries that can
    30  // be added to load an initial set of tables into the schema.
    31  func AddDefaultQueries(db *fakesqldb.DB) {
    32  	db.ClearQueryPattern()
    33  	db.AddQuery("select unix_timestamp()", &sqltypes.Result{
    34  		Fields: []*querypb.Field{{
    35  			Type: sqltypes.Uint64,
    36  		}},
    37  		Rows: [][]sqltypes.Value{
    38  			{sqltypes.NewInt32(1427325875)},
    39  		},
    40  	})
    41  	db.AddQuery("select @@global.sql_mode", &sqltypes.Result{
    42  		Fields: []*querypb.Field{{
    43  			Type: sqltypes.VarChar,
    44  		}},
    45  		Rows: [][]sqltypes.Value{
    46  			{sqltypes.NewVarBinary("STRICT_TRANS_TABLES")},
    47  		},
    48  	})
    49  	db.AddQuery("select @@autocommit", &sqltypes.Result{
    50  		Fields: []*querypb.Field{{
    51  			Type: sqltypes.Uint64,
    52  		}},
    53  		Rows: [][]sqltypes.Value{
    54  			{sqltypes.NewVarBinary("1")},
    55  		},
    56  	})
    57  	db.AddQuery("select @@sql_auto_is_null", &sqltypes.Result{
    58  		Fields: []*querypb.Field{{
    59  			Type: sqltypes.Uint64,
    60  		}},
    61  		Rows: [][]sqltypes.Value{
    62  			{sqltypes.NewVarBinary("0")},
    63  		},
    64  	})
    65  
    66  	db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{
    67  		Fields: mysql.ShowPrimaryFields,
    68  		Rows: [][]sqltypes.Value{
    69  			mysql.ShowPrimaryRow("test_table_01", "pk"),
    70  			mysql.ShowPrimaryRow("test_table_02", "pk"),
    71  			mysql.ShowPrimaryRow("test_table_03", "pk"),
    72  			mysql.ShowPrimaryRow("seq", "id"),
    73  			mysql.ShowPrimaryRow("msg", "id"),
    74  		},
    75  	})
    76  
    77  	db.MockQueriesForTable("test_table_01", &sqltypes.Result{
    78  		Fields: []*querypb.Field{{
    79  			Name: "pk",
    80  			Type: sqltypes.Int32,
    81  		}},
    82  	})
    83  
    84  	db.MockQueriesForTable("test_table_02", &sqltypes.Result{
    85  		Fields: []*querypb.Field{{
    86  			Name: "pk",
    87  			Type: sqltypes.Int32,
    88  		}},
    89  	})
    90  
    91  	db.MockQueriesForTable("test_table_03", &sqltypes.Result{
    92  		Fields: []*querypb.Field{{
    93  			Name: "pk",
    94  			Type: sqltypes.Int32,
    95  		}},
    96  	})
    97  
    98  	db.MockQueriesForTable("seq", &sqltypes.Result{
    99  		Fields: []*querypb.Field{{
   100  			Name: "id",
   101  			Type: sqltypes.Int32,
   102  		}, {
   103  			Name: "next_id",
   104  			Type: sqltypes.Int64,
   105  		}, {
   106  			Name: "cache",
   107  			Type: sqltypes.Int64,
   108  		}, {
   109  			Name: "increment",
   110  			Type: sqltypes.Int64,
   111  		}},
   112  	})
   113  
   114  	db.MockQueriesForTable("msg", &sqltypes.Result{
   115  		Fields: []*querypb.Field{{
   116  			Name: "id",
   117  			Type: sqltypes.Int64,
   118  		}, {
   119  			Name: "priority",
   120  			Type: sqltypes.Int64,
   121  		}, {
   122  			Name: "time_next",
   123  			Type: sqltypes.Int64,
   124  		}, {
   125  			Name: "epoch",
   126  			Type: sqltypes.Int64,
   127  		}, {
   128  			Name: "time_acked",
   129  			Type: sqltypes.Int64,
   130  		}, {
   131  			Name: "message",
   132  			Type: sqltypes.Int64,
   133  		}},
   134  	})
   135  
   136  	db.AddQuery("begin", &sqltypes.Result{})
   137  	db.AddQuery("commit", &sqltypes.Result{})
   138  
   139  }