test

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorEventResultId = "$ERROR"
View Source
const KeywordIntentionalFail = "MX_INTENTIONAL_FAIL"

KeywordIntentionalFail - Used by tests to always cause a 500 Internal Server Error response.

View Source
const KeywordNeutral = "MX_NEUTRAL"

KeywordNeutral - Used by tests to always flag a message as neutral ("not spammy").

View Source
const KeywordSpammy = "MX_SPAMMY"

KeywordSpammy - Used by tests to always flag a message as generic spam.

View Source
const KeywordSpammyCSAM = "MX_SPAMMY_CSAM"

KeywordSpammyCSAM - Used by tests to always flag a message as "containing CSAM".

Variables

View Source
var SimulatedError = errors.New("simulated error")

Functions

func AssertApiError added in v1.1.0

func AssertApiError(t *testing.T, w *httptest.ResponseRecorder, errcode string, error string)

func AssertJsonBody added in v1.1.0

func AssertJsonBody(t *testing.T, w *httptest.ResponseRecorder, expected any)

func MakeJsonBody added in v1.1.0

func MakeJsonBody(t *testing.T, body any) io.Reader

func MakeOpenAIModerationServer added in v1.1.0

func MakeOpenAIModerationServer(t *testing.T, apiKey string) *httptest.Server

MakeOpenAIModerationServer - Creates a mock OpenAI Moderation API server for use in tests.

func MustMakeAuditQueue

func MustMakeAuditQueue(size int) *audit.Queue

func MustMakeKeywordEvent added in v1.1.0

func MustMakeKeywordEvent(keyword string) gomatrixserverlib.PDU

MustMakeKeywordEvent - Creates a consistent event using the specified keyword

func MustMakePDU

func MustMakePDU(event *BaseClientEvent) gomatrixserverlib.PDU

Types

type BaseClientEvent

type BaseClientEvent struct {
	RoomId      string                       `json:"room_id"`
	EventId     string                       `json:"event_id"`
	Type        string                       `json:"type"`
	StateKey    *string                      `json:"state_key"`
	Sender      string                       `json:"sender"`
	Content     map[string]any               `json:"content"`
	StickyUntil time.Time                    `json:"-"` // exclude from JSON to avoid making the event improper/too large
	Signatures  map[string]map[string]string `json:"signatures,omitempty"`
}

type MemoryContentScanner

type MemoryContentScanner struct {
	T *testing.T
	// contains filtered or unexported fields
}

func NewMemoryContentScanner

func NewMemoryContentScanner(t *testing.T) *MemoryContentScanner

func (*MemoryContentScanner) Expect

func (m *MemoryContentScanner) Expect(contentType content.Type, content []byte, retClassifications []classification.Classification, retErr error)

func (*MemoryContentScanner) Scan

func (m *MemoryContentScanner) Scan(ctx context.Context, contentType content.Type, content []byte) ([]classification.Classification, error)

type MemoryPubsub

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

func NewMemoryPubsub

func NewMemoryPubsub(t *testing.T) *MemoryPubsub

func (*MemoryPubsub) Close

func (m *MemoryPubsub) Close() error

func (*MemoryPubsub) Publish

func (m *MemoryPubsub) Publish(ctx context.Context, topic string, val string) error

func (*MemoryPubsub) Subscribe

func (m *MemoryPubsub) Subscribe(ctx context.Context, topic string) (<-chan string, error)

func (*MemoryPubsub) Unsubscribe

func (m *MemoryPubsub) Unsubscribe(ctx context.Context, ch <-chan string) error

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage(t *testing.T) *MemoryStorage

func (*MemoryStorage) Close

func (m *MemoryStorage) Close() error

func (*MemoryStorage) CreateCommunity

func (m *MemoryStorage) CreateCommunity(ctx context.Context, name string) (*storage.StoredCommunity, error)

func (*MemoryStorage) DeleteRoom

func (m *MemoryStorage) DeleteRoom(ctx context.Context, roomId string) error

