github.com/dolthub/go-mysql-server@v0.18.0/sql/row_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 sql
    16  
    17  import (
    18  	"io"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestRowsToRowIterEmpty(t *testing.T) {
    25  	require := require.New(t)
    26  
    27  	ctx := NewEmptyContext()
    28  	iter := RowsToRowIter()
    29  	r, err := iter.Next(ctx)
    30  	require.Equal(io.EOF, err)
    31  	require.Nil(r)
    32  
    33  	r, err = iter.Next(ctx)
    34  	require.Equal(io.EOF, err)
    35  	require.Nil(r)
    36  
    37  	err = iter.Close(ctx)
    38  	require.NoError(err)
    39  }
    40  
    41  func TestRowsToRowIter(t *testing.T) {
    42  	require := require.New(t)
    43  
    44  	ctx := NewEmptyContext()
    45  	iter := RowsToRowIter(NewRow(1), NewRow(2), NewRow(3))
    46  	r, err := iter.Next(ctx)
    47  	require.NoError(err)
    48  	require.Equal(NewRow(1), r)
    49  
    50  	r, err = iter.Next(ctx)
    51  	require.NoError(err)
    52  	require.Equal(NewRow(2), r)
    53  
    54  	r, err = iter.Next(ctx)
    55  	require.NoError(err)
    56  	require.Equal(NewRow(3), r)
    57  
    58  	r, err = iter.Next(ctx)
    59  	require.Equal(io.EOF, err)
    60  	require.Nil(r)
    61  
    62  	r, err = iter.Next(ctx)
    63  	require.Equal(io.EOF, err)
    64  	require.Nil(r)
    65  
    66  	err = iter.Close(ctx)
    67  	require.NoError(err)
    68  }