testutil package - github.com/VTGare/Eugen/testutil - Go Packages

testutil

package
v0.0.0-...-affb030 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIPath

func APIPath(rawURL string) string

APIPath extracts the Discord API path portion from a full URL. For example, "https://discord.com/api/v9/channels/123" -> "/channels/123"

Types

type Handler

type Handler func(req *http.Request) (body []byte, statusCode int)

func JSON

func JSON(val any, status int) Handler

type MockSession

type MockSession struct {
	Session *discordgo.Session
	// contains filtered or unexported fields
}

func NewSession

func NewSession(t TestReporter) *MockSession

NewSession creates a MockSession with a pre-configured discordgo.Session. The session's State is initialized from NewState() and must be populated by the caller using the Bot helper methods (GuildAdd, MemberAdd, etc.) or by calling WithGuild/WithMember.

The session's HTTP client is wired to an httptest.Server whose behavior is controlled by the Handlers map.

func (*MockSession) Close

func (ms *MockSession) Close()

func (*MockSession) On

func (ms *MockSession) On(pathPrefix string, handler Handler)

func (*MockSession) WithBotUser

func (ms *MockSession) WithBotUser(userID, username string) *MockSession

func (*MockSession) WithChannel

func (ms *MockSession) WithChannel(ch *discordgo.Channel) *MockSession

func (*MockSession) WithGuild

func (ms *MockSession) WithGuild(guild *discordgo.Guild) *MockSession

func (*MockSession) WithMember

func (ms *MockSession) WithMember(guildID string, member *discordgo.Member) *MockSession

type MongoContainer

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

MongoContainer wraps a running MongoDB testcontainers instance and the connection URI needed to build *store.Store instances.

func StartMongoDB

func StartMongoDB(t TBF) *MongoContainer

StartMongoDB starts a MongoDB container using testcontainers-go. The container is terminated when Cleanup is called. This is intended to be called once per test suite, typically in a Ginkgo BeforeSuite block.

func (*MongoContainer) Cleanup

func (m *MongoContainer) Cleanup()

Cleanup terminates the MongoDB container. Call this via DeferCleanup in a Ginkgo AfterSuite.

func (*MongoContainer) NewTestStore

func (m *MongoContainer) NewTestStore(t TBF) *store.Store

NewTestStore creates a *store.Store connected to the given MongoDB container. Each call creates a uniquely-named database (test_eugen_<n>) to provide isolation between tests within the same suite.

type TBF

type TBF interface {
	Helper()
	Fatalf(format string, args ...any)
}

TBF is the minimal subset of testing.TB / ginkgo.FullGinkgoTInterface that the test helpers need.

type TestReporter

type TestReporter interface {
	Helper()
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)
}

Jump to

Keyboard shortcuts

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