github.com/dolthub/go-mysql-server@v0.18.0/sql/rowexec/showtablestatus_test.go (about)

     1  // Copyright 2020-2021 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package rowexec
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"github.com/dolthub/go-mysql-server/memory"
    23  	"github.com/dolthub/go-mysql-server/sql"
    24  	"github.com/dolthub/go-mysql-server/sql/plan"
    25  	"github.com/dolthub/go-mysql-server/test"
    26  )
    27  
    28  func TestShowTableStatus(t *testing.T) {
    29  	require := require.New(t)
    30  
    31  	db1 := memory.NewDatabase("a")
    32  	db1.AddTable("t1", memory.NewTable(db1, "t1", sql.PrimaryKeySchema{}, db1.GetForeignKeyCollection()))
    33  	db1.AddTable("t2", memory.NewTable(db1, "t2", sql.PrimaryKeySchema{}, db1.GetForeignKeyCollection()))
    34  
    35  	db2 := memory.NewDatabase("b")
    36  	db2.AddTable("t3", memory.NewTable(db2, "t3", sql.PrimaryKeySchema{}, db2.GetForeignKeyCollection()))
    37  	db2.AddTable("t4", memory.NewTable(db2, "t4", sql.PrimaryKeySchema{}, db2.GetForeignKeyCollection()))
    38  
    39  	catalog := test.NewCatalog(sql.NewDatabaseProvider(db1, db2))
    40  	pro := memory.NewDBProvider(db1, db2)
    41  	ctx := newContext(pro)
    42  
    43  	node := plan.NewShowTableStatus(db1)
    44  	node.Catalog = catalog
    45  
    46  	ctx.SetCurrentDatabase("a")
    47  	iter, err := DefaultBuilder.Build(ctx, node, nil)
    48  	require.NoError(err)
    49  
    50  	rows, err := sql.RowIterToRows(ctx, iter)
    51  	require.NoError(err)
    52  
    53  	expected := []sql.Row{
    54  		{"t1", "InnoDB", "10", "Fixed", uint64(0), uint64(0), uint64(0), uint64(0), int64(0), int64(0), nil, nil, nil, nil, sql.Collation_Default.String(), nil, nil, nil},
    55  		{"t2", "InnoDB", "10", "Fixed", uint64(0), uint64(0), uint64(0), uint64(0), int64(0), int64(0), nil, nil, nil, nil, sql.Collation_Default.String(), nil, nil, nil},
    56  	}
    57  
    58  	require.ElementsMatch(expected, rows)
    59  	node = plan.NewShowTableStatus(db2)
    60  	node.Catalog = catalog
    61  
    62  	iter, err = DefaultBuilder.Build(ctx, node, nil)
    63  	require.NoError(err)
    64  
    65  	rows, err = sql.RowIterToRows(ctx, iter)
    66  	require.NoError(err)
    67  
    68  	expected = []sql.Row{
    69  		{"t3", "InnoDB", "10", "Fixed", uint64(0), uint64(0), uint64(0), uint64(0), int64(0), int64(0), nil, nil, nil, nil, sql.Collation_Default.String(), nil, nil, nil},
    70  		{"t4", "InnoDB", "10", "Fixed", uint64(0), uint64(0), uint64(0), uint64(0), int64(0), int64(0), nil, nil, nil, nil, sql.Collation_Default.String(), nil, nil, nil},
    71  	}
    72  
    73  	require.ElementsMatch(expected, rows)
    74  }