test: fix initialize tests

This commit is contained in:
Kirill 2023-07-06 22:17:08 +03:00
parent 5409141801
commit 091e42f91f
5 changed files with 40 additions and 16 deletions

@ -4,6 +4,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/twmb/franz-go/pkg/kgo"
"go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/integration/mtest"
"go.uber.org/zap" "go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize"
@ -31,11 +32,17 @@ func TestNewAPI(t *testing.T) {
PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"}, PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"},
}) })
brokers := initialize.NewBrokers(initialize.BrokersDeps{
Logger: logger,
TariffClient: &kgo.Client{},
})
services := initialize.NewServices(initialize.ServicesDeps{ services := initialize.NewServices(initialize.ServicesDeps{
Logger: logger, Logger: logger,
Repositories: repositories, Repositories: repositories,
Clients: clients, Clients: clients,
ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "domen"}, ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "domen"},
Brokers: brokers,
}) })
controllers := initialize.NewControllers(initialize.ControllersDeps{ controllers := initialize.NewControllers(initialize.ControllersDeps{

@ -74,6 +74,10 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
AuthMicroservice: models.AuthMicroserviceConfiguration{ AuthMicroservice: models.AuthMicroserviceConfiguration{
URL: defaultAuthURL, URL: defaultAuthURL,
}, },
Kafka: models.KafkaConfiguration{
Tariff: models.TariffKafkaConfiguration{Topic: "topic"},
Brokers: []string{"localhost:8080", "localhost:8081"},
},
HubadminMicroservice: models.HubadminMicroserviceConfiguration{ HubadminMicroservice: models.HubadminMicroserviceConfiguration{
URL: defaultHubAdminURL, URL: defaultHubAdminURL,
}, },
@ -114,6 +118,9 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
t.Setenv("JWT_ISSUER", defaultConfiguration.Service.JWT.Issuer) t.Setenv("JWT_ISSUER", defaultConfiguration.Service.JWT.Issuer)
t.Setenv("JWT_AUDIENCE", defaultConfiguration.Service.JWT.Audience) 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("AUTH_MICROSERVICE_USER_URL", defaultConfiguration.Service.AuthMicroservice.URL.User)
t.Setenv("HUBADMIN_MICROSERVICE_TARIFF_URL", defaultConfiguration.Service.HubadminMicroservice.URL.Tariff) t.Setenv("HUBADMIN_MICROSERVICE_TARIFF_URL", defaultConfiguration.Service.HubadminMicroservice.URL.Tariff)
t.Setenv("CURRENCY_MICROSERVICE_TRANSLATE_URL", defaultConfiguration.Service.CurrencyMicroservice.URL.Translate) t.Setenv("CURRENCY_MICROSERVICE_TRANSLATE_URL", defaultConfiguration.Service.CurrencyMicroservice.URL.Translate)

@ -4,6 +4,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/twmb/franz-go/pkg/kgo"
"go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/integration/mtest"
"go.uber.org/zap" "go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize"
@ -31,10 +32,16 @@ func TestNewControllers(t *testing.T) {
MongoDB: t.Client.Database("test"), MongoDB: t.Client.Database("test"),
}) })
brokers := initialize.NewBrokers(initialize.BrokersDeps{
Logger: logger,
TariffClient: &kgo.Client{},
})
services := initialize.NewServices(initialize.ServicesDeps{ services := initialize.NewServices(initialize.ServicesDeps{
Logger: logger, Logger: logger,
Clients: clients, Clients: clients,
Repositories: repositories, Repositories: repositories,
Brokers: brokers,
ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"}, ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"},
}) })

@ -45,6 +45,12 @@ func NewServices(deps ServicesDeps) *Services {
HistoryService: historyService, HistoryService: historyService,
}) })
tariffBrokerService := tariff.New(tariff.Deps{
Logger: deps.Logger,
Consumer: deps.Brokers.TariffConsumer,
Producer: deps.Brokers.TariffProducer,
})
return &Services{ return &Services{
WalletService: walletService, WalletService: walletService,
HistoryService: historyService, HistoryService: historyService,
@ -58,12 +64,13 @@ func NewServices(deps ServicesDeps) *Services {
Repository: deps.Repositories.CurrencyRepository, Repository: deps.Repositories.CurrencyRepository,
}), }),
CartService: cart.New(cart.Deps{ CartService: cart.New(cart.Deps{
Logger: deps.Logger, Logger: deps.Logger,
Repository: deps.Repositories.AccountRepository, Repository: deps.Repositories.AccountRepository,
HubadminClient: deps.Clients.HubadminClient, HubadminClient: deps.Clients.HubadminClient,
DiscountClient: deps.Clients.DiscountClient, DiscountClient: deps.Clients.DiscountClient,
WalletService: walletService, WalletService: walletService,
HistoryService: historyService, HistoryService: historyService,
TariffBrokerService: tariffBrokerService,
}), }),
PaymentService: payment.New(payment.Deps{ PaymentService: payment.New(payment.Deps{
Logger: deps.Logger, Logger: deps.Logger,
@ -77,10 +84,6 @@ func NewServices(deps ServicesDeps) *Services {
WalletService: walletService, WalletService: walletService,
HistoryService: historyService, HistoryService: historyService,
}), }),
TariffBrokerService: tariff.New(tariff.Deps{ TariffBrokerService: tariffBrokerService,
Logger: deps.Logger,
Consumer: deps.Brokers.TariffConsumer,
Producer: deps.Brokers.TariffProducer,
}),
} }
} }

@ -32,15 +32,15 @@ type ServiceConfiguration struct {
DiscountMicroservice DiscountMicroserviceConfiguration DiscountMicroservice DiscountMicroserviceConfiguration
PaymentMicroservice PaymentMicroserviceConfiguration PaymentMicroservice PaymentMicroserviceConfiguration
JWT JWTConfiguration JWT JWTConfiguration
Kafka Kafka Kafka KafkaConfiguration
} }
type Kafka struct { type KafkaConfiguration struct {
Tariff TariffKafka `json:"tariff"` Tariff TariffKafkaConfiguration `json:"tariff"`
Brokers []string `json:"brokers" env:"KAFKA_BROKERS,required"` Brokers []string `json:"brokers" env:"KAFKA_BROKERS,required"`
} }
type TariffKafka struct { type TariffKafkaConfiguration struct {
Topic string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"` Topic string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"`
} }