Use a separate cache db when running tests.

This commit is contained in:
mikestefanello 2022-02-06 10:07:25 -05:00
parent a8bd9f8b2d
commit 5def458946
5 changed files with 41 additions and 15 deletions

View file

@ -36,10 +36,17 @@ type (
)
// NewTaskClient creates a new task client
func NewTaskClient(cfg config.CacheConfig) *TaskClient {
func NewTaskClient(cfg *config.Config) *TaskClient {
// Determine the database based on the environment
db := cfg.Cache.Database
if cfg.App.Environment == config.EnvTest {
db = cfg.Cache.TestDatabase
}
conn := asynq.RedisClientOpt{
Addr: fmt.Sprintf("%s:%d", cfg.Hostname, cfg.Port),
Password: cfg.Password,
Addr: fmt.Sprintf("%s:%d", cfg.Cache.Hostname, cfg.Cache.Port),
Password: cfg.Cache.Password,
DB: db,
}
return &TaskClient{