vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/gen4/column_name_test.go (about)

     1  /*
     2  Copyright 2021 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 vtgate
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"vitess.io/vitess/go/test/endtoend/utils"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  	"github.com/stretchr/testify/require"
    27  
    28  	"vitess.io/vitess/go/mysql"
    29  	"vitess.io/vitess/go/test/endtoend/cluster"
    30  )
    31  
    32  func TestColumnNames(t *testing.T) {
    33  	defer cluster.PanicHandler(t)
    34  	ctx := context.Background()
    35  
    36  	conn, err := mysql.Connect(ctx, &vtParams)
    37  	require.NoError(t, err)
    38  	defer conn.Close()
    39  
    40  	utils.Exec(t, conn, "create table uks.t2(id bigint,phone bigint,msg varchar(100),primary key(id)) Engine=InnoDB")
    41  	defer utils.Exec(t, conn, "drop table uks.t2")
    42  
    43  	qr := utils.Exec(t, conn, "SELECT t1.id as t1id, t2.id as t2id, t2.phone as t2phn FROM ks.t1 cross join uks.t2 where t1.id = t2.id ORDER BY t2.phone")
    44  
    45  	assert.Equal(t, 3, len(qr.Fields))
    46  	assert.Equal(t, "t1id", qr.Fields[0].Name)
    47  	assert.Equal(t, "t2id", qr.Fields[1].Name)
    48  	assert.Equal(t, "t2phn", qr.Fields[2].Name)
    49  }