Skip to content

Commit

Permalink
feat(logs): adding logs and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiz Pegoraro committed Sep 28, 2023
1 parent 1380cb5 commit 6261e45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
16 changes: 10 additions & 6 deletions maestro/service/deploy_service_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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)
}
})
}
}
26 changes: 19 additions & 7 deletions maestro/service/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"errors"
"github.com/orb-community/orb/maestro/deployment"
"go.uber.org/zap"
)
Expand All @@ -12,32 +13,43 @@ 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 {
return nil
}

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) {
Expand Down

0 comments on commit 6261e45

Please sign in to comment.