From e49155481768709393605ee01158167adc13e677 Mon Sep 17 00:00:00 2001 From: Luiz Pegoraro Date: Thu, 28 Sep 2023 15:50:03 -0300 Subject: [PATCH] feat(maestro): fixing and adding new tests. --- maestro/deployment/service.go | 13 +++++++++---- maestro/service.go | 3 ++- maestro/service/deploy_service_test.go | 2 +- maestro/service/producer_test.go | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 maestro/service/producer_test.go diff --git a/maestro/deployment/service.go b/maestro/deployment/service.go index 092b671b4..27fec2608 100644 --- a/maestro/deployment/service.go +++ b/maestro/deployment/service.go @@ -43,11 +43,16 @@ type deploymentService struct { var _ Service = (*deploymentService)(nil) -func NewDeploymentService(logger *zap.Logger, repository Repository, kafkaUrl string, encryptionKey string) Service { +func NewDeploymentService(logger *zap.Logger, repository Repository, kafkaUrl string, encryptionKey string, maestroProducer producer.Producer) Service { namedLogger := logger.Named("deployment-service") es := password.NewEncryptionService(logger, encryptionKey) cb := config.NewConfigBuilder(namedLogger, kafkaUrl, es) - return &deploymentService{logger: namedLogger, dbRepository: repository, configBuilder: cb, encryptionService: es} + return &deploymentService{logger: namedLogger, + dbRepository: repository, + configBuilder: cb, + encryptionService: es, + maestroProducer: maestroProducer, + } } func (d *deploymentService) CreateDeployment(ctx context.Context, deployment *Deployment) error { @@ -82,12 +87,12 @@ func (d *deploymentService) getAuthBuilder(authType string) config.AuthBuilderSe func (d *deploymentService) encodeConfig(deployment *Deployment) (types.Metadata, error) { authType := deployment.GetConfig() - if authType != nil { + if authType == nil { return nil, errors.New("deployment do not have authentication information") } value := authType.GetSubMetadata(AuthenticationKey)["type"].(string) authBuilder := d.getAuthBuilder(value) - if authBuilder != nil { + if authBuilder == nil { return nil, errors.New("deployment do not have authentication information") } return authBuilder.EncodeAuth(deployment.GetConfig()) diff --git a/maestro/service.go b/maestro/service.go index 33106559e..4071553f1 100644 --- a/maestro/service.go +++ b/maestro/service.go @@ -50,7 +50,8 @@ func NewMaestroService(logger *zap.Logger, streamRedisClient *redis.Client, sink sinksGrpcClient sinkspb.SinkServiceClient, otelCfg config.OtelConfig, db *sqlx.DB, svcCfg config.BaseSvcConfig) Service { kubectr := kubecontrol.NewService(logger) repo := deployment.NewRepositoryService(db, logger) - deploymentService := deployment.NewDeploymentService(logger, repo, otelCfg.KafkaUrl, svcCfg.EncryptionKey) + maestroProducer := producer.NewMaestroProducer(logger, streamRedisClient) + deploymentService := deployment.NewDeploymentService(logger, repo, otelCfg.KafkaUrl, svcCfg.EncryptionKey, maestroProducer) ps := producer.NewMaestroProducer(logger, streamRedisClient) monitorService := monitor.NewMonitorService(logger, &sinksGrpcClient, ps, &kubectr) eventService := service.NewEventService(logger, deploymentService, kubectr) diff --git a/maestro/service/deploy_service_test.go b/maestro/service/deploy_service_test.go index 99f56bbe9..e4837ec6e 100644 --- a/maestro/service/deploy_service_test.go +++ b/maestro/service/deploy_service_test.go @@ -46,7 +46,7 @@ func Test_eventService_HandleSinkCreate(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { logger := zap.NewNop() - deploymentService := deployment.NewDeploymentService(logger, NewFakeRepository(logger), "kafka:9092", "MY_SECRET") + deploymentService := deployment.NewDeploymentService(logger, NewFakeRepository(logger), "kafka:9092", "MY_SECRET", NewTestProducer(logger)) d := NewEventService(logger, deploymentService, nil) ctx := context.WithValue(context.Background(), "test", tt.name) if err := d.HandleSinkCreate(ctx, tt.args.event); (err != nil) != tt.wantErr { diff --git a/maestro/service/producer_test.go b/maestro/service/producer_test.go new file mode 100644 index 000000000..e108b1bfa --- /dev/null +++ b/maestro/service/producer_test.go @@ -0,0 +1,19 @@ +package service + +import ( + "context" + "github.com/orb-community/orb/maestro/redis/producer" + "go.uber.org/zap" +) + +type testProducer struct { + logger *zap.Logger +} + +func NewTestProducer(logger *zap.Logger) producer.Producer { + return &testProducer{logger: logger} +} + +func (t *testProducer) PublishSinkStatus(_ context.Context, _ string, _ string, _ string, _ string) error { + return nil +}