Skip to content

Commit

Permalink
Merge pull request #1512 PublicRevertReorderForIssue1501
Browse files Browse the repository at this point in the history
PublicRevertReorderForIssue1501
  • Loading branch information
rekby authored Oct 17, 2024
2 parents 5acfc74 + 29f6adb commit 1bcbc91
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions tests/integration/database_sql_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

Expand Down Expand Up @@ -167,3 +168,130 @@ func TestRegressionKikimr17104(t *testing.T) {
})
})
}

func TestUUIDSerializationDatabaseSQLIssue1501(t *testing.T) {
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
// test with special uuid - all bytes are different for check any byte swaps

t.Run("old-send", func(t *testing.T) {
// test old behavior - for test way of safe work with data, written with bagged API version
var (
scope = newScope(t)
db = scope.SQLDriver()
)

idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
expectedResultWithBug := "2d9e498b-b746-9cfb-084d-de4e1cb4736e"
id := [16]byte(uuid.MustParse(idString))
row := db.QueryRow(`
DECLARE $val AS UUID;
SELECT CAST($val AS Utf8)`, sql.Named("val", id),
)

require.NoError(t, row.Err())

var res string

err := row.Scan(&res)
require.NoError(t, err)
require.Equal(t, expectedResultWithBug, res)
})
t.Run("old-receive-to-bytes", func(t *testing.T) {
// test old behavior - for test way of safe work with data, written with bagged API version
var (
scope = newScope(t)
db = scope.SQLDriver()
)

idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
expectedResultWithBug := "8b499e2d-46b7-fb9c-4d08-4ede6e73b41c"
row := db.QueryRow(`
DECLARE $val AS Text;
SELECT CAST($val AS UUID)`,
sql.Named("val", idString),
)

require.NoError(t, row.Err())

var res [16]byte

err := row.Scan(&res)
require.NoError(t, err)

resUUID := uuid.UUID(res)
require.Equal(t, expectedResultWithBug, resUUID.String())
})
t.Run("old-receive-to-string", func(t *testing.T) {
// test old behavior - for test way of safe work with data, written with bagged API version
var (
scope = newScope(t)
db = scope.SQLDriver()
)

idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
row := db.QueryRow(`
DECLARE $val AS Text;
SELECT CAST($val AS UUID)`,
sql.Named("val", idString),
)

require.NoError(t, row.Err())

var res string

err := row.Scan(&res)
require.Error(t, err)
})
t.Run("old-receive-to-uuid", func(t *testing.T) {
// test old behavior - for test way of safe work with data, written with bagged API version
var (
scope = newScope(t)
db = scope.SQLDriver()
)

idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
row := db.QueryRow(`
DECLARE $val AS Text;
SELECT CAST($val AS UUID)`,
sql.Named("val", idString),
)

require.NoError(t, row.Err())

var res uuid.UUID

err := row.Scan(&res)
require.Error(t, err)
})
t.Run("old-send-receive", func(t *testing.T) {
// test old behavior - for test way of safe work with data, written with bagged API version
var (
scope = newScope(t)
db = scope.SQLDriver()
)

idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
id := uuid.MustParse(idString)
idParam := [16]byte(id)
row := db.QueryRow(`
DECLARE $val AS UUID;
SELECT $val`,
sql.Named("val", idParam),
)

require.NoError(t, row.Err())

var resBytes [16]byte
err := row.Scan(&resBytes)
require.NoError(t, err)

resUUID := uuid.UUID(resBytes)

require.Equal(t, id, resUUID)
})
}

0 comments on commit 1bcbc91

Please sign in to comment.