func newSingleUseConnectorWithOptions(
	options ...types.ConnectorOption,
) *SingleUseConnector {
	args := &types.ConnectorOptions{}
	for _, option := range options {
		option(args)
	}
	return &SingleUseConnector{
		ConnectorOptions: *args,
	}
}
Test helpers

newSingleUseConnectorWithOptions creates a new SingleUseConnector, and allows
you to specify the newMSSQLConnector explicitly.  Intended to be used in unit
tests only.
package mssql
import (
	"errors"
	"io"
	"net"
	"testing"
	errorspkg "github.com/pkg/errors"
	"github.com/stretchr/testify/assert"
	"github.com/cyberark/secretless-broker/internal/plugin/connectors/tcp/mssql/mock"
	"github.com/cyberark/secretless-broker/internal/plugin/connectors/tcp/mssql/types"
	pluginconnector "github.com/cyberark/secretless-broker/pkg/secretless/plugin/connector"
	mssql "github.com/denisenkom/go-mssqldb"
)
func TestSingleUseConnector_Connect(t *testing.T) {
	t.Run("singleUseConnector.driver#Connect success", func(t *testing.T) {
		expectedBackendConn := mock.DefaultMSSQLConnectorCtor.BackendConn
		connector := newSingleUseConnectorWithOptions(
			mock.DefaultConnectorOptions,
		)
		actualBackendConn, err := runDefaultTestConnect(connector)
		assert.Nil(t, err)
		if err != nil {
			return
		}
		assert.Equal(t, expectedBackendConn, actualBackendConn)
	})
	t.Run("singleUseConnector.driver#Connect fail", func(t *testing.T) {
		var methodFailsExpectedErr = errors.New("failed to complete connection")
		customCtor := mock.DefaultMSSQLConnectorCtor
		customCtor.Err = methodFailsExpectedErr
		methodFails(t, methodFailsExpectedErr, mock.CustomNewMSSQLConnectorOption(customCtor))
	})
	t.Run("singleUseConnector#ReadPreLoginRequest fail", func(t *testing.T) {
		var methodFailsExpectedErr = errors.New("failed to read prelogin request from client")
		methodFails(t, methodFailsExpectedErr, func(connectorOptions *types.ConnectorOptions) {
			connectorOptions.ReadPreloginRequest = func(
				io.ReadWriteCloser,
			) (map[uint8][]byte, error) {
				return nil, methodFailsExpectedErr
			}
		})
	})
	t.Run("singleUseConnector#WritePreloginResponse succeeds", func(t *testing.T) {
		fakePreLoginResponse := map[uint8][]byte{
			mssql.PreloginVERSION:    {0, 0, 0, 0, 0, 0},
			mssql.PreloginENCRYPTION: {mssql.EncryptOn},
			mssql.PreloginINSTOPT:    {0},
			mssql.PreloginTHREADID:   {0, 0, 0, 0},
			mssql.PreloginMARS:       {0},  
		}
		expectedPreLoginResponse := map[uint8][]byte{
			mssql.PreloginVERSION:    {0, 0, 0, 0, 0, 0},
			mssql.PreloginENCRYPTION: {mssql.EncryptNotSup},
			mssql.PreloginINSTOPT:    {0},
			mssql.PreloginTHREADID:   {0, 0, 0, 0},
			mssql.PreloginMARS:       {0},  
		}
		var actualPreLoginResponse map[uint8][]byte
		var actualClient io.ReadWriteCloser
		customCtor := mock.DefaultMSSQLConnectorCtor
		customCtor.ServerPreloginResponse = fakePreLoginResponse
		connector := newSingleUseConnectorWithOptions(
			mock.DefaultConnectorOptions,
			mock.CustomNewMSSQLConnectorOption(customCtor),
			func(connectorOptions *types.ConnectorOptions) {
				connectorOptions.WritePreloginResponse = func(
					w io.ReadWriteCloser,
					fields map[uint8][]byte,
				) error {
					actualClient = w
					actualPreLoginResponse = fields
					return nil
				}
			},
		)
		_, _ = runDefaultTestConnect(connector)
		expectedClient := connector.clientConn
		assert.Equal(t, actualPreLoginResponse, expectedPreLoginResponse)
		assert.Equal(t, expectedClient, actualClient)
	})
	t.Run("singleUseConnector#WritePreloginResponse fails", func(t *testing.T) {
		var methodFailsExpectedErr = errors.New("failed to write prelogin response to client")
		methodFails(t, methodFailsExpectedErr, func(connectorOptions *types.ConnectorOptions) {
			connectorOptions.WritePreloginResponse = func(
				io.ReadWriteCloser,
				map[uint8][]byte,
			) error {
				return methodFailsExpectedErr
			}
		})
	})
	t.Run("singleUseConnector#ReadLoginRequest succeeds", func(t *testing.T) {
		expectedLoginRequest := &mssql.LoginRequest{}
		expectedLoginRequest.Database = "test-database"
		expectedLoginRequest.AppName = "test-app-name"
		var actualLoginRequest *mssql.LoginRequest
		var actualClient io.ReadWriteCloser
		customCtor := mock.DefaultMSSQLConnectorCtor
		customCtor.ClientLoginRequestPtr = &actualLoginRequest
		connector := newSingleUseConnectorWithOptions(
			mock.DefaultConnectorOptions,
			mock.CustomNewMSSQLConnectorOption(customCtor),
			func(connectorOptions *types.ConnectorOptions) {
				connectorOptions.ReadLoginRequest = func(r io.ReadWriteCloser) (*mssql.LoginRequest, error) {
					actualClient = r
					return expectedLoginRequest, nil
				}
			},
		)
		_, _ = runDefaultTestConnect(connector)
		expectedClient := connector.clientConn
		assert.Equal(t, actualLoginRequest, expectedLoginRequest)
		assert.Equal(t, expectedClient, actualClient)
	})
	t.Run("singleUseConnector#ReadLoginRequest fail", func(t *testing.T) {
		var methodFailsExpectedErr = errors.New("failed to handle login from client")
		methodFails(t, methodFailsExpectedErr, func(connectorOptions *types.ConnectorOptions) {
			connectorOptions.ReadLoginRequest = func(
				r io.ReadWriteCloser,
			) (request *mssql.LoginRequest, e error) {
				return nil, methodFailsExpectedErr
			}
		})
	})
}