Skip to content

Commit

Permalink
feat(maestro): fixing and adding new tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiz Pegoraro committed Sep 28, 2023
1 parent 6261e45 commit e491554
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
13 changes: 9 additions & 4 deletions maestro/deployment/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion maestro/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion maestro/service/deploy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions maestro/service/producer_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e491554

Please sign in to comment.