From 091e42f91ff754d793726744b9e3891e16f57812 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 6 Jul 2023 22:17:08 +0300 Subject: [PATCH] test: fix initialize tests --- internal/initialize/api_test.go | 7 +++++++ internal/initialize/config_test.go | 7 +++++++ internal/initialize/controllers_test.go | 7 +++++++ internal/initialize/services.go | 25 ++++++++++++++----------- internal/models/config.go | 10 +++++----- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/internal/initialize/api_test.go b/internal/initialize/api_test.go index a2b4bcd..9772184 100644 --- a/internal/initialize/api_test.go +++ b/internal/initialize/api_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/twmb/franz-go/pkg/kgo" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.uber.org/zap" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize" @@ -31,11 +32,17 @@ func TestNewAPI(t *testing.T) { PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"}, }) + brokers := initialize.NewBrokers(initialize.BrokersDeps{ + Logger: logger, + TariffClient: &kgo.Client{}, + }) + services := initialize.NewServices(initialize.ServicesDeps{ Logger: logger, Repositories: repositories, Clients: clients, ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "domen"}, + Brokers: brokers, }) controllers := initialize.NewControllers(initialize.ControllersDeps{ diff --git a/internal/initialize/config_test.go b/internal/initialize/config_test.go index 1345ed2..2f1fb60 100644 --- a/internal/initialize/config_test.go +++ b/internal/initialize/config_test.go @@ -74,6 +74,10 @@ func setDefaultTestingENV(t *testing.T) *models.Config { AuthMicroservice: models.AuthMicroserviceConfiguration{ URL: defaultAuthURL, }, + Kafka: models.KafkaConfiguration{ + Tariff: models.TariffKafkaConfiguration{Topic: "topic"}, + Brokers: []string{"localhost:8080", "localhost:8081"}, + }, HubadminMicroservice: models.HubadminMicroserviceConfiguration{ URL: defaultHubAdminURL, }, @@ -114,6 +118,9 @@ func setDefaultTestingENV(t *testing.T) *models.Config { t.Setenv("JWT_ISSUER", defaultConfiguration.Service.JWT.Issuer) t.Setenv("JWT_AUDIENCE", defaultConfiguration.Service.JWT.Audience) + t.Setenv("KAFKA_BROKERS", "localhost:8080,localhost:8081") + t.Setenv("KAFKA_TOPIC_TARIFF", defaultConfiguration.Service.Kafka.Tariff.Topic) + t.Setenv("AUTH_MICROSERVICE_USER_URL", defaultConfiguration.Service.AuthMicroservice.URL.User) t.Setenv("HUBADMIN_MICROSERVICE_TARIFF_URL", defaultConfiguration.Service.HubadminMicroservice.URL.Tariff) t.Setenv("CURRENCY_MICROSERVICE_TRANSLATE_URL", defaultConfiguration.Service.CurrencyMicroservice.URL.Translate) diff --git a/internal/initialize/controllers_test.go b/internal/initialize/controllers_test.go index 3d299e9..ed0a658 100644 --- a/internal/initialize/controllers_test.go +++ b/internal/initialize/controllers_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/twmb/franz-go/pkg/kgo" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.uber.org/zap" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize" @@ -31,10 +32,16 @@ func TestNewControllers(t *testing.T) { MongoDB: t.Client.Database("test"), }) + brokers := initialize.NewBrokers(initialize.BrokersDeps{ + Logger: logger, + TariffClient: &kgo.Client{}, + }) + services := initialize.NewServices(initialize.ServicesDeps{ Logger: logger, Clients: clients, Repositories: repositories, + Brokers: brokers, ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"}, }) diff --git a/internal/initialize/services.go b/internal/initialize/services.go index 5b438ef..3ae1e6a 100644 --- a/internal/initialize/services.go +++ b/internal/initialize/services.go @@ -45,6 +45,12 @@ func NewServices(deps ServicesDeps) *Services { HistoryService: historyService, }) + tariffBrokerService := tariff.New(tariff.Deps{ + Logger: deps.Logger, + Consumer: deps.Brokers.TariffConsumer, + Producer: deps.Brokers.TariffProducer, + }) + return &Services{ WalletService: walletService, HistoryService: historyService, @@ -58,12 +64,13 @@ func NewServices(deps ServicesDeps) *Services { Repository: deps.Repositories.CurrencyRepository, }), CartService: cart.New(cart.Deps{ - Logger: deps.Logger, - Repository: deps.Repositories.AccountRepository, - HubadminClient: deps.Clients.HubadminClient, - DiscountClient: deps.Clients.DiscountClient, - WalletService: walletService, - HistoryService: historyService, + Logger: deps.Logger, + Repository: deps.Repositories.AccountRepository, + HubadminClient: deps.Clients.HubadminClient, + DiscountClient: deps.Clients.DiscountClient, + WalletService: walletService, + HistoryService: historyService, + TariffBrokerService: tariffBrokerService, }), PaymentService: payment.New(payment.Deps{ Logger: deps.Logger, @@ -77,10 +84,6 @@ func NewServices(deps ServicesDeps) *Services { WalletService: walletService, HistoryService: historyService, }), - TariffBrokerService: tariff.New(tariff.Deps{ - Logger: deps.Logger, - Consumer: deps.Brokers.TariffConsumer, - Producer: deps.Brokers.TariffProducer, - }), + TariffBrokerService: tariffBrokerService, } } diff --git a/internal/models/config.go b/internal/models/config.go index 2ed0b42..ef9a9b5 100644 --- a/internal/models/config.go +++ b/internal/models/config.go @@ -32,15 +32,15 @@ type ServiceConfiguration struct { DiscountMicroservice DiscountMicroserviceConfiguration PaymentMicroservice PaymentMicroserviceConfiguration JWT JWTConfiguration - Kafka Kafka + Kafka KafkaConfiguration } -type Kafka struct { - Tariff TariffKafka `json:"tariff"` - Brokers []string `json:"brokers" env:"KAFKA_BROKERS,required"` +type KafkaConfiguration struct { + Tariff TariffKafkaConfiguration `json:"tariff"` + Brokers []string `json:"brokers" env:"KAFKA_BROKERS,required"` } -type TariffKafka struct { +type TariffKafkaConfiguration struct { Topic string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"` }