@@ -24,7 +24,6 @@ import (
2424 "github.com/mindersec/minder/internal/entities/properties/service"
2525 "github.com/mindersec/minder/internal/entities/properties/service/mock/fixtures"
2626 stubeventer "github.com/mindersec/minder/internal/events/stubs"
27- pbinternal "github.com/mindersec/minder/internal/proto"
2827 mockgithub "github.com/mindersec/minder/internal/providers/github/mock"
2928 ghprops "github.com/mindersec/minder/internal/providers/github/properties"
3029 "github.com/mindersec/minder/internal/providers/manager"
@@ -96,10 +95,6 @@ type (
9695 providerMockBuilder = func (controller * gomock.Controller ) providerMock
9796)
9897
99- func getPullRequestProperties () * properties.Properties {
100- return properties .NewProperties (pullRequestPropMap )
101- }
102-
10398func newProviderMock (opts ... func (providerMock )) providerMockBuilder {
10499 return func (ctrl * gomock.Controller ) providerMock {
105100 mock := mockgithub .NewMockGitHub (ctrl )
@@ -110,22 +105,6 @@ func newProviderMock(opts ...func(providerMock)) providerMockBuilder {
110105 }
111106}
112107
113- func withSuccessfulGetEntityName (name string ) func (providerMock ) {
114- return func (mock providerMock ) {
115- mock .EXPECT ().
116- GetEntityName (gomock .Any (), gomock .Any ()).
117- Return (name , nil )
118- }
119- }
120-
121- func withSuccessfulFetchAllProperties (props * properties.Properties ) func (mock providerMock ) {
122- return func (mock providerMock ) {
123- mock .EXPECT ().
124- FetchAllProperties (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).
125- Return (props , nil )
126- }
127- }
128-
129108func WithSuccessfulPropertiesToProtoMessage (proto protoreflect.ProtoMessage ) func (mock providerMock ) {
130109 return func (mock providerMock ) {
131110 mock .EXPECT ().
@@ -168,18 +147,6 @@ func checkRepoMessage(t *testing.T, msg *watermill.Message) {
168147 assert .Equal (t , repoPropMap [properties .RepoPropertyIsFork ].(bool ), pbrepo .IsFork )
169148}
170149
171- func checkPullRequestMessage (t * testing.T , msg * watermill.Message ) {
172- t .Helper ()
173-
174- eiw , err := entities .ParseEntityEvent (msg )
175- require .NoError (t , err )
176- require .NotNil (t , eiw )
177-
178- pbpr , ok := eiw .Entity .(* pbinternal.PullRequest )
179- require .True (t , ok )
180- assert .Equal (t , pullRequestPropMap [ghprops .PullPropertyNumber ].(int64 ), pbpr .Number )
181- }
182-
183150type handlerBuilder func (
184151 evt interfaces.Publisher ,
185152 store db.Store ,
@@ -205,17 +172,6 @@ func refreshByIDHandlerBuilder(
205172 return NewRefreshByIDAndEvaluateHandler (evt , store , propSvc , provMgr )
206173}
207174
208- func addOriginatingEntityHandlerBuilder (
209- evt interfaces.Publisher ,
210- store db.Store ,
211- propSvc service.PropertiesService ,
212- provMgr manager.ProviderManager ,
213- ) interfaces.Consumer {
214- // Create a nil entityCreator for testing - the tests focus on other handlers
215- // and addOriginatingEntityHandler tests would need separate setup
216- return NewAddOriginatingEntityHandler (evt , store , propSvc , provMgr , nil )
217- }
218-
219175func removeOriginatingEntityHandlerBuilder (
220176 evt interfaces.Publisher ,
221177 store db.Store ,
@@ -548,80 +504,80 @@ func TestRefreshEntityAndDoHandler_HandleRefreshEntityAndEval(t *testing.T) {
548504 // The test was testing internal implementation details that have been refactored
549505 // New tests for addOriginatingEntityHandler should be written that properly mock EntityCreator
550506 /*
551- {
552- name: "NewAddOriginatingEntityHandler: Adding a pull request originating entity publishes",
553- handlerBuilderFn: addOriginatingEntityHandlerBuilder,
554- messageBuilder: func() *message.HandleEntityAndDoMessage {
555- prProps := properties.NewProperties(map[string]any{
556- properties.PropertyUpstreamID: "789",
557- ghprops.PullPropertyNumber: int64(789),
558- })
559- originatorProps := properties.NewProperties(map[string]any{
560- properties.PropertyUpstreamID: "123",
561- })
562-
563- return message.NewEntityRefreshAndDoMessage().
564- WithEntity(minderv1.Entity_ENTITY_PULL_REQUESTS, prProps).
565- WithOriginator(minderv1.Entity_ENTITY_REPOSITORIES, originatorProps).
566- WithProviderImplementsHint("github")
567- },
568- setupPropSvcMocks: func() fixtures.MockPropertyServiceBuilder {
569- pullEwp := buildEwp(t, pullRequestEwp, pullRequestPropMap)
570- pullProtoEnt, err := ghprops.PullRequestV1FromProperties(pullEwp.Properties)
571- require.NoError(t, err)
572-
573- repoPropsEwp := buildEwp(t, repoEwp, pullRequestPropMap)
574-
575- return fixtures.NewMockPropertiesService(
576- fixtures.WithSuccessfulEntityByUpstreamHint(repoPropsEwp, githubHint),
577- fixtures.WithSuccessfulEntityWithPropertiesAsProto(pullProtoEnt),
578- fixtures.WithSuccessfulSaveAllProperties(),
579- )
580- },
581- mockStoreFunc: df.NewMockStore(
582- df.WithTransaction(),
583- df.WithSuccessfulUpsertPullRequestWithParams(
584-
585- db.EntityInstance{
586- ID: pullRequestID,
587- EntityType: db.EntitiesPullRequest,
588- Name: "",
589- ProjectID: projectID,
590- ProviderID: providerID,
591- OriginatedFrom: uuid.NullUUID{
592- UUID: repoID,
593- Valid: true,
507+ {
508+ name: "NewAddOriginatingEntityHandler: Adding a pull request originating entity publishes",
509+ handlerBuilderFn: addOriginatingEntityHandlerBuilder,
510+ messageBuilder: func() *message.HandleEntityAndDoMessage {
511+ prProps := properties.NewProperties(map[string]any{
512+ properties.PropertyUpstreamID: "789",
513+ ghprops.PullPropertyNumber: int64(789),
514+ })
515+ originatorProps := properties.NewProperties(map[string]any{
516+ properties.PropertyUpstreamID: "123",
517+ })
518+
519+ return message.NewEntityRefreshAndDoMessage().
520+ WithEntity(minderv1.Entity_ENTITY_PULL_REQUESTS, prProps).
521+ WithOriginator(minderv1.Entity_ENTITY_REPOSITORIES, originatorProps).
522+ WithProviderImplementsHint("github")
523+ },
524+ setupPropSvcMocks: func() fixtures.MockPropertyServiceBuilder {
525+ pullEwp := buildEwp(t, pullRequestEwp, pullRequestPropMap)
526+ pullProtoEnt, err := ghprops.PullRequestV1FromProperties(pullEwp.Properties)
527+ require.NoError(t, err)
528+
529+ repoPropsEwp := buildEwp(t, repoEwp, pullRequestPropMap)
530+
531+ return fixtures.NewMockPropertiesService(
532+ fixtures.WithSuccessfulEntityByUpstreamHint(repoPropsEwp, githubHint),
533+ fixtures.WithSuccessfulEntityWithPropertiesAsProto(pullProtoEnt),
534+ fixtures.WithSuccessfulSaveAllProperties(),
535+ )
536+ },
537+ mockStoreFunc: df.NewMockStore(
538+ df.WithTransaction(),
539+ df.WithSuccessfulUpsertPullRequestWithParams(
540+
541+ db.EntityInstance{
542+ ID: pullRequestID,
543+ EntityType: db.EntitiesPullRequest,
544+ Name: "",
545+ ProjectID: projectID,
546+ ProviderID: providerID,
547+ OriginatedFrom: uuid.NullUUID{
548+ UUID: repoID,
549+ Valid: true,
550+ },
594551 },
595- },
596- db.CreateOrEnsureEntityByIDParams{
597- ID: uuid.New() ,
598- EntityType: db.EntitiesPullRequest ,
599- Name : pullName ,
600- ProjectID: projectID ,
601- ProviderID: providerID,
602- OriginatedFrom: uuid.NullUUID{
603- UUID: repoID ,
604- Valid: true ,
552+ db.CreateOrEnsureEntityByIDParams{
553+ ID: uuid.New(),
554+ EntityType: db.EntitiesPullRequest ,
555+ Name: pullName ,
556+ ProjectID : projectID ,
557+ ProviderID: providerID ,
558+ OriginatedFrom: uuid.NullUUID{
559+ UUID: repoID,
560+ Valid: true ,
561+ } ,
605562 },
606- } ,
563+ ) ,
607564 ),
608- ),
609- providerSetup: newProviderMock(
610- withSuccessfulGetEntityName(pullName),
611- withSuccessfulFetchAllProperties(getPullRequestProperties()),
612- WithSuccessfulPropertiesToProtoMessage(&pbinternal.PullRequest{
613- Number: 789,
614- }),
615- ),
616- providerManagerSetup: func(prov provifv1.Provider) provManFixtures.ProviderManagerMockBuilder {
617- return provManFixtures.NewProviderManagerMock(
618- provManFixtures.WithSuccessfulInstantiateFromID(prov),
619- )
565+ providerSetup: newProviderMock(
566+ withSuccessfulGetEntityName(pullName),
567+ withSuccessfulFetchAllProperties(getPullRequestProperties()),
568+ WithSuccessfulPropertiesToProtoMessage(&pbinternal.PullRequest{
569+ Number: 789,
570+ }),
571+ ),
572+ providerManagerSetup: func(prov provifv1.Provider) provManFixtures.ProviderManagerMockBuilder {
573+ return provManFixtures.NewProviderManagerMock(
574+ provManFixtures.WithSuccessfulInstantiateFromID(prov),
575+ )
576+ },
577+ expectedPublish: true,
578+ topic: constants.TopicQueueEntityEvaluate,
579+ checkWmMsg: checkPullRequestMessage,
620580 },
621- expectedPublish: true,
622- topic: constants.TopicQueueEntityEvaluate,
623- checkWmMsg: checkPullRequestMessage,
624- },
625581 */
626582 {
627583 name : "NewRemoveOriginatingEntityHandler: Happy path does not publish" ,
0 commit comments