Skip to content

Commit

Permalink
xsql fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Oct 24, 2023
1 parent eae4c63 commit fb30263
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 138 deletions.
26 changes: 11 additions & 15 deletions internal/xsql/badconn/badconn_go1.18_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"database/sql/driver"
"errors"
"fmt"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -113,33 +114,28 @@ var errsToCheck = []error{
xerrors.Operation(
xerrors.WithStatusCode(Ydb.StatusIds_SESSION_BUSY),
),
xerrors.Retryable(errors.New("retryable error")),
xerrors.Retryable(errors.New("retryable error"), xerrors.WithDeleteSession()),
io.EOF,
xerrors.WithStackTrace(io.EOF),
}

func Test_badConnError_Is(t *testing.T) {
for _, err := range errsToCheck {
t.Run(err.Error(), func(t *testing.T) {
e := Map(err)

if xerrors.Is(e, driver.ErrBadConn) {
require.True(t, xerrors.Is(e, err))
}

if errors.Is(e, driver.ErrBadConn) {
require.True(t, errors.Is(e, err))
}
err = Map(err)
require.Equal(t,
xerrors.MustDeleteSession(err),
xerrors.Is(err, driver.ErrBadConn),
)
})
}
}

func Test_badConnError_As_Error(t *testing.T) {
for _, err := range errsToCheck {
t.Run(err.Error(), func(t *testing.T) {
var e xerrors.Error
if !xerrors.As(err, &e) {
t.Skip()
}

require.True(t, xerrors.As(Map(err), &e))
require.ErrorAs(t, Map(err), &err) //nolint:gosec
})
}
}
Loading

0 comments on commit fb30263

Please sign in to comment.