mock

package
v1.7.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConnectorOptions types.ConnectorOption = func(connectOptions *types.ConnectorOptions) {
	connectOptions.Logger = logmock.NewLogger()
	connectOptions.ReadPreloginRequest = SuccessfulReadPreloginRequest
	connectOptions.WritePreloginResponse = SuccessfulWritePreloginResponse
	connectOptions.ReadLoginRequest = SuccessfulReadLoginRequest
	connectOptions.WriteError = SuccessfulWriteError
	connectOptions.NewTdsBuffer = FakeTdsBufferCtor
	connectOptions.NewMSSQLConnector = DefaultNewMSSQLConnector
}

DefaultConnectorOptions is a 'functional option' containing the default successful methods of each dependency

View Source
var DefaultMSSQLConnectorCtor = MSSQLConnectorCtor{
	BackendConn:            NewNetConn(nil),
	Err:                    nil,
	ServerPreloginResponse: map[uint8][]byte{},
	ClientLoginRequestPtr:  nil,
}

DefaultMSSQLConnectorCtor is the default constructor for MSSQLConnectorCtor

View Source
var DefaultNewMSSQLConnector = NewSuccessfulMSSQLConnectorCtor(
	func(ctx context.Context) (net.Conn, error) {
		interceptor := mssql.ConnectInterceptorFromContext(ctx)

		interceptor.ServerPreLoginResponse <- DefaultMSSQLConnectorCtor.ServerPreloginResponse

		<-interceptor.ClientLoginRequest

		return DefaultMSSQLConnectorCtor.BackendConn, DefaultMSSQLConnectorCtor.Err
	},
)

DefaultNewMSSQLConnector returns an always successful MSSQLConnectorCtor

Functions

func CustomNewMSSQLConnectorOption added in v1.5.0

func CustomNewMSSQLConnectorOption(ctor MSSQLConnectorCtor) types.ConnectorOption

CustomNewMSSQLConnectorOption allows us to inject a custom MSSQLConnectorCtor to control the output of the connect method

func FakeTdsBufferCtor

func FakeTdsBufferCtor(r io.ReadWriteCloser) io.ReadWriteCloser

FakeTdsBufferCtor returns the ReadWriteCloser passed in.

func NewFailingMSSQLConnector

func NewFailingMSSQLConnector(err error) types.MSSQLConnector

NewFailingMSSQLConnector returns an MSSQLConnector double whose Connect method always fails.

func NewFailingMSSQLConnectorCtor

func NewFailingMSSQLConnectorCtor(err error) types.MSSQLConnectorCtor

NewFailingMSSQLConnectorCtor returns an MSSQLConnectorCtor that always returns the specified error.

func NewSuccessfulMSSQLConnector

func NewSuccessfulMSSQLConnector(
	fn func(context.Context) (net.Conn, error),
) types.MSSQLConnector

NewSuccessfulMSSQLConnector returns an MSSQLConnector double whose Connect method always succeeds.

func NewSuccessfulMSSQLConnectorCtor

func NewSuccessfulMSSQLConnectorCtor(
	fn types.MSSQLConnectorFunc,
) types.MSSQLConnectorCtor

NewSuccessfulMSSQLConnectorCtor returns an MSSQLConnectorCtor that always succeeds.

func SuccessfulReadLoginRequest added in v1.5.0

func SuccessfulReadLoginRequest(io.ReadWriteCloser) (*mssql.LoginRequest, error)

SuccessfulReadLoginRequest is a double for a ReadLoginRequestFunc that always succeeds.

func SuccessfulReadPreloginRequest added in v1.5.0

func SuccessfulReadPreloginRequest(io.ReadWriteCloser) (map[uint8][]byte, error)

SuccessfulReadPreloginRequest is a double for a ReadPreloginRequestFunc that always succeeds.

func SuccessfulWriteError added in v1.5.0

func SuccessfulWriteError(io.ReadWriteCloser, mssql.Error) error

SuccessfulWriteError is a double for a WriteErrorFunc that always succeeds.

func SuccessfulWritePreloginResponse added in v1.5.0

func SuccessfulWritePreloginResponse(io.ReadWriteCloser, map[uint8][]byte) error

SuccessfulWritePreloginResponse is a double for a WritePreloginResponseFunc that always succeeds.

Types

type MSSQLConnectorCtor added in v1.5.0

type MSSQLConnectorCtor struct {
	// Backend connection returned from the call to Connect
	BackendConn net.Conn
	// Error returned from the call to Connect
	Err error
	// PreloginResponse from the server passed to interceptor during Connect
	ServerPreloginResponse map[uint8][]byte
	// Pointer to unload client login request to, taken from interceptor during Connect
	ClientLoginRequestPtr **mssql.LoginRequest
}

MSSQLConnectorCtor is a mock which represents options when creating a mssql.MSSQLConnectorCtor. This makes it possible to customize some key values in a Connect double: func Connect(...) (net.Conn, error)

type NetConn

type NetConn struct {
	net.Conn
	// contains filtered or unexported fields
}

NetConn acts as a double of a true network connection, ie, a net.Conn. TODO: This will need to be upgraded to have more granularity. For example,

to handle cases where sending the authentication OK message works, but
sending an error fails.  Etc.

func NewNetConn

func NewNetConn(errOnWrite error) *NetConn

NewNetConn returns a net.Conn double whose behavior we can control.

func (*NetConn) Write

func (n *NetConn) Write([]byte) (numBytes int, err error)

Write "writes" bytes to our fake net.Conn.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL