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