added interface for tests IProducer
This commit is contained in:
parent
be6a01d2c7
commit
e87f39e553
0
.gitea/workflows/deployTests.yml
Normal file
0
.gitea/workflows/deployTests.yml
Normal file
@ -17,6 +17,7 @@ import (
|
||||
"gitea.pena/SQuiz/core/pkg/closer"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/twmb/franz-go/pkg/kgo"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"time"
|
||||
@ -70,15 +71,16 @@ func Run(ctx context.Context, cfg initialize.Config, build Build) error {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
loggerForHlog := zapLogger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(core, clickHouseLogger)
|
||||
}))
|
||||
|
||||
var loggerForHlog *zap.Logger
|
||||
if cfg.IsTest {
|
||||
loggerForHlog = zapLogger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(core)
|
||||
}))
|
||||
} else {
|
||||
loggerForHlog = zapLogger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(core, clickHouseLogger)
|
||||
}))
|
||||
}
|
||||
|
||||
loggerHlog := hlog.New(loggerForHlog).Module(initialize.ModuleLogger)
|
||||
@ -93,20 +95,28 @@ func Run(ctx context.Context, cfg initialize.Config, build Build) error {
|
||||
return err
|
||||
}
|
||||
|
||||
kafkaClient, err := initialize.KafkaInit(ctx, initialize.KafkaDeps{
|
||||
KafkaGroup: cfg.KafkaGroup,
|
||||
KafkaBrokers: cfg.KafkaBrokers,
|
||||
KafkaTopic: cfg.KafkaTopicNotifyer,
|
||||
})
|
||||
if err != nil {
|
||||
zapLogger.Error("Error initializing kafka", zap.Error(err))
|
||||
return err
|
||||
var kafkaClient *kgo.Client
|
||||
if !cfg.IsTest {
|
||||
kafkaClient, err = initialize.KafkaInit(ctx, initialize.KafkaDeps{
|
||||
KafkaGroup: cfg.KafkaGroup,
|
||||
KafkaBrokers: cfg.KafkaBrokers,
|
||||
KafkaTopic: cfg.KafkaTopicNotifyer,
|
||||
})
|
||||
if err != nil {
|
||||
zapLogger.Error("Error initializing kafka", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
producer := brokers.NewProducer(brokers.ProducerDeps{
|
||||
KafkaClient: kafkaClient,
|
||||
Logger: zapLogger,
|
||||
})
|
||||
var producer brokers.IProducer
|
||||
if !cfg.IsTest {
|
||||
producer = brokers.NewProducer(brokers.ProducerDeps{
|
||||
KafkaClient: kafkaClient,
|
||||
Logger: zapLogger,
|
||||
})
|
||||
} else {
|
||||
producer = &brokers.MockProducer{}
|
||||
}
|
||||
|
||||
redisClient, err := initialize.Redis(ctx, cfg)
|
||||
if err != nil {
|
||||
|
@ -8,6 +8,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type IProducer interface {
|
||||
ToMailNotify(ctx context.Context, message Message) error
|
||||
}
|
||||
|
||||
type ProducerDeps struct {
|
||||
KafkaClient *kgo.Client
|
||||
Logger *zap.Logger
|
||||
@ -50,3 +54,10 @@ func (p *Producer) ToMailNotify(ctx context.Context, message Message) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type MockProducer struct {
|
||||
}
|
||||
|
||||
func (p *MockProducer) ToMailNotify(ctx context.Context, message Message) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
type Deps struct {
|
||||
Dal *dal.DAL
|
||||
AuthClient auth.IAuthClient
|
||||
Producer *brokers.Producer
|
||||
Producer brokers.IProducer
|
||||
ServiceName string
|
||||
RedisClient *redis.Client
|
||||
}
|
||||
@ -30,7 +30,7 @@ type Deps struct {
|
||||
type Account struct {
|
||||
dal *dal.DAL
|
||||
authClient auth.IAuthClient
|
||||
producer *brokers.Producer
|
||||
producer brokers.IProducer
|
||||
serviceName string
|
||||
redisClient *redis.Client
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
"gitea.pena/SQuiz/core/internal/brokers"
|
||||
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/account"
|
||||
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/question"
|
||||
@ -10,13 +9,14 @@ import (
|
||||
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/statistic"
|
||||
"gitea.pena/SQuiz/core/internal/controllers/http_controllers/telegram"
|
||||
"gitea.pena/SQuiz/core/internal/controllers/rpc_controllers"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
type ControllerDeps struct {
|
||||
Clients *Clients
|
||||
DALs *DALs
|
||||
Config Config
|
||||
Producer *brokers.Producer
|
||||
Producer brokers.IProducer
|
||||
RedisClient *redis.Client
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user