github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/buffer_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package colexec
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    18  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    19  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestBufferOp(t *testing.T) {
    24  	defer leaktest.AfterTest(t)()
    25  
    26  	ctx := context.Background()
    27  	inputTuples := tuples{{int64(1)}, {int64(2)}, {int64(3)}}
    28  	input := newOpTestInput(coldata.BatchSize(), inputTuples, []*types.T{types.Int})
    29  	buffer := NewBufferOp(input).(*bufferOp)
    30  	buffer.Init()
    31  
    32  	t.Run("TestBufferReturnsInputCorrectly", func(t *testing.T) {
    33  		buffer.advance(ctx)
    34  		b := buffer.Next(ctx)
    35  		require.Nil(t, b.Selection())
    36  		require.Equal(t, len(inputTuples), b.Length())
    37  		for i, val := range inputTuples {
    38  			require.Equal(t, val[0], b.ColVec(0).Int64()[i])
    39  		}
    40  
    41  		// We've read over the batch, so we now should get a zero-length batch.
    42  		b = buffer.Next(ctx)
    43  		require.Nil(t, b.Selection())
    44  		require.Equal(t, 0, b.Length())
    45  	})
    46  }