github.com/dolthub/go-mysql-server@v0.18.0/sql/rowexec/show_tables_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  	"io"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/require"
    22  
    23  	"github.com/dolthub/go-mysql-server/memory"
    24  	"github.com/dolthub/go-mysql-server/sql"
    25  	"github.com/dolthub/go-mysql-server/sql/plan"
    26  )
    27  
    28  func TestShowTables(t *testing.T) {
    29  	require := require.New(t)
    30  	ctx := sql.NewEmptyContext()
    31  
    32  	unresolvedShowTables := plan.NewShowTables(sql.UnresolvedDatabase(""), false, nil)
    33  
    34  	require.False(unresolvedShowTables.Resolved())
    35  	require.Nil(unresolvedShowTables.Children())
    36  
    37  	db := memory.NewDatabase("test")
    38  	db.AddTable("test1", memory.NewTable(db, "test1", sql.PrimaryKeySchema{}, db.GetForeignKeyCollection()))
    39  	db.AddTable("test2", memory.NewTable(db, "test2", sql.PrimaryKeySchema{}, db.GetForeignKeyCollection()))
    40  	db.AddTable("test3", memory.NewTable(db, "test3", sql.PrimaryKeySchema{}, db.GetForeignKeyCollection()))
    41  
    42  	resolvedShowTables := plan.NewShowTables(db, false, nil)
    43  	require.True(resolvedShowTables.Resolved())
    44  	require.Nil(resolvedShowTables.Children())
    45  
    46  	iter, err := DefaultBuilder.Build(ctx, resolvedShowTables, nil)
    47  	require.NoError(err)
    48  
    49  	res, err := iter.Next(ctx)
    50  	require.NoError(err)
    51  	require.Equal("test1", res[0])
    52  
    53  	res, err = iter.Next(ctx)
    54  	require.NoError(err)
    55  	require.Equal("test2", res[0])
    56  
    57  	res, err = iter.Next(ctx)
    58  	require.NoError(err)
    59  	require.Equal("test3", res[0])
    60  
    61  	_, err = iter.Next(ctx)
    62  	require.Equal(io.EOF, err)
    63  }