diff --git a/event_reporter/reporter/app_revision.go b/event_reporter/reporter/app_revision.go index d03114b29a3a1d..7500625893ec28 100644 --- a/event_reporter/reporter/app_revision.go +++ b/event_reporter/reporter/app_revision.go @@ -42,11 +42,14 @@ func (s *applicationEventReporter) getRevisionsDetails(ctx context.Context, a *a continue } + sourceIndex := int32(idx) + rm, err := s.applicationServiceClient.RevisionMetadata(ctx, &application.RevisionMetadataQuery{ Name: &a.Name, AppNamespace: &a.Namespace, Revision: &revision, Project: &project, + SourceIndex: &sourceIndex, }) if err != nil { return nil, err diff --git a/event_reporter/reporter/app_revision_test.go b/event_reporter/reporter/app_revision_test.go index e0649e76151120..ee9e97af06b343 100644 --- a/event_reporter/reporter/app_revision_test.go +++ b/event_reporter/reporter/app_revision_test.go @@ -5,28 +5,14 @@ import ( "github.com/argoproj/argo-cd/v2/event_reporter/application/mocks" "github.com/argoproj/argo-cd/v2/event_reporter/metrics" "github.com/argoproj/argo-cd/v2/event_reporter/utils" - appclient "github.com/argoproj/argo-cd/v2/pkg/apiclient/application" - + "github.com/argoproj/argo-cd/v2/pkg/apiclient/application" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" - servercache "github.com/argoproj/argo-cd/v2/server/cache" + "github.com/argoproj/argo-cd/v2/server/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "testing" ) -func reporterWithMockedClient(t *testing.T, returnValue *v1alpha1.RevisionMetadata, returnError error) *applicationEventReporter { - appServiceClient := mocks.NewApplicationClient(t) - appServiceClient.On("RevisionMetadata", mock.Anything, mock.Anything, mock.Anything).Return(returnValue, returnError) - - return &applicationEventReporter{ - &servercache.Cache{}, - &MockCodefreshClient{}, - newAppLister(), - appServiceClient, - &metrics.MetricsServer{}, - } -} - func TestGetRevisionsDetails(t *testing.T) { t.Run("should return revisions for single source app", func(t *testing.T) { @@ -39,8 +25,6 @@ func TestGetRevisionsDetails(t *testing.T) { }, }} - reporter := reporterWithMockedClient(t, expectedResult[0].Metadata, nil) - app := v1alpha1.Application{ Spec: v1alpha1.ApplicationSpec{ Source: &v1alpha1.ApplicationSource{ @@ -51,6 +35,26 @@ func TestGetRevisionsDetails(t *testing.T) { }, } + appServiceClient := mocks.NewApplicationClient(t) + project := app.Spec.GetProject() + sourceIdx1 := int32(0) + + appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ + Name: &app.Name, + AppNamespace: &app.Namespace, + Revision: &expectedResult[0].Revision, + Project: &project, + SourceIndex: &sourceIdx1, + }).Return(expectedResult[0].Metadata, nil) + + reporter := &applicationEventReporter{ + &cache.Cache{}, + &MockCodefreshClient{}, + newAppLister(), + appServiceClient, + &metrics.MetricsServer{}, + } + result, _ := reporter.getRevisionsDetails(context.Background(), &app, []string{expectedRevision}) assert.Equal(t, expectedResult, result) @@ -90,21 +94,25 @@ func TestGetRevisionsDetails(t *testing.T) { project := app.Spec.GetProject() appServiceClient := mocks.NewApplicationClient(t) - appServiceClient.On("RevisionMetadata", mock.Anything, &appclient.RevisionMetadataQuery{ + sourceIdx1 := int32(0) + sourceIdx2 := int32(1) + appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ Name: &app.Name, AppNamespace: &app.Namespace, Revision: &expectedRevision1, Project: &project, + SourceIndex: &sourceIdx1, }).Return(expectedResult[0].Metadata, nil) - appServiceClient.On("RevisionMetadata", mock.Anything, &appclient.RevisionMetadataQuery{ + appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ Name: &app.Name, AppNamespace: &app.Namespace, Revision: &expectedRevision2, Project: &project, + SourceIndex: &sourceIdx2, }).Return(expectedResult[1].Metadata, nil) reporter := &applicationEventReporter{ - &servercache.Cache{}, + &cache.Cache{}, &MockCodefreshClient{}, newAppLister(), appServiceClient, @@ -122,8 +130,6 @@ func TestGetRevisionsDetails(t *testing.T) { Revision: expectedRevision, }} - reporter := reporterWithMockedClient(t, expectedResult[0].Metadata, nil) - app := v1alpha1.Application{ Spec: v1alpha1.ApplicationSpec{ Source: &v1alpha1.ApplicationSource{ @@ -134,6 +140,26 @@ func TestGetRevisionsDetails(t *testing.T) { }, } + appServiceClient := mocks.NewApplicationClient(t) + project := app.Spec.GetProject() + sourceIdx1 := int32(0) + + appServiceClient.On("RevisionMetadata", mock.Anything, &application.RevisionMetadataQuery{ + Name: &app.Name, + AppNamespace: &app.Namespace, + Revision: &expectedResult[0].Revision, + Project: &project, + SourceIndex: &sourceIdx1, + }).Return(expectedResult[0].Metadata, nil) + + reporter := &applicationEventReporter{ + &cache.Cache{}, + &MockCodefreshClient{}, + newAppLister(), + appServiceClient, + &metrics.MetricsServer{}, + } + result, _ := reporter.getRevisionsDetails(context.Background(), &app, []string{expectedRevision}) assert.Equal(t, expectedResult, result)