func (*MemoryStorage) GetAllRooms

func (m *MemoryStorage) GetAllRooms(ctx context.Context) ([]*storage.StoredRoom, error)

func (*MemoryStorage) GetCommunity

func (m *MemoryStorage) GetCommunity(ctx context.Context, communityId string) (*storage.StoredCommunity, error)

func (*MemoryStorage) GetCommunityByAccessToken added in v1.2.0

func (m *MemoryStorage) GetCommunityByAccessToken(ctx context.Context, accessToken string) (*storage.StoredCommunity, error)

func (*MemoryStorage) GetEventResult

func (m *MemoryStorage) GetEventResult(ctx context.Context, eventId string) (*storage.StoredEventResult, error)

func (*MemoryStorage) GetKeywordTemplate added in v1.1.0

func (m *MemoryStorage) GetKeywordTemplate(ctx context.Context, name string) (*storage.StoredKeywordTemplate, error)

func (*MemoryStorage) GetRoom

func (m *MemoryStorage) GetRoom(ctx context.Context, roomId string) (*storage.StoredRoom, error)

func (*MemoryStorage) GetTrustData

func (m *MemoryStorage) GetTrustData(ctx context.Context, sourceName string, key string, result any) error

func (*MemoryStorage) GetUserIdsAndDisplayNamesByRoomId

func (m *MemoryStorage) GetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string) ([]string, []string, error)

func (*MemoryStorage) IsUserBannedInList

func (m *MemoryStorage) IsUserBannedInList(ctx context.Context, listRoomId string, userId string) (bool, error)

func (*MemoryStorage) PopStateLearnQueue

func (*MemoryStorage) PushStateLearnQueue

func (m *MemoryStorage) PushStateLearnQueue(ctx context.Context, item *storage.StateLearnQueueItem) error

func (*MemoryStorage) SetListBanRules

func (m *MemoryStorage) SetListBanRules(ctx context.Context, listRoomId string, entityToEntityType map[string]string) error

func (*MemoryStorage) SetTrustData

func (m *MemoryStorage) SetTrustData(ctx context.Context, sourceName string, key string, data any) error

func (*MemoryStorage) SetUserIdsAndDisplayNamesByRoomId

func (m *MemoryStorage) SetUserIdsAndDisplayNamesByRoomId(ctx context.Context, roomId string, userIds []string, displayNames []string) error

func (*MemoryStorage) UpsertCommunity

func (m *MemoryStorage) UpsertCommunity(ctx context.Context, community *storage.StoredCommunity) error

func (*MemoryStorage) UpsertEventResult

func (m *MemoryStorage) UpsertEventResult(ctx context.Context, event *storage.StoredEventResult) error

func (*MemoryStorage) UpsertKeywordTemplate added in v1.1.0

func (m *MemoryStorage) UpsertKeywordTemplate(ctx context.Context, template *storage.StoredKeywordTemplate) error

func (*MemoryStorage) UpsertRoom

func (m *MemoryStorage) UpsertRoom(ctx context.Context, room *storage.StoredRoom) error

type MemoryTransaction

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

func (*MemoryTransaction) Commit

func (t *MemoryTransaction) Commit() error

func (*MemoryTransaction) Rollback

func (t *MemoryTransaction) Rollback() error

type StaticMediaDownloader

type StaticMediaDownloader struct {
	T             *testing.T
	Media         map[string][]byte
	DownloadCalls int
}

func MustMakeMediaDownloader

func MustMakeMediaDownloader(t *testing.T) *StaticMediaDownloader

func (*StaticMediaDownloader) DownloadMedia

func (s *StaticMediaDownloader) DownloadMedia(ctx context.Context, origin string, mediaId string) ([]byte, error)

func (*StaticMediaDownloader) Set

func (s *StaticMediaDownloader) Set(origin string, mediaId string, bytes []byte) *StaticMediaDownloader

Jump to

Keyboard shortcuts

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