cleanup and refactors
This commit is contained in:
@@ -10,7 +10,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
TestTimeout = 2 * time.Second
|
||||
@@ -18,7 +20,9 @@ const (
|
||||
NegativeTestTimeout = 100 * time.Millisecond
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type MockIncomingData struct {
|
||||
MsgType int
|
||||
@@ -37,7 +41,9 @@ type ExpectedLog struct {
|
||||
Attrs map[string]any
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Setup
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
func SetupTestSocket(t *testing.T) (
|
||||
socket *MockSocket,
|
||||
@@ -81,7 +87,9 @@ func SetupTestSocket(t *testing.T) (
|
||||
return
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
func ExpectIncoming(t *testing.T, incoming <-chan []byte, expected []byte) {
|
||||
t.Helper()
|
||||
@@ -126,7 +134,9 @@ func Never(t *testing.T, condition func() bool, msg string) {
|
||||
assert.Never(t, condition, NegativeTestTimeout, TestTick, msg)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Logging Helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
func AssertLogSequence(t *testing.T, records []slog.Record, expected []ExpectedLog) {
|
||||
t.Helper()
|
||||
|
||||
@@ -9,12 +9,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Re-exported types for consumer convenience
|
||||
// ----------------------------------------------------------------------------
|
||||
// Re-exports
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type Socket = types.Socket
|
||||
type Dialer = types.Dialer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Dialer Mocks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type MockDialer struct {
|
||||
DialContextFunc func(
|
||||
@@ -28,7 +32,9 @@ func (m *MockDialer) DialContext(
|
||||
return m.DialContextFunc(ctx, url, h)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Socket Mocks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type MockSocket struct {
|
||||
WriteMessageFunc func(int, []byte) error
|
||||
@@ -93,7 +99,9 @@ func (m *MockSocket) SetPongHandler(h func(s string) error) {
|
||||
m.SetPongHandlerFunc(h)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Logging mocks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
type MockSlogHandler struct {
|
||||
records *[]slog.Record
|
||||
|
||||
Reference in New Issue
Block a user