helpers

package
v0.0.0-...-3414fa2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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

func AssertCartItemsEmpty(t *testing.T, db *DBHelper, userId uint64)

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

func LoadFixture(filename string, v interface{}) error

For backward compatibility

func SaveFixture

func SaveFixture(filename string, v interface{}) error

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

func (h *DBHelper) CleanTestData(ctx context.Context) error

CleanTestData removes test data from all relevant tables

func (*DBHelper) ClearUserCart

func (h *DBHelper) ClearUserCart(ctx context.Context, userId uint64) error

ClearUserCart removes all items from a user's cart

func (*DBHelper) Close

func (h *DBHelper) Close() error

Close closes the database connections

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

func (*DBHelper) PrepareTestCartItem

func (h *DBHelper) PrepareTestCartItem(ctx context.Context, userId uint64, productId uint64, skuId uint64, quantity int64) (*model.CartItems, error)

PrepareTestCartItem creates a test cart item

func (*DBHelper) PrepareTestCartStatistics

func (h *DBHelper) PrepareTestCartStatistics(ctx context.Context, userId uint64, total, selected int64, totalAmount, selectedAmount float64) error

PrepareTestCartStatistics creates or updates test cart statistics

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) Close

func (h *RMQHelper) Close() error

Close closes the RabbitMQ connection and channel

func (*RMQHelper) ConsumeMessage

func (h *RMQHelper) ConsumeMessage(queueName string, timeout time.Duration) (*amqp.Delivery, error)

func (*RMQHelper) GetChannel

func (h *RMQHelper) GetChannel() *amqp.Channel

GetChannel returns the underlying AMQP channel

func (*RMQHelper) IsConnected

func (h *RMQHelper) IsConnected() bool

IsConnected checks if the broker connection is still alive

func (*RMQHelper) PublishEvent

func (h *RMQHelper) PublishEvent(exchange, routingKey string, event interface{}) error

PublishEvent publishes an event message to the specified exchange

func (*RMQHelper) SetupTestQueues

func (h *RMQHelper) SetupTestQueues() error

SetupTestQueues declares required exchanges and queues for testing

Jump to

Keyboard shortcuts

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