From 7e9c9d75985cabe89315e23e7281659cca79d33f Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 11 Sep 2024 14:13:35 +0200 Subject: [PATCH] Rename EntityWithProperties to EntityWithPropertiesByID We're about to add a different `EntityWithPropertiesByUpstreamID` so let's make the names more descriptive. --- internal/controlplane/handlers_evalstatus.go | 2 +- internal/controlplane/handlers_profile.go | 2 +- internal/controlplane/handlers_providers_test.go | 4 ++-- internal/engine/executor.go | 2 +- internal/engine/executor_test.go | 2 +- internal/entities/properties/service/mock/service.go | 12 ++++++------ internal/entities/properties/service/service.go | 6 +++--- internal/entities/properties/service/service_test.go | 2 +- internal/history/service.go | 2 +- internal/history/service_test.go | 4 ++-- internal/providers/github/manager/manager.go | 2 +- internal/repositories/service.go | 6 +++--- internal/repositories/service_test.go | 4 ++-- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/controlplane/handlers_evalstatus.go b/internal/controlplane/handlers_evalstatus.go index fab119025e..9c4259191d 100644 --- a/internal/controlplane/handlers_evalstatus.go +++ b/internal/controlplane/handlers_evalstatus.go @@ -393,7 +393,7 @@ func (s *Server) sortEntitiesEvaluationStatus( continue } - efp, err := s.props.EntityWithProperties(ctx, e.EntityID, nil) + efp, err := s.props.EntityWithPropertiesByID(ctx, e.EntityID, nil) if err != nil { if errors.Is(err, propSvc.ErrEntityNotFound) { // If the entity is not found, log and skip diff --git a/internal/controlplane/handlers_profile.go b/internal/controlplane/handlers_profile.go index 5354633252..046de40aeb 100644 --- a/internal/controlplane/handlers_profile.go +++ b/internal/controlplane/handlers_profile.go @@ -456,7 +456,7 @@ func (s *Server) getRuleEvalStatus( // the caller just ignores allt the errors anyway, so we don't start a transaction as the integrity issues // would not be discovered anyway - efp, err := s.props.EntityWithProperties(ctx, dbRuleEvalStat.EntityID, nil) + efp, err := s.props.EntityWithPropertiesByID(ctx, dbRuleEvalStat.EntityID, nil) if err != nil { return nil, fmt.Errorf("error fetching entity for properties: %w", err) } diff --git a/internal/controlplane/handlers_providers_test.go b/internal/controlplane/handlers_providers_test.go index d66ee903e3..4e387b9e57 100644 --- a/internal/controlplane/handlers_providers_test.go +++ b/internal/controlplane/handlers_providers_test.go @@ -528,7 +528,7 @@ func TestDeleteProvider(t *testing.T) { mockprops := propSvc.NewMockPropertiesService(ctrl) mockprops.EXPECT(). - EntityWithProperties(gomock.Any(), gomock.Any(), nil). + EntityWithPropertiesByID(gomock.Any(), gomock.Any(), nil). Return(models.NewEntityWithPropertiesFromInstance( models.EntityInstance{}, nil), nil) @@ -649,7 +649,7 @@ func TestDeleteProviderByID(t *testing.T) { mockprops := propSvc.NewMockPropertiesService(ctrl) mockprops.EXPECT(). - EntityWithProperties(gomock.Any(), gomock.Any(), nil). + EntityWithPropertiesByID(gomock.Any(), gomock.Any(), nil). Return(models.NewEntityWithPropertiesFromInstance( models.EntityInstance{}, nil), nil) diff --git a/internal/engine/executor.go b/internal/engine/executor.go index 3838f011de..0f0b6d4056 100644 --- a/internal/engine/executor.go +++ b/internal/engine/executor.go @@ -235,7 +235,7 @@ func (e *executor) profileEvalStatus( } // get the entity with properties by the entity UUID - ewp, err := e.propService.EntityWithProperties(ctx, entityID, + ewp, err := e.propService.EntityWithPropertiesByID(ctx, entityID, service.CallBuilder().WithStoreOrTransaction(e.querier)) if err != nil { return fmt.Errorf("error getting entity with properties: %w", err) diff --git a/internal/engine/executor_test.go b/internal/engine/executor_test.go index 05a2b71d42..46a7297417 100644 --- a/internal/engine/executor_test.go +++ b/internal/engine/executor_test.go @@ -325,7 +325,7 @@ default allow = true`, mockPropSvc := mockprops.NewMockPropertiesService(ctrl) mockPropSvc.EXPECT(). - EntityWithProperties(gomock.Any(), repositoryID, gomock.Any()). + EntityWithPropertiesByID(gomock.Any(), repositoryID, gomock.Any()). Return(&models.EntityWithProperties{ Entity: models.EntityInstance{ ID: repositoryID, diff --git a/internal/entities/properties/service/mock/service.go b/internal/entities/properties/service/mock/service.go index 948fcb66b7..e9e52f8807 100644 --- a/internal/entities/properties/service/mock/service.go +++ b/internal/entities/properties/service/mock/service.go @@ -47,19 +47,19 @@ func (m *MockPropertiesService) EXPECT() *MockPropertiesServiceMockRecorder { return m.recorder } -// EntityWithProperties mocks base method. -func (m *MockPropertiesService) EntityWithProperties(ctx context.Context, entityID uuid.UUID, opts *service.CallOptions) (*models.EntityWithProperties, error) { +// EntityWithPropertiesByID mocks base method. +func (m *MockPropertiesService) EntityWithPropertiesByID(ctx context.Context, entityID uuid.UUID, opts *service.CallOptions) (*models.EntityWithProperties, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EntityWithProperties", ctx, entityID, opts) + ret := m.ctrl.Call(m, "EntityWithPropertiesByID", ctx, entityID, opts) ret0, _ := ret[0].(*models.EntityWithProperties) ret1, _ := ret[1].(error) return ret0, ret1 } -// EntityWithProperties indicates an expected call of EntityWithProperties. -func (mr *MockPropertiesServiceMockRecorder) EntityWithProperties(ctx, entityID, opts any) *gomock.Call { +// EntityWithPropertiesByID indicates an expected call of EntityWithPropertiesByID. +func (mr *MockPropertiesServiceMockRecorder) EntityWithPropertiesByID(ctx, entityID, opts any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EntityWithProperties", reflect.TypeOf((*MockPropertiesService)(nil).EntityWithProperties), ctx, entityID, opts) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EntityWithPropertiesByID", reflect.TypeOf((*MockPropertiesService)(nil).EntityWithPropertiesByID), ctx, entityID, opts) } // EntityWithPropertiesAsProto mocks base method. diff --git a/internal/entities/properties/service/service.go b/internal/entities/properties/service/service.go index 0d7e43f9c1..bab4e6e88a 100644 --- a/internal/entities/properties/service/service.go +++ b/internal/entities/properties/service/service.go @@ -60,8 +60,8 @@ type PropertiesService interface { EntityWithPropertiesAsProto( ctx context.Context, ewp *models.EntityWithProperties, provMgr manager.ProviderManager, ) (protoreflect.ProtoMessage, error) - // EntityWithProperties Fetches an Entity by ID and Project in order to refresh the properties - EntityWithProperties( + // EntityWithPropertiesByID Fetches an Entity by ID and Project in order to refresh the properties + EntityWithPropertiesByID( ctx context.Context, entityID uuid.UUID, opts *CallOptions, ) (*models.EntityWithProperties, error) // RetrieveAllProperties fetches all properties for an entity @@ -290,7 +290,7 @@ func (ps *propertiesService) ReplaceProperty( return err } -func (ps *propertiesService) EntityWithProperties( +func (ps *propertiesService) EntityWithPropertiesByID( ctx context.Context, entityID uuid.UUID, opts *CallOptions, ) (*models.EntityWithProperties, error) { diff --git a/internal/entities/properties/service/service_test.go b/internal/entities/properties/service/service_test.go index 3d4c7281a1..691b1bef9b 100644 --- a/internal/entities/properties/service/service_test.go +++ b/internal/entities/properties/service/service_test.go @@ -904,7 +904,7 @@ func TestPropertiesService_EntityWithProperties(t *testing.T) { Return(tt.dbPropsBuilder(tt.entityID), nil) ps := NewPropertiesService(mockDB) - result, err := ps.EntityWithProperties(ctx, tt.entityID, nil) + result, err := ps.EntityWithPropertiesByID(ctx, tt.entityID, nil) require.NoError(t, err) require.NotNil(t, result) require.Equal(t, result.Entity.ID, tt.entityID) diff --git a/internal/history/service.go b/internal/history/service.go index 5a7fc8d0cf..9b1b57c418 100644 --- a/internal/history/service.go +++ b/internal/history/service.go @@ -218,7 +218,7 @@ func (ehs *evaluationHistoryService) ListEvaluationHistory( data := make([]*OneEvalHistoryAndEntity, 0, len(rows)) for _, row := range rows { - efp, err := propsvc.EntityWithProperties(ctx, row.EntityID, + efp, err := propsvc.EntityWithPropertiesByID(ctx, row.EntityID, propertiessvc.CallBuilder().WithStoreOrTransaction(qtx)) if err != nil { return nil, fmt.Errorf("error fetching entity for properties: %w", err) diff --git a/internal/history/service_test.go b/internal/history/service_test.go index 792949ff59..5e8b971782 100644 --- a/internal/history/service_test.go +++ b/internal/history/service_test.go @@ -836,12 +836,12 @@ func TestListEvaluationHistory(t *testing.T) { pm := pmMock.NewMockProviderManager(ctrl) propsSvc := propsSvcMock.NewMockPropertiesService(ctrl) for _, efp := range tt.efp { - propsSvc.EXPECT().EntityWithProperties(ctx, gomock.Any(), gomock.Any()). + propsSvc.EXPECT().EntityWithPropertiesByID(ctx, gomock.Any(), gomock.Any()). Return(efp, tt.entityForPropertiesError) } if tt.entityForPropertiesError != nil && len(tt.efp) == 0 { - propsSvc.EXPECT().EntityWithProperties(ctx, gomock.Any(), gomock.Any()). + propsSvc.EXPECT().EntityWithPropertiesByID(ctx, gomock.Any(), gomock.Any()). Return(nil, tt.entityForPropertiesError).AnyTimes() } propsSvc.EXPECT().RetrieveAllPropertiesForEntity(ctx, gomock.Any(), gomock.Any(), gomock.Any()). diff --git a/internal/providers/github/manager/manager.go b/internal/providers/github/manager/manager.go index 770577784c..1124249395 100644 --- a/internal/providers/github/manager/manager.go +++ b/internal/providers/github/manager/manager.go @@ -177,7 +177,7 @@ func (g *githubProviderManager) Delete(ctx context.Context, config *db.Provider) } for _, ent := range entities { - ewp, err := g.propsSvc.EntityWithProperties(ctx, ent.ID, nil) + ewp, err := g.propsSvc.EntityWithPropertiesByID(ctx, ent.ID, nil) if err != nil { zerolog.Ctx(ctx).Error().Err(err). Str("provider_id", config.ID.String()). diff --git a/internal/repositories/service.go b/internal/repositories/service.go index 739f0c0ca3..87012e38da 100644 --- a/internal/repositories/service.go +++ b/internal/repositories/service.go @@ -257,7 +257,7 @@ func (r *repositoryService) ListRepositories( ents = make([]*models.EntityWithProperties, 0, len(repoEnts)) for _, ent := range repoEnts { - ewp, err := r.propSvc.EntityWithProperties(ctx, ent.ID, + ewp, err := r.propSvc.EntityWithPropertiesByID(ctx, ent.ID, service.CallBuilder().WithStoreOrTransaction(qtx)) if err != nil { return nil, fmt.Errorf("error fetching properties for repository: %w", err) @@ -315,7 +315,7 @@ func (r *repositoryService) DeleteByID(ctx context.Context, repositoryID uuid.UU logger.BusinessRecord(ctx).Project = projectID logger.BusinessRecord(ctx).Repository = repositoryID - ent, err := r.propSvc.EntityWithProperties(ctx, repositoryID, nil) + ent, err := r.propSvc.EntityWithPropertiesByID(ctx, repositoryID, nil) if err != nil { return fmt.Errorf("error fetching repository: %w", err) } @@ -355,7 +355,7 @@ func (r *repositoryService) DeleteByName( logger.BusinessRecord(ctx).Repository = repo.ID - ent, err := r.propSvc.EntityWithProperties(ctx, repo.ID, nil) + ent, err := r.propSvc.EntityWithPropertiesByID(ctx, repo.ID, nil) if err != nil { return fmt.Errorf("error fetching repository: %w", err) } diff --git a/internal/repositories/service_test.go b/internal/repositories/service_test.go index 84ec057666..b03b69946d 100644 --- a/internal/repositories/service_test.go +++ b/internal/repositories/service_test.go @@ -712,7 +712,7 @@ func withSuccessfulPropFetch(prop *properties.Properties) func(svcMock propSvcMo func withSuccessfulEntityWithProps(mock propSvcMock) { mock.EXPECT(). - EntityWithProperties(gomock.Any(), gomock.Any(), gomock.Any()). + EntityWithPropertiesByID(gomock.Any(), gomock.Any(), gomock.Any()). Return(models.NewEntityWithPropertiesFromInstance(models.EntityInstance{ ID: dbRepo.ID, ProjectID: projectID, @@ -722,7 +722,7 @@ func withSuccessfulEntityWithProps(mock propSvcMock) { func withFailedEntityWithProps(mock propSvcMock) { mock.EXPECT(). - EntityWithProperties(gomock.Any(), gomock.Any(), gomock.Any()). + EntityWithPropertiesByID(gomock.Any(), gomock.Any(), gomock.Any()). Return(nil, errDefault) }