github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/topic_read_messages_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
    12  	"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicsugar"
    13  )
    14  
    15  func TestTopicReadMessages(t *testing.T) {
    16  	ctx := xtest.Context(t)
    17  
    18  	db, reader := createFeedAndReader(ctx, t)
    19  
    20  	sendCDCMessage(ctx, t, db)
    21  	msg, err := reader.ReadMessage(ctx)
    22  	require.NoError(t, err)
    23  	require.NotEmpty(t, msg.CreatedAt)
    24  	t.Logf("msg: %#v", msg)
    25  
    26  	require.NoError(t, err)
    27  	err = topicsugar.ReadMessageDataWithCallback(msg, func(data []byte) error {
    28  		t.Log("Content:", string(data))
    29  		return nil
    30  	})
    31  	require.NoError(t, err)
    32  
    33  	sendCDCMessage(ctx, t, db)
    34  	batch, err := reader.ReadMessageBatch(ctx)
    35  	require.NoError(t, err)
    36  	require.NotEmpty(t, batch.Messages)
    37  }