testutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities and mocks for cdev tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, s, substr, msg string)

AssertContains checks if a string contains a substring.

func AssertEqual

func AssertEqual(t *testing.T, expected, actual interface{}, msg string)

AssertEqual is a simple equality assertion helper.

func AssertError

func AssertError(t *testing.T, err error, msg string)

AssertError asserts that an error is not nil.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse asserts that a condition is false.

func AssertNil

func AssertNil(t *testing.T, value interface{}, msg string)

AssertNil asserts that a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError asserts that an error is nil.

func AssertNotNil

func AssertNotNil(t *testing.T, value interface{}, msg string)

AssertNotNil asserts that a value is not nil.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue asserts that a condition is true.

Types

type MockEventHub

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

MockEventHub implements ports.EventHub for testing.

func NewMockEventHub

func NewMockEventHub() *MockEventHub

NewMockEventHub creates a new mock event hub.

func (*MockEventHub) IsRunning

func (m *MockEventHub) IsRunning() bool

IsRunning returns true if the hub was started and not stopped.

func (*MockEventHub) Publish

func (m *MockEventHub) Publish(e events.Event)

Publish records the event.

func (*MockEventHub) PublishedEvents

func (m *MockEventHub) PublishedEvents() []events.Event

PublishedEvents returns all published events.

func (*MockEventHub) Start

func (m *MockEventHub) Start() error

Start marks the hub as started.

func (*MockEventHub) Stop

func (m *MockEventHub) Stop() error

Stop marks the hub as stopped.

func (*MockEventHub) Subscribe

func (m *MockEventHub) Subscribe(sub ports.Subscriber)

Subscribe records the subscriber.

func (*MockEventHub) SubscriberCount

func (m *MockEventHub) SubscriberCount() int

SubscriberCount returns the number of subscribers.

func (*MockEventHub) Unsubscribe

func (m *MockEventHub) Unsubscribe(id string)

Unsubscribe removes a subscriber by ID.

type MockSubscriber

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

MockSubscriber implements ports.Subscriber for testing.

func NewMockSubscriber

func NewMockSubscriber(id string) *MockSubscriber

NewMockSubscriber creates a new mock subscriber.

func (*MockSubscriber) ClearEvents

func (m *MockSubscriber) ClearEvents()

ClearEvents removes all recorded events.

func (*MockSubscriber) Close

func (m *MockSubscriber) Close() error

Close marks the subscriber as closed.

func (*MockSubscriber) Done

func (m *MockSubscriber) Done() <-chan struct{}

Done returns a channel that's closed when the subscriber is done.

func (*MockSubscriber) EventCount

func (m *MockSubscriber) EventCount() int

EventCount returns the number of received events.

func (*MockSubscriber) Events

func (m *MockSubscriber) Events() []events.Event

Events returns all received events.

func (*MockSubscriber) ID

func (m *MockSubscriber) ID() string

ID returns the subscriber ID.

func (*MockSubscriber) IsClosed

func (m *MockSubscriber) IsClosed() bool

IsClosed returns whether the subscriber was closed.

func (*MockSubscriber) Send

func (m *MockSubscriber) Send(e events.Event) error

Send records the event and returns any configured error.

func (*MockSubscriber) SetSendError

func (m *MockSubscriber) SetSendError(err error)

SetSendError configures an error to return on Send.

func (*MockSubscriber) SetSendFunc

func (m *MockSubscriber) SetSendFunc(fn func(events.Event) error)

SetSendFunc sets a custom function for Send behavior.

Jump to

Keyboard shortcuts

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