From 6261e45d39aed63b797ca6566adfdb590edce357 Mon Sep 17 00:00:00 2001 From: Luiz Pegoraro Date: Thu, 28 Sep 2023 15:36:36 -0300 Subject: [PATCH] feat(logs): adding logs and unit tests. --- maestro/service/deploy_service_test.go | 16 ++++++++++------ maestro/service/repository_test.go | 26 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/maestro/service/deploy_service_test.go b/maestro/service/deploy_service_test.go index af11347dd..99f56bbe9 100644 --- a/maestro/service/deploy_service_test.go +++ b/maestro/service/deploy_service_test.go @@ -1,8 +1,11 @@ package service import ( + "context" + "github.com/orb-community/orb/maestro/deployment" "github.com/orb-community/orb/maestro/redis" "github.com/orb-community/orb/pkg/types" + "go.uber.org/zap" "testing" "time" ) @@ -42,12 +45,13 @@ 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, - //d := NewEventService(logger, ) - //if err := d.HandleSinkCreate(tt.args.ctx, tt.args.event); (err != nil) != tt.wantErr { - // t.Errorf("HandleSinkCreate() error = %v, wantErr %v", err, tt.wantErr) - //} + logger := zap.NewNop() + deploymentService := deployment.NewDeploymentService(logger, NewFakeRepository(logger), "kafka:9092", "MY_SECRET") + 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 { + t.Errorf("HandleSinkCreate() error = %v, wantErr %v", err, tt.wantErr) + } }) } } diff --git a/maestro/service/repository_test.go b/maestro/service/repository_test.go index 82070c753..795df9331 100644 --- a/maestro/service/repository_test.go +++ b/maestro/service/repository_test.go @@ -2,6 +2,7 @@ package service import ( "context" + "errors" "github.com/orb-community/orb/maestro/deployment" "go.uber.org/zap" ) @@ -12,20 +13,26 @@ type fakeRepository struct { } func NewFakeRepository(logger *zap.Logger) deployment.Repository { - - return &fakeRepository{logger: logger} + return &fakeRepository{logger: logger, inMemoryDict: make(map[string]*deployment.Deployment)} } func (f *fakeRepository) FetchAll(ctx context.Context) ([]deployment.Deployment, error) { - return nil, nil + var allDeployments []deployment.Deployment + for _, deploy := range f.inMemoryDict { + allDeployments = append(allDeployments, *deploy) + } + return allDeployments, nil } func (f *fakeRepository) Add(ctx context.Context, deployment *deployment.Deployment) (*deployment.Deployment, error) { - return nil, nil + deployment.Id = "fake-id" + f.inMemoryDict[deployment.SinkID] = deployment + return deployment, nil } func (f *fakeRepository) Update(ctx context.Context, deployment *deployment.Deployment) (*deployment.Deployment, error) { - return nil, nil + f.inMemoryDict[deployment.SinkID] = deployment + return deployment, nil } func (f *fakeRepository) UpdateStatus(ctx context.Context, ownerID string, sinkId string, status string, errorMessage string) error { @@ -33,11 +40,16 @@ func (f *fakeRepository) UpdateStatus(ctx context.Context, ownerID string, sinkI } func (f *fakeRepository) Remove(ctx context.Context, ownerId string, sinkId string) error { + delete(f.inMemoryDict, sinkId) return nil } -func (f *fakeRepository) FindByOwnerAndSink(ctx context.Context, ownerId string, sinkId string) (*deployment.Deployment, error) { - return nil, nil +func (f *fakeRepository) FindByOwnerAndSink(ctx context.Context, _ string, sinkId string) (*deployment.Deployment, error) { + deploy, ok := f.inMemoryDict[sinkId] + if ok { + return deploy, nil + } + return nil, errors.New("not found") } func (f *fakeRepository) FindByCollectorName(ctx context.Context, collectorName string) (*deployment.Deployment, error) {