mocks

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockTransport

type MockTransport struct {
	// contains filtered or unexported fields
}

MockTransport is a mock HTTP RoundTripper that records requests and returns fixture-based responses

func NewMockTransport

func NewMockTransport(fixtureDir string) *MockTransport

NewMockTransport creates a new MockTransport

func (*MockTransport) ClearRequests

func (m *MockTransport) ClearRequests()

ClearRequests clears the request history

func (*MockTransport) FindRequest

func (m *MockTransport) FindRequest(method, pathContains string) *RequestRecord

FindRequest finds a request matching the criteria

func (*MockTransport) GetRequestCount

func (m *MockTransport) GetRequestCount() int

GetRequestCount returns the number of recorded requests

func (*MockTransport) GetRequests

func (m *MockTransport) GetRequests() []*RequestRecord

GetRequests returns all recorded requests

func (*MockTransport) RoundTrip

func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

func (*MockTransport) SetDefaultResponse

func (m *MockTransport) SetDefaultResponse(response *http.Response)

SetDefaultResponse sets a default response for unmatched requests

func (*MockTransport) SetResponse

func (m *MockTransport) SetResponse(method, path string, response *http.Response)

SetResponse sets a specific response for a request pattern

func (*MockTransport) SetResponseWithBody

func (m *MockTransport) SetResponseWithBody(method, path string, statusCode int, body interface{})

SetResponseWithBody sets a response with JSON body

type MockWebSocketConn

type MockWebSocketConn struct {
	// contains filtered or unexported fields
}

MockWebSocketConn is a mock WebSocket connection for testing

func NewMockWebSocketConn

func NewMockWebSocketConn() *MockWebSocketConn

NewMockWebSocketConn creates a new mock WebSocket connection

func (*MockWebSocketConn) ClearWrittenMessages

func (m *MockWebSocketConn) ClearWrittenMessages()

ClearWrittenMessages clears the written messages history

func (*MockWebSocketConn) Close

func (m *MockWebSocketConn) Close() error

Close closes the connection

func (*MockWebSocketConn) GetWrittenMessages

func (m *MockWebSocketConn) GetWrittenMessages() [][]byte

GetWrittenMessages returns all messages written to the connection

func (*MockWebSocketConn) IsClosed

func (m *MockWebSocketConn) IsClosed() bool

IsClosed returns whether the connection is closed

func (*MockWebSocketConn) QueueJSONMessage

func (m *MockWebSocketConn) QueueJSONMessage(v interface{}) error

QueueJSONMessage queues a JSON message to be read

func (*MockWebSocketConn) QueueMessage

func (m *MockWebSocketConn) QueueMessage(message []byte)

QueueMessage queues a message to be read

func (*MockWebSocketConn) ReadMessage

func (m *MockWebSocketConn) ReadMessage() (messageType int, message []byte, err error)

ReadMessage reads a message from the connection

func (*MockWebSocketConn) SendError

func (m *MockWebSocketConn) SendError(err error)

SendError sends an error through the error channel

func (*MockWebSocketConn) SendMessage

func (m *MockWebSocketConn) SendMessage(message []byte)

SendMessage sends a message through the message channel

func (*MockWebSocketConn) SetCloseError

func (m *MockWebSocketConn) SetCloseError(err error)

SetCloseError sets an error to return on Close

func (*MockWebSocketConn) SetReadError

func (m *MockWebSocketConn) SetReadError(err error)

SetReadError sets an error to return on ReadMessage

func (*MockWebSocketConn) SetWriteError

func (m *MockWebSocketConn) SetWriteError(err error)

SetWriteError sets an error to return on WriteMessage

func (*MockWebSocketConn) WriteMessage

func (m *MockWebSocketConn) WriteMessage(messageType int, data []byte) error

WriteMessage writes a message to the connection

type MockWebSocketDialer

type MockWebSocketDialer struct {
	// contains filtered or unexported fields
}

MockWebSocketDialer is a mock WebSocket dialer for testing

func NewMockWebSocketDialer

func NewMockWebSocketDialer() *MockWebSocketDialer

NewMockWebSocketDialer creates a new mock WebSocket dialer

func (*MockWebSocketDialer) DialContext

func (m *MockWebSocketDialer) DialContext(ctx context.Context, urlStr string, requestHeader map[string][]string) (*MockWebSocketConn, error)

DialContext mocks the WebSocket dial operation

func (*MockWebSocketDialer) GetConnection

func (m *MockWebSocketDialer) GetConnection(urlStr string) *MockWebSocketConn

GetConnection returns the connection for a URL

func (*MockWebSocketDialer) SetConnection

func (m *MockWebSocketDialer) SetConnection(urlStr string, conn *MockWebSocketConn)

SetConnection sets a connection for a specific URL

func (*MockWebSocketDialer) SetDefaultConnection

func (m *MockWebSocketDialer) SetDefaultConnection(conn *MockWebSocketConn)

SetDefaultConnection sets a default connection to use

type RequestRecord

type RequestRecord struct {
	Method      string
	URL         string
	Headers     http.Header
	Body        []byte
	BodyString  string
	QueryParams map[string]string
}

RequestRecord represents a recorded HTTP request

Jump to

Keyboard shortcuts

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