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

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"os"
     9  	"path"
    10  	"regexp"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/require"
    14  
    15  	"github.com/ydb-platform/ydb-go-sdk/v3"
    16  	"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
    17  	"github.com/ydb-platform/ydb-go-sdk/v3/table"
    18  	"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
    19  	"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
    20  )
    21  
    22  func TestDataQueryIssueRowCol(t *testing.T) {
    23  	ctx, cancel := context.WithCancel(context.Background())
    24  	defer cancel()
    25  
    26  	db, err := ydb.Open(ctx,
    27  		os.Getenv("YDB_CONNECTION_STRING"),
    28  		ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")),
    29  	)
    30  	require.NoError(t, err)
    31  	exists, err := sugar.IsTableExists(ctx, db.Scheme(), path.Join(db.Name(), "users"))
    32  	require.NoError(t, err)
    33  	if exists {
    34  		err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
    35  			return s.DropTable(ctx, path.Join(db.Name(), "users"))
    36  		})
    37  		require.NoError(t, err)
    38  	}
    39  	err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
    40  		return s.CreateTable(ctx, path.Join(db.Name(), "users"),
    41  			options.WithColumn("id", types.TypeUint64),
    42  			options.WithPrimaryKeyColumn("id"),
    43  		)
    44  	})
    45  	require.NoError(t, err)
    46  	err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
    47  		_, _, err = s.Execute(ctx, table.DefaultTxControl(), `
    48  				UPSERT INTO "users" (id) VALUES (1);
    49  			`, nil,
    50  		)
    51  		return err
    52  	})
    53  	require.Error(t, err)
    54  	err = ydb.OperationError(err)
    55  	require.Error(t, err)
    56  	re := regexp.MustCompile(", address = [a-zA-Z0-9.:-]+,")
    57  	errText := re.ReplaceAllStringFunc(err.Error(), func(s string) string {
    58  		return ","
    59  	})
    60  	require.Equal(t, "operation/GENERIC_ERROR (code = 400080, issues = [{2:17 => 'String literal can not be used here'}])", errText) //nolint:lll
    61  }