generated from PenaSide/GolangTemplate
refactor: errors pkg & tests
This commit is contained in:
parent
0b83d6f10b
commit
f679de4f5d
@ -4,8 +4,8 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/swagger"
|
||||
)
|
||||
|
||||
func NewAPI(controllers *Controllers) *swagger.API {
|
||||
return swagger.New(&swagger.Deps{
|
||||
func NewAPI(controllers Controllers) *swagger.API {
|
||||
return swagger.New(swagger.Deps{
|
||||
AccountController: controllers.AccountController,
|
||||
CurrencyController: controllers.CurrencyController,
|
||||
CartController: controllers.CartController,
|
||||
|
@ -17,32 +17,33 @@ func TestNewAPI(t *testing.T) {
|
||||
assert.NotPanics(t, func() {
|
||||
logger := zap.New(zap.L().Core())
|
||||
|
||||
repositories := initialize.NewRepositories(&initialize.RepositoriesDeps{
|
||||
repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
|
||||
Logger: logger,
|
||||
MongoDB: t.Client.Database("test"),
|
||||
})
|
||||
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{User: ""},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{Tariff: ""},
|
||||
CurrencyURL: &models.CurrencyMicroserviceURL{},
|
||||
DiscountServiceConfiguration: &models.DiscountMicroserviceConfiguration{},
|
||||
PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{},
|
||||
DiscountServiceConfiguration: &models.DiscountMicroserviceConfiguration{HostGRPC: "host"},
|
||||
PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"},
|
||||
})
|
||||
|
||||
services := initialize.NewServices(&initialize.ServicesDeps{
|
||||
Logger: logger,
|
||||
Repositories: repositories,
|
||||
Clients: clients,
|
||||
services := initialize.NewServices(initialize.ServicesDeps{
|
||||
Logger: logger,
|
||||
Repositories: repositories,
|
||||
Clients: clients,
|
||||
ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "domen"},
|
||||
})
|
||||
|
||||
controllers := initialize.NewControllers(&initialize.ControllersDeps{
|
||||
controllers := initialize.NewControllers(initialize.ControllersDeps{
|
||||
Logger: logger,
|
||||
Services: services,
|
||||
})
|
||||
|
||||
api := initialize.NewAPI(controllers)
|
||||
api := initialize.NewAPI(*controllers)
|
||||
|
||||
assert.NotNil(t, api)
|
||||
})
|
||||
|
@ -23,21 +23,21 @@ type Clients struct {
|
||||
PaymentClient *client.PaymentClient
|
||||
}
|
||||
|
||||
func NewClients(deps *ClientsDeps) *Clients {
|
||||
func NewClients(deps ClientsDeps) *Clients {
|
||||
return &Clients{
|
||||
AuthClient: client.NewAuthClient(&client.AuthClientDeps{
|
||||
AuthClient: client.NewAuthClient(client.AuthClientDeps{
|
||||
Logger: deps.Logger,
|
||||
URLs: deps.AuthURL,
|
||||
}),
|
||||
HubadminClient: client.NewHubadminClient(&client.HubadminClientDeps{
|
||||
HubadminClient: client.NewHubadminClient(client.HubadminClientDeps{
|
||||
Logger: deps.Logger,
|
||||
URLs: deps.HubadminURL,
|
||||
}),
|
||||
CurrencyClient: client.NewCurrencyClient(&client.CurrencyClientDeps{
|
||||
CurrencyClient: client.NewCurrencyClient(client.CurrencyClientDeps{
|
||||
Logger: deps.Logger,
|
||||
URLs: deps.CurrencyURL,
|
||||
}),
|
||||
DiscountClient: client.NewDiscountClient(&client.DiscountClientDeps{
|
||||
DiscountClient: client.NewDiscountClient(client.DiscountClientDeps{
|
||||
Logger: deps.Logger,
|
||||
DiscountServiceHost: deps.DiscountServiceConfiguration.HostGRPC,
|
||||
}),
|
||||
|
@ -14,7 +14,7 @@ func TestNewClients(t *testing.T) {
|
||||
logger := zap.New(zap.L().Core())
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
|
@ -65,6 +65,11 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
||||
Host: "localhost",
|
||||
Port: "8080",
|
||||
},
|
||||
GRPC: models.ConfigurationGRPC{
|
||||
Host: "localhost",
|
||||
Port: "8081",
|
||||
Domen: "domen",
|
||||
},
|
||||
Service: models.ServiceConfiguration{
|
||||
AuthMicroservice: models.AuthMicroserviceConfiguration{
|
||||
URL: defaultAuthURL,
|
||||
@ -75,6 +80,12 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
||||
CurrencyMicroservice: models.CurrencyMicroserviceConfiguration{
|
||||
URL: defaultCurrencyURL,
|
||||
},
|
||||
DiscountMicroservice: models.DiscountMicroserviceConfiguration{
|
||||
HostGRPC: "domen",
|
||||
},
|
||||
PaymentMicroservice: models.PaymentMicroserviceConfiguration{
|
||||
HostGRPC: "domen",
|
||||
},
|
||||
JWT: models.JWTConfiguration{
|
||||
PrivateKey: "jwt private key",
|
||||
PublicKey: "jwt public key",
|
||||
@ -94,6 +105,10 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
||||
},
|
||||
}
|
||||
|
||||
t.Setenv("GRPC_HOST", defaultConfiguration.GRPC.Host)
|
||||
t.Setenv("GRPC_PORT", defaultConfiguration.GRPC.Port)
|
||||
t.Setenv("GRPC_DOMEN", defaultConfiguration.GRPC.Domen)
|
||||
|
||||
t.Setenv("JWT_PUBLIC_KEY", defaultConfiguration.Service.JWT.PublicKey)
|
||||
t.Setenv("JWT_PRIVATE_KEY", defaultConfiguration.Service.JWT.PrivateKey)
|
||||
t.Setenv("JWT_ISSUER", defaultConfiguration.Service.JWT.Issuer)
|
||||
@ -102,6 +117,8 @@ func setDefaultTestingENV(t *testing.T) *models.Config {
|
||||
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)
|
||||
t.Setenv("DISCOUNT_MICROSERVICE_GRPC_HOST", defaultConfiguration.Service.DiscountMicroservice.HostGRPC)
|
||||
t.Setenv("PAYMENT_MICROSERVICE_GRPC_HOST", defaultConfiguration.Service.PaymentMicroservice.HostGRPC)
|
||||
|
||||
t.Setenv("MONGO_HOST", defaultConfiguration.Database.Host)
|
||||
t.Setenv("MONGO_PORT", defaultConfiguration.Database.Port)
|
||||
|
@ -24,21 +24,21 @@ type Controllers struct {
|
||||
PaymentController *payment.Controller
|
||||
}
|
||||
|
||||
func NewControllers(deps *ControllersDeps) *Controllers {
|
||||
func NewControllers(deps ControllersDeps) *Controllers {
|
||||
return &Controllers{
|
||||
AccountController: account.New(&account.Deps{
|
||||
AccountController: account.New(account.Deps{
|
||||
Logger: deps.Logger,
|
||||
Service: deps.Services.AccountService,
|
||||
}),
|
||||
CurrencyController: currency.New(¤cy.Deps{
|
||||
CurrencyController: currency.New(currency.Deps{
|
||||
Logger: deps.Logger,
|
||||
CurrencyService: deps.Services.CurrencyService,
|
||||
}),
|
||||
CartController: cart.New(&cart.Deps{
|
||||
CartController: cart.New(cart.Deps{
|
||||
Logger: deps.Logger,
|
||||
CartService: deps.Services.CartService,
|
||||
}),
|
||||
HistoryController: history.New(&history.Deps{
|
||||
HistoryController: history.New(history.Deps{
|
||||
Logger: deps.Logger,
|
||||
HistoryService: deps.Services.HistoryService,
|
||||
}),
|
||||
|
@ -17,7 +17,7 @@ func TestNewControllers(t *testing.T) {
|
||||
logger := zap.New(zap.L().Core())
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
@ -26,19 +26,19 @@ func TestNewControllers(t *testing.T) {
|
||||
PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"},
|
||||
})
|
||||
|
||||
repositories := initialize.NewRepositories(&initialize.RepositoriesDeps{
|
||||
repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
|
||||
Logger: logger,
|
||||
MongoDB: t.Client.Database("test"),
|
||||
})
|
||||
|
||||
services := initialize.NewServices(&initialize.ServicesDeps{
|
||||
services := initialize.NewServices(initialize.ServicesDeps{
|
||||
Logger: logger,
|
||||
Clients: clients,
|
||||
Repositories: repositories,
|
||||
ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"},
|
||||
})
|
||||
|
||||
controllers := initialize.NewControllers(&initialize.ControllersDeps{
|
||||
controllers := initialize.NewControllers(initialize.ControllersDeps{
|
||||
Logger: logger,
|
||||
Services: services,
|
||||
})
|
||||
|
@ -18,18 +18,18 @@ type Repositories struct {
|
||||
HistoryRepository *repository.HistoryRepository
|
||||
}
|
||||
|
||||
func NewRepositories(deps *RepositoriesDeps) *Repositories {
|
||||
func NewRepositories(deps RepositoriesDeps) *Repositories {
|
||||
return &Repositories{
|
||||
HealthRepository: repository.NewHealthRepository(deps.MongoDB),
|
||||
AccountRepository: repository.NewAccountRepository(&repository.AccountRepositoryDeps{
|
||||
AccountRepository: repository.NewAccountRepository(repository.AccountRepositoryDeps{
|
||||
Logger: deps.Logger,
|
||||
MongoDB: deps.MongoDB.Collection("accounts"),
|
||||
}),
|
||||
CurrencyRepository: repository.NewCurrencyRepository(&repository.CurrencyRepositoryDeps{
|
||||
CurrencyRepository: repository.NewCurrencyRepository(repository.CurrencyRepositoryDeps{
|
||||
Logger: deps.Logger,
|
||||
MongoDB: deps.MongoDB.Collection("currency_lists"),
|
||||
}),
|
||||
HistoryRepository: repository.NewHistoryRepository(&repository.HistoryRepositoryDeps{
|
||||
HistoryRepository: repository.NewHistoryRepository(repository.HistoryRepositoryDeps{
|
||||
Logger: deps.Logger,
|
||||
MongoDB: deps.MongoDB.Collection("histories"),
|
||||
}),
|
||||
|
@ -16,7 +16,7 @@ func TestNewRepositories(t *testing.T) {
|
||||
logger := zap.New(zap.L().Core())
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
repositories := initialize.NewRepositories(&initialize.RepositoriesDeps{
|
||||
repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
|
||||
Logger: logger,
|
||||
MongoDB: t.Client.Database("test"),
|
||||
})
|
||||
|
@ -29,7 +29,7 @@ type Services struct {
|
||||
PaymentCallbackService *callback.PaymentCallbackService
|
||||
}
|
||||
|
||||
func NewServices(deps *ServicesDeps) *Services {
|
||||
func NewServices(deps ServicesDeps) *Services {
|
||||
walletService := wallet.New(wallet.Deps{
|
||||
Logger: deps.Logger,
|
||||
Repository: deps.Repositories.AccountRepository,
|
||||
|
@ -17,7 +17,7 @@ func TestNewServices(t *testing.T) {
|
||||
logger := zap.New(zap.L().Core())
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
clients := initialize.NewClients(&initialize.ClientsDeps{
|
||||
clients := initialize.NewClients(initialize.ClientsDeps{
|
||||
Logger: logger,
|
||||
AuthURL: &models.AuthMicroserviceURL{},
|
||||
HubadminURL: &models.HubadminMicroserviceURL{},
|
||||
@ -26,12 +26,12 @@ func TestNewServices(t *testing.T) {
|
||||
PaymentServiceConfiguration: &models.PaymentMicroserviceConfiguration{HostGRPC: "host"},
|
||||
})
|
||||
|
||||
repositories := initialize.NewRepositories(&initialize.RepositoriesDeps{
|
||||
repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
|
||||
Logger: logger,
|
||||
MongoDB: t.Client.Database("test"),
|
||||
})
|
||||
|
||||
services := initialize.NewServices(&initialize.ServicesDeps{
|
||||
services := initialize.NewServices(initialize.ServicesDeps{
|
||||
Logger: logger,
|
||||
Clients: clients,
|
||||
Repositories: repositories,
|
||||
|
@ -23,11 +23,7 @@ type AuthClient struct {
|
||||
urls *models.AuthMicroserviceURL
|
||||
}
|
||||
|
||||
func NewAuthClient(deps *AuthClientDeps) *AuthClient {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewAuthClient>")
|
||||
}
|
||||
|
||||
func NewAuthClient(deps AuthClientDeps) *AuthClient {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewAuthClient>")
|
||||
}
|
||||
|
@ -23,11 +23,7 @@ type CurrencyClient struct {
|
||||
urls *models.CurrencyMicroserviceURL
|
||||
}
|
||||
|
||||
func NewCurrencyClient(deps *CurrencyClientDeps) *CurrencyClient {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewCurrencyClient>")
|
||||
}
|
||||
|
||||
func NewCurrencyClient(deps CurrencyClientDeps) *CurrencyClient {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewCurrencyClient>")
|
||||
}
|
||||
|
@ -23,11 +23,7 @@ type DiscountClient struct {
|
||||
discountServiceHost string
|
||||
}
|
||||
|
||||
func NewDiscountClient(deps *DiscountClientDeps) *DiscountClient {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewDiscountClient>")
|
||||
}
|
||||
|
||||
func NewDiscountClient(deps DiscountClientDeps) *DiscountClient {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewDiscountClient>")
|
||||
}
|
||||
|
@ -23,11 +23,7 @@ type HubadminClient struct {
|
||||
urls *models.HubadminMicroserviceURL
|
||||
}
|
||||
|
||||
func NewHubadminClient(deps *HubadminClientDeps) *HubadminClient {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewHubadminClient>")
|
||||
}
|
||||
|
||||
func NewHubadminClient(deps HubadminClientDeps) *HubadminClient {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewHubadminClient>")
|
||||
}
|
||||
|
@ -34,11 +34,7 @@ type Controller struct {
|
||||
Service accountService
|
||||
}
|
||||
|
||||
func New(deps *Deps) *Controller {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <New (account controller)>")
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <New (account controller)>")
|
||||
}
|
||||
|
@ -31,11 +31,7 @@ type Controller struct {
|
||||
cartService cartService
|
||||
}
|
||||
|
||||
func New(deps *Deps) *Controller {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <New (cart controller)>")
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <New (cart controller)>")
|
||||
}
|
||||
|
@ -27,11 +27,7 @@ type Controller struct {
|
||||
currencyService currencyService
|
||||
}
|
||||
|
||||
func New(deps *Deps) *Controller {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <New (account controller)>")
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <New (account controller)>")
|
||||
}
|
||||
|
@ -29,11 +29,7 @@ type Controller struct {
|
||||
historyService historyService
|
||||
}
|
||||
|
||||
func New(deps *Deps) *Controller {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <New (history controller)>")
|
||||
}
|
||||
|
||||
func New(deps Deps) *Controller {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <New (history controller)>")
|
||||
}
|
||||
|
@ -27,11 +27,7 @@ type AccountRepository struct {
|
||||
mongoDB *mongo.Collection
|
||||
}
|
||||
|
||||
func NewAccountRepository(deps *AccountRepositoryDeps) *AccountRepository {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewAccountRepository>")
|
||||
}
|
||||
|
||||
func NewAccountRepository(deps AccountRepositoryDeps) *AccountRepository {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewAccountRepository>")
|
||||
}
|
||||
|
@ -26,11 +26,7 @@ type CurrencyRepository struct {
|
||||
mongoDB *mongo.Collection
|
||||
}
|
||||
|
||||
func NewCurrencyRepository(deps *CurrencyRepositoryDeps) *CurrencyRepository {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewCurrencyRepository>")
|
||||
}
|
||||
|
||||
func NewCurrencyRepository(deps CurrencyRepositoryDeps) *CurrencyRepository {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewCurrencyRepository>")
|
||||
}
|
||||
|
@ -27,11 +27,7 @@ type HistoryRepository struct {
|
||||
mongoDB *mongo.Collection
|
||||
}
|
||||
|
||||
func NewHistoryRepository(deps *HistoryRepositoryDeps) *HistoryRepository {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <NewHistoryRepository>")
|
||||
}
|
||||
|
||||
func NewHistoryRepository(deps HistoryRepositoryDeps) *HistoryRepository {
|
||||
if deps.Logger == nil {
|
||||
log.Panicln("logger is nil on <NewHistoryRepository>")
|
||||
}
|
||||
|
@ -56,11 +56,7 @@ type API struct {
|
||||
historyController historyController
|
||||
}
|
||||
|
||||
func New(deps *Deps) *API {
|
||||
if deps == nil {
|
||||
log.Panicln("deps is nil on <New (API)>")
|
||||
}
|
||||
|
||||
func New(deps Deps) *API {
|
||||
if deps.AccountController == nil {
|
||||
log.Panicln("AccountController is nil on <New (API)>")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user