vitess.io/vitess@v0.16.2/go/vt/vtgate/endtoend/misc_test.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 endtoend
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"testing"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  	"github.com/stretchr/testify/require"
    26  
    27  	"vitess.io/vitess/go/mysql"
    28  )
    29  
    30  var ctx = context.Background()
    31  
    32  func TestDatabaseFunc(t *testing.T) {
    33  	conn, err := mysql.Connect(ctx, &vtParams)
    34  	require.NoError(t, err)
    35  	defer conn.Close()
    36  
    37  	exec(t, conn, "use ks")
    38  	qr := exec(t, conn, "select database()")
    39  	require.Equal(t, `[[VARCHAR("ks")]]`, fmt.Sprintf("%v", qr.Rows))
    40  }
    41  
    42  func TestSysNumericPrecisionScale(t *testing.T) {
    43  	conn, err := mysql.Connect(ctx, &vtParams)
    44  	require.NoError(t, err)
    45  	defer conn.Close()
    46  
    47  	qr := exec(t, conn, "select numeric_precision, numeric_scale from information_schema.columns where table_schema = 'ks' and table_name = 't1'")
    48  	assert.True(t, qr.Fields[0].Type == qr.Rows[0][0].Type())
    49  	assert.True(t, qr.Fields[1].Type == qr.Rows[0][1].Type())
    50  }
    51  
    52  func TestCreateAndDropDatabase(t *testing.T) {
    53  	// note that this is testing vttest and not vtgate
    54  	conn, err := mysql.Connect(ctx, &vtParams)
    55  	require.NoError(t, err)
    56  	defer conn.Close()
    57  
    58  	// run it 3 times.
    59  	for count := 0; count < 3; count++ {
    60  		t.Run(fmt.Sprintf("exec:%d", count), func(t *testing.T) {
    61  			_ = exec(t, conn, "create database testitest")
    62  			_ = exec(t, conn, "use testitest")
    63  			qr := exec(t, conn, "select round(1.58)")
    64  			assert.Equal(t, `[[DECIMAL(2)]]`, fmt.Sprintf("%v", qr.Rows))
    65  
    66  			_ = exec(t, conn, "drop database testitest")
    67  			_, err = conn.ExecuteFetch("use testitest", 1000, true)
    68  			require.Error(t, err)
    69  		})
    70  	}
    71  }