Documentation ¶
Index ¶
- func AssertCartItemSelected(t *testing.T, db *DBHelper, userId uint64, skuId uint64, ...)
- func AssertCartItemsEmpty(t *testing.T, db *DBHelper, userId uint64)
- func AssertCartStatistics(t *testing.T, db *DBHelper, userId uint64, expectedStats struct{ ... })
- func AssertDatabaseState(t *testing.T, db *DBHelper, userId uint64, expectedItems int, ...)
- func AssertMessageContent(t *testing.T, msg *amqp.Delivery, expectedType string, ...)
- func AssertMessageReceived(t *testing.T, rmq RMQAssertions, queueName string, timeout time.Duration) *amqp.Delivery
- func AssertNoMessageReceived(t *testing.T, rmq RMQAssertions, queueName string, timeout time.Duration)
- func LoadFixture(filename string, v interface{}) error
- func SaveFixture(filename string, v interface{}) error
- type DBAssertions
- type DBHelper
- func (h *DBHelper) CleanTestData(ctx context.Context) error
- func (h *DBHelper) ClearUserCart(ctx context.Context, userId uint64) error
- func (h *DBHelper) Close() error
- func (h *DBHelper) GetCartItemsByUserId(ctx context.Context, userId uint64) ([]*model.CartItems, error)
- func (h *DBHelper) GetCartItemsModel() model.CartItemsModel
- func (h *DBHelper) GetCartStatistics(ctx context.Context, userId uint64) (*model.CartStatistics, error)
- func (h *DBHelper) GetCartStatsModel() model.CartStatisticsModel
- func (h *DBHelper) PrepareTestCartItem(ctx context.Context, userId uint64, productId uint64, skuId uint64, ...) (*model.CartItems, error)
- func (h *DBHelper) PrepareTestCartStatistics(ctx context.Context, userId uint64, total, selected int64, ...) error
- type FixtureHelper
- type RMQAssertions
- type RMQHelper
- func (h *RMQHelper) Close() error
- func (h *RMQHelper) ConsumeMessage(queueName string, timeout time.Duration) (*amqp.Delivery, error)
- func (h *RMQHelper) GetChannel() *amqp.Channel
- func (h *RMQHelper) IsConnected() bool
- func (h *RMQHelper) PublishEvent(exchange, routingKey string, event interface{}) error
- func (h *RMQHelper) SetupTestQueues() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCartItemSelected ¶
func AssertCartItemSelected(t *testing.T, db *DBHelper, userId uint64, skuId uint64, expectedSelected int64)
AssertCartItemSelected verifies if specific cart items are selected/unselected
func AssertCartItemsEmpty ¶
AssertCartItemsEmpty verifies that the user's cart is empty
func AssertCartStatistics ¶
func AssertCartStatistics(t *testing.T, db *DBHelper, userId uint64, expectedStats struct { TotalQuantity int64 SelectedQuantity int64 TotalAmount float64 SelectedAmount float64 })
AssertCartStatistics verifies the cart statistics match expected values
func AssertDatabaseState ¶
func AssertDatabaseState(t *testing.T, db *DBHelper, userId uint64, expectedItems int, expectedStats struct { TotalQuantity int64 SelectedQuantity int64 TotalAmount float64 SelectedAmount float64 })
AssertDatabaseState verifies all relevant database states in one call
func AssertMessageContent ¶
func AssertMessageContent(t *testing.T, msg *amqp.Delivery, expectedType string, expectedRoutingKey string)
AssertMessageContent verifies the message content matches expected data
func AssertMessageReceived ¶
func AssertMessageReceived(t *testing.T, rmq RMQAssertions, queueName string, timeout time.Duration) *amqp.Delivery
AssertMessageReceived checks if a message was received on the specified queue
func AssertNoMessageReceived ¶
func AssertNoMessageReceived(t *testing.T, rmq RMQAssertions, queueName string, timeout time.Duration)
AssertNoMessageReceived verifies that no message is received within timeout
func LoadFixture ¶
For backward compatibility
func SaveFixture ¶
Types ¶
type DBAssertions ¶
type DBAssertions interface { GetCartItems(ctx context.Context, userId uint64) (interface{}, error) GetCartStatistics(ctx context.Context, userId uint64) (interface{}, error) }
DBAssertions defines interface for database related assertions
type DBHelper ¶
type DBHelper struct {
// contains filtered or unexported fields
}
func NewDBHelper ¶
func NewDBHelper(mysqlDSN string, redisConf cache.ClusterConf) (*DBHelper, error)
NewDBHelper creates a new database helper with the given configuration
func (*DBHelper) CleanTestData ¶
CleanTestData removes test data from all relevant tables
func (*DBHelper) ClearUserCart ¶
ClearUserCart removes all items from a user's cart
func (*DBHelper) GetCartItemsByUserId ¶
func (h *DBHelper) GetCartItemsByUserId(ctx context.Context, userId uint64) ([]*model.CartItems, error)
GetCartItemsByUserId retrieves all cart items for a user
func (*DBHelper) GetCartItemsModel ¶
func (h *DBHelper) GetCartItemsModel() model.CartItemsModel
GetCartItemsModel returns the cart items model
func (*DBHelper) GetCartStatistics ¶
func (h *DBHelper) GetCartStatistics(ctx context.Context, userId uint64) (*model.CartStatistics, error)
GetCartStatistics retrieves cart statistics for a user
func (*DBHelper) GetCartStatsModel ¶
func (h *DBHelper) GetCartStatsModel() model.CartStatisticsModel
GetCartStatsModel returns the cart statistics model
type FixtureHelper ¶
type FixtureHelper struct {
// contains filtered or unexported fields
}
FixtureHelper handles test fixture operations
func NewFixtureHelper ¶
func NewFixtureHelper() *FixtureHelper
NewFixtureHelper creates a new fixture helper
func (*FixtureHelper) LoadFixture ¶
func (h *FixtureHelper) LoadFixture(filename string, v interface{}) error
LoadFixture loads test data from JSON file
func (*FixtureHelper) LoadFixtureString ¶
func (h *FixtureHelper) LoadFixtureString(filename string) (string, error)
LoadFixtureString loads fixture data as a string
func (*FixtureHelper) SaveFixture ¶
func (h *FixtureHelper) SaveFixture(filename string, v interface{}) error
SaveFixture saves test data to JSON file
func (*FixtureHelper) ValidateFixture ¶
func (h *FixtureHelper) ValidateFixture(filename string) error
ValidateFixture checks if the fixture file exists and contains valid JSON
type RMQAssertions ¶
type RMQAssertions interface {
ConsumeMessage(queueName string, timeout time.Duration) (*amqp.Delivery, error)
}
RMQAssertions defines interface for RabbitMQ related assertions
type RMQHelper ¶
type RMQHelper struct {
// contains filtered or unexported fields
}
func NewRMQHelper ¶
func NewRMQHelper(config *rmqconfig.RabbitMQConfig) (*RMQHelper, error)
NewRMQHelper creates a new RMQ helper with given configuration
func (*RMQHelper) ConsumeMessage ¶
func (*RMQHelper) GetChannel ¶
GetChannel returns the underlying AMQP channel
func (*RMQHelper) IsConnected ¶
IsConnected checks if the broker connection is still alive
func (*RMQHelper) PublishEvent ¶
PublishEvent publishes an event message to the specified exchange
func (*RMQHelper) SetupTestQueues ¶
SetupTestQueues declares required exchanges and queues for testing