Skip to content

Commit

Permalink
event-reporter / app_revision.go: added sourceIndex param to applicat…
Browse files Browse the repository at this point in the history
…ionServiceClient.RevisionMetadata in order to properly support multisourced apps
  • Loading branch information
oleksandr-codefresh committed Oct 1, 2024
1 parent 02c14a3 commit c3aa11f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
3 changes: 3 additions & 0 deletions event_reporter/reporter/app_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 49 additions & 23 deletions event_reporter/reporter/app_revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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{
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand All @@ -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)
Expand Down

0 comments on commit c3aa11f

Please sign in to comment.