github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/topic/topicwriterinternal/writer_single_stream_test.go (about)

     1  package topicwriterinternal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicwriter"
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
    10  )
    11  
    12  func TestWriterImpl_CreateInitMessage(t *testing.T) {
    13  	t.Run("Empty", func(t *testing.T) {
    14  		ctx := xtest.Context(t)
    15  		cfg := SingleStreamWriterConfig{
    16  			WritersCommonConfig: WritersCommonConfig{
    17  				producerID:          "producer",
    18  				topic:               "topic",
    19  				writerMeta:          map[string]string{"key": "val"},
    20  				defaultPartitioning: rawtopicwriter.NewPartitioningPartitionID(5),
    21  				compressorCount:     1,
    22  			},
    23  			getLastSeqNum: true,
    24  		}
    25  		w := newSingleStreamWriterStopped(ctx, cfg)
    26  		expected := rawtopicwriter.InitRequest{
    27  			Path:             w.cfg.topic,
    28  			ProducerID:       w.cfg.producerID,
    29  			WriteSessionMeta: w.cfg.writerMeta,
    30  			Partitioning:     w.cfg.defaultPartitioning,
    31  			GetLastSeqNo:     true,
    32  		}
    33  		require.Equal(t, expected, w.createInitRequest())
    34  	})
    35  
    36  	t.Run("WithoutGetLastSeq", func(t *testing.T) {
    37  		ctx := xtest.Context(t)
    38  		w := newSingleStreamWriterStopped(ctx,
    39  			SingleStreamWriterConfig{getLastSeqNum: false},
    40  		)
    41  		require.False(t, w.createInitRequest().GetLastSeqNo)
    42  	})
    43  }