Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap conn created with connector #221

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (d otDriver) Connect(ctx context.Context) (driver.Conn, error) {
return nil, err
}

return makeConn(c, d.connConfig), nil
return wrapConn(c, d.connConfig), nil
}

func (d otDriver) Driver() driver.Driver {
Expand Down
40 changes: 40 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ func TestWrap_DriverContext_ConnectError(t *testing.T) {
assert.Equal(t, expectedError, err)
}

func TestWrap_DriverContext_ConnectNamedValueChecker(t *testing.T) {
t.Parallel()

_, m, err := sqlmock.New()
require.NoError(t, err)

parent := struct {
driver.Driver
driver.DriverContext
}{
DriverContext: driverOpenConnectorFunc(func(name string) (driver.Connector, error) {
return struct {
driverDriverFunc
driverConnectFunc
driverNamedValueCheckerFunc
}{
driverConnectFunc: func(ctx context.Context) (driver.Conn, error) {
return m.(driver.Conn), nil
},
}, nil
}),
}

drv := otelsql.Wrap(parent).(driver.DriverContext) // nolint: errcheck

connector, err := drv.OpenConnector("")
require.NoError(t, err)

conn, err := connector.Connect(context.Background())
require.NoError(t, err)

assert.Implements(t, (*driver.NamedValueChecker)(nil), conn)
}

func TestWrap_DriverContext_CloseBeforeOpenConnector(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2758,6 +2792,12 @@ func (f driverDriverFunc) Driver() driver.Driver {
return f()
}

type driverNamedValueCheckerFunc func(*driver.NamedValue) error

func (f driverNamedValueCheckerFunc) CheckNamedValue(nv *driver.NamedValue) error {
return f(nv)
}

type testError string

func (e testError) Error() string {
Expand Down