Documentation
¶
Index ¶
- Constants
- func AssertAggregateID(t *testing.T, evt event.DomainEvent, expectedID string)
- func AssertEventCount(t *testing.T, events []event.DomainEvent, expected int)
- func AssertEventPublished(t *testing.T, events []event.DomainEvent, eventType string) event.DomainEvent
- func AssertEventType(t *testing.T, evt event.DomainEvent, expectedType string)
- func AssertNoError(t *testing.T, err error, msgAndArgs ...any)
- func AssertNotZeroUUID(t *testing.T, id uuid.UUID, msgAndArgs ...any)
- func AssertTimeAfter(t *testing.T, actual, expected time.Time, msgAndArgs ...any)
- func AssertTimeApproximatelyEqual(t *testing.T, expected, actual time.Time, delta time.Duration, ...)
- func AssertTimeBefore(t *testing.T, actual, expected time.Time, msgAndArgs ...any)
- func AssertTimeNotZero(t *testing.T, tm time.Time, msgAndArgs ...any)
- func AssertUUIDEqual(t *testing.T, expected, actual uuid.UUID, msgAndArgs ...any)
- func AssertVersion(t *testing.T, evt event.DomainEvent, expectedVersion int)
- func AssertZeroUUID(t *testing.T, id uuid.UUID, msgAndArgs ...any)
- func CleanupSharedContainer()
- func CleanupSharedKeycloakContainer()
- func CleanupSharedRedisContainer()
- func NewTestContext(t *testing.T) context.Context
- func RequireNotZeroUUID(t *testing.T, id uuid.UUID, msgAndArgs ...any)
- func RequireTimeApproximatelyEqual(t *testing.T, expected, actual time.Time, delta time.Duration, ...)
- func RequireTimeNotZero(t *testing.T, tm time.Time, msgAndArgs ...any)
- func RequireUUIDEqual(t *testing.T, expected, actual uuid.UUID, msgAndArgs ...any)
- func RequireZeroUUID(t *testing.T, id uuid.UUID, msgAndArgs ...any)
- func SetupSharedTestMongoDB(t *testing.T) *mongo.Database
- func SetupSharedTestMongoDBWithClient(t *testing.T) (*mongo.Client, *mongo.Database)
- func SetupSharedTestMongoDBWithClientOptions(t *testing.T, createIndexes bool) (*mongo.Client, *mongo.Database)
- func SetupSharedTestMongoDBWithOptions(t *testing.T, createIndexes bool) *mongo.Database
- func SetupTestMongoDB(t *testing.T) *mongo.Database
- func SetupTestMongoDBIsolated(t *testing.T) *mongo.Database
- func SetupTestMongoDBWithClient(t *testing.T) (*mongo.Client, *mongo.Database)
- func SetupTestMongoDBWithClientIsolated(t *testing.T) (*mongo.Client, *mongo.Database)
- func SetupTestRedis(t *testing.T) *redis.Client
- func SetupTestRedisIsolated(t *testing.T) *redis.Client
- func SetupTestRedisWithPrefix(t *testing.T) (*redis.Client, string)
- type KeycloakTokenResponse
- type KeycloakUserInfo
- type MongoContainer
- type SharedKeycloakContainer
- func (c *SharedKeycloakContainer) ClientExists(ctx context.Context) (bool, error)
- func (c *SharedKeycloakContainer) GetAdminToken(ctx context.Context) (string, error)
- func (c *SharedKeycloakContainer) GetGroups(ctx context.Context) ([]string, error)
- func (c *SharedKeycloakContainer) GetRealmRoles(ctx context.Context) ([]string, error)
- func (c *SharedKeycloakContainer) GetUserInfo(ctx context.Context, accessToken string) (*KeycloakUserInfo, error)
- func (c *SharedKeycloakContainer) GetUserToken(ctx context.Context, username, password string) (*KeycloakTokenResponse, error)
- func (c *SharedKeycloakContainer) GetUsers(ctx context.Context) ([]string, error)
- func (c *SharedKeycloakContainer) RealmExists(ctx context.Context) (bool, error)
- type SharedMongoContainer
- type SharedRedisContainer
- type TestSuite
Constants ¶
const ( KeycloakTestUserPassword = "test123" KeycloakAdminTestPassword = keycloakAdminPassword )
Exported test credentials used by integration/e2e tests.
Variables ¶
This section is empty.
Functions ¶
func AssertAggregateID ¶
func AssertAggregateID(t *testing.T, evt event.DomainEvent, expectedID string)
AssertAggregateID checks aggregate ID in the event
func AssertEventCount ¶
func AssertEventCount(t *testing.T, events []event.DomainEvent, expected int)
AssertEventCount checks count of published events
func AssertEventPublished ¶
func AssertEventPublished(t *testing.T, events []event.DomainEvent, eventType string) event.DomainEvent
AssertEventPublished checks that event of specific type was published
func AssertEventType ¶
func AssertEventType(t *testing.T, evt event.DomainEvent, expectedType string)
AssertEventType checks event type
func AssertNoError ¶
AssertNoError checks absence of error and stops test
func AssertNotZeroUUID ¶
AssertNotZeroUUID checks, that UUID not empty
func AssertTimeAfter ¶
AssertTimeAfter checks, that actual time after expected
func AssertTimeApproximatelyEqual ¶
func AssertTimeApproximatelyEqual(t *testing.T, expected, actual time.Time, delta time.Duration, msgAndArgs ...any)
AssertTimeApproximatelyEqual checks, that two time approximately equal with acceptable tolerance delta (usually time.Second or time.Millisecond)
func AssertTimeBefore ¶
AssertTimeBefore checks, that actual time before expected
func AssertTimeNotZero ¶
AssertTimeNotZero checks, that time not nil
func AssertUUIDEqual ¶
AssertUUIDEqual checks equality of two UUIDs
func AssertVersion ¶
func AssertVersion(t *testing.T, evt event.DomainEvent, expectedVersion int)
AssertVersion checks aggregate version in the event
func AssertZeroUUID ¶
AssertZeroUUID checks, that UUID empty
func CleanupSharedContainer ¶
func CleanupSharedContainer()
CleanupSharedContainer terminates the shared container. This is typically called from TestMain or when all tests are done.
func CleanupSharedKeycloakContainer ¶
func CleanupSharedKeycloakContainer()
CleanupSharedKeycloakContainer terminates the shared container. This is typically called from TestMain or when all tests are done.
func CleanupSharedRedisContainer ¶
func CleanupSharedRedisContainer()
CleanupSharedRedisContainer terminates the shared container. This is typically called from TestMain or when all tests are done.
func NewTestContext ¶
NewTestContext creates context with timeout for tests
func RequireNotZeroUUID ¶
RequireNotZeroUUID checks, that UUID not empty and stops test at error
func RequireTimeApproximatelyEqual ¶
func RequireTimeApproximatelyEqual(t *testing.T, expected, actual time.Time, delta time.Duration, msgAndArgs ...any)
RequireTimeApproximatelyEqual checks, that two time approximately equal and stops test at error
func RequireTimeNotZero ¶
RequireTimeNotZero checks, that time not nil and stops test at error
func RequireUUIDEqual ¶
RequireUUIDEqual checks equality of two UUIDs and stops test at error
func RequireZeroUUID ¶
RequireZeroUUID checks, that UUID empty and stops test at error
func SetupSharedTestMongoDB ¶
SetupSharedTestMongoDB creates a test database using the shared MongoDB container. Each test gets its own isolated database within the shared container. This is much faster than starting a new container for each test. Note: Index creation is disabled by default to prevent MongoDB container crashes. Use SetupSharedTestMongoDBWithOptions(t, true) if you need indexes.
func SetupSharedTestMongoDBWithClient ¶
SetupSharedTestMongoDBWithClient creates a test database and returns both client and database. Uses the shared MongoDB container for faster test execution. Note: Index creation is disabled by default to prevent MongoDB container crashes. Use SetupSharedTestMongoDBWithClientOptions(t, true) if you need indexes.
func SetupSharedTestMongoDBWithClientOptions ¶
func SetupSharedTestMongoDBWithClientOptions(t *testing.T, createIndexes bool) (*mongo.Client, *mongo.Database)
SetupSharedTestMongoDBWithClientOptions creates a test database with optional index creation.
func SetupSharedTestMongoDBWithOptions ¶
SetupSharedTestMongoDBWithOptions creates a test database with optional index creation. Use createIndexes=false for tests that don't need indexes for faster execution.
func SetupTestMongoDB ¶
SetupTestMongoDB creates connection to test MongoDB using shared container. each test receives its own isolated database for safe parallel execution.
func SetupTestMongoDBIsolated ¶
SetupTestMongoDBIsolated creates new container MongoDB for full isolation. Use this function only when needed full isolation of container. in most cases SetupTestMongoDB is sufficient (isolation at the database).
func SetupTestMongoDBWithClient ¶
SetupTestMongoDBWithClient creates connection to test MongoDB and returns client and database. uses shared container for faster tests.
func SetupTestMongoDBWithClientIsolated ¶
SetupTestMongoDBWithClientIsolated creates new container and returns client and database. Use only when needed full isolation of container.
func SetupTestRedis ¶
SetupTestRedis creates a Redis client using the shared container. This is the recommended way to get a Redis client for tests.
func SetupTestRedisIsolated ¶
SetupTestRedisIsolated creates a new Redis container for complete isolation. Use this only when you need a completely clean Redis instance.
Types ¶
type KeycloakTokenResponse ¶
type KeycloakTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
RefreshExpiresIn int `json:"refresh_expires_in"`
TokenType string `json:"token_type"`
IDToken string `json:"id_token,omitempty"`
Scope string `json:"scope,omitempty"`
}
KeycloakTokenResponse represents the token response from Keycloak
type KeycloakUserInfo ¶
type KeycloakUserInfo struct {
Sub string `json:"sub"`
PreferredUsername string `json:"preferred_username"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Name string `json:"name"`
GivenName string `json:"given_name,omitempty"`
FamilyName string `json:"family_name,omitempty"`
Groups []string `json:"groups,omitempty"`
RealmAccess struct {
Roles []string `json:"roles"`
} `json:"realm_access"`
}
KeycloakUserInfo represents user info from Keycloak
type MongoContainer ¶
type MongoContainer struct {
Container testcontainers.Container
URI string
}
MongoContainer represents MongoDB container for tests
type SharedKeycloakContainer ¶
type SharedKeycloakContainer struct {
}
SharedKeycloakContainer represents a reusable Keycloak container for tests
func GetSharedKeycloakContainer ¶
func GetSharedKeycloakContainer(ctx context.Context) (*SharedKeycloakContainer, error)
GetSharedKeycloakContainer returns a singleton Keycloak container. The container is started once and reused across all tests.
func SetupTestKeycloak ¶
func SetupTestKeycloak(t *testing.T) *SharedKeycloakContainer
SetupTestKeycloak creates a Keycloak container using the shared container. This is the recommended way to get a Keycloak container for tests.
func SetupTestKeycloakIsolated ¶
func SetupTestKeycloakIsolated(t *testing.T) *SharedKeycloakContainer
SetupTestKeycloakIsolated creates a new Keycloak container for complete isolation. Use this only when you need a completely clean Keycloak instance.
func (*SharedKeycloakContainer) ClientExists ¶
func (c *SharedKeycloakContainer) ClientExists(ctx context.Context) (bool, error)
ClientExists checks if the OAuth2 client exists
func (*SharedKeycloakContainer) GetAdminToken ¶
func (c *SharedKeycloakContainer) GetAdminToken(ctx context.Context) (string, error)
GetAdminToken obtains an admin access token
func (*SharedKeycloakContainer) GetGroups ¶
func (c *SharedKeycloakContainer) GetGroups(ctx context.Context) ([]string, error)
GetGroups retrieves all groups
func (*SharedKeycloakContainer) GetRealmRoles ¶
func (c *SharedKeycloakContainer) GetRealmRoles(ctx context.Context) ([]string, error)
GetRealmRoles retrieves all realm roles
func (*SharedKeycloakContainer) GetUserInfo ¶
func (c *SharedKeycloakContainer) GetUserInfo(ctx context.Context, accessToken string) (*KeycloakUserInfo, error)
GetUserInfo retrieves user info using an access token
func (*SharedKeycloakContainer) GetUserToken ¶
func (c *SharedKeycloakContainer) GetUserToken( ctx context.Context, username, password string, ) (*KeycloakTokenResponse, error)
GetUserToken obtains an access token for a test user using direct access grants.
func (*SharedKeycloakContainer) GetUsers ¶
func (c *SharedKeycloakContainer) GetUsers(ctx context.Context) ([]string, error)
GetUsers retrieves all users in the realm
func (*SharedKeycloakContainer) RealmExists ¶
func (c *SharedKeycloakContainer) RealmExists(ctx context.Context) (bool, error)
RealmExists checks if the realm exists
type SharedMongoContainer ¶
type SharedMongoContainer struct {
// contains filtered or unexported fields
}
SharedMongoContainer represents a reusable MongoDB container for tests
func GetSharedMongoContainer ¶
func GetSharedMongoContainer(ctx context.Context) (*SharedMongoContainer, error)
GetSharedMongoContainer returns a singleton MongoDB container. The container is started once and reused across all tests. It will be terminated when the test binary exits. If the container has crashed, it will be automatically recreated.
type SharedRedisContainer ¶
type SharedRedisContainer struct {
// contains filtered or unexported fields
}
SharedRedisContainer represents a reusable Redis container for tests
func GetSharedRedisContainer ¶
func GetSharedRedisContainer(ctx context.Context) (*SharedRedisContainer, error)
GetSharedRedisContainer returns a singleton Redis container. The container is started once and reused across all tests.
type TestSuite ¶
type TestSuite struct {
// Mocks
ChatRepo *mocks.MockChatRepository
MessageRepo *mocks.MockMessageRepository
UserRepo *mocks.MockUserRepository
WorkspaceRepo *mocks.MockWorkspaceRepository
NotificationRepo *mocks.MockNotificationRepository
EventBus *mocks.MockEventBus
EventStore *mocks.MockEventStore
// Use Cases - Chat
CreateChat *chatapp.CreateChatUseCase
AddParticipant *chatapp.AddParticipantUseCase
ConvertToTask *chatapp.ConvertToTaskUseCase
ChangeStatus *chatapp.ChangeStatusUseCase
AssignUser *chatapp.AssignUserUseCase
// contains filtered or unexported fields
}
TestSuite represents full set for integration testing
func NewTestSuite ¶
NewTestSuite creates New test suite with all initialized components