@@ -5,28 +5,14 @@ import (
55 "github.com/argoproj/argo-cd/v2/event_reporter/application/mocks"
66 "github.com/argoproj/argo-cd/v2/event_reporter/metrics"
77 "github.com/argoproj/argo-cd/v2/event_reporter/utils"
8- appclient "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
9-
8+ "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
109 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
11- servercache "github.com/argoproj/argo-cd/v2/server/cache"
10+ "github.com/argoproj/argo-cd/v2/server/cache"
1211 "github.com/stretchr/testify/assert"
1312 "github.com/stretchr/testify/mock"
1413 "testing"
1514)
1615
17- func reporterWithMockedClient (t * testing.T , returnValue * v1alpha1.RevisionMetadata , returnError error ) * applicationEventReporter {
18- appServiceClient := mocks .NewApplicationClient (t )
19- appServiceClient .On ("RevisionMetadata" , mock .Anything , mock .Anything , mock .Anything ).Return (returnValue , returnError )
20-
21- return & applicationEventReporter {
22- & servercache.Cache {},
23- & MockCodefreshClient {},
24- newAppLister (),
25- appServiceClient ,
26- & metrics.MetricsServer {},
27- }
28- }
29-
3016func TestGetRevisionsDetails (t * testing.T ) {
3117
3218 t .Run ("should return revisions for single source app" , func (t * testing.T ) {
@@ -39,8 +25,6 @@ func TestGetRevisionsDetails(t *testing.T) {
3925 },
4026 }}
4127
42- reporter := reporterWithMockedClient (t , expectedResult [0 ].Metadata , nil )
43-
4428 app := v1alpha1.Application {
4529 Spec : v1alpha1.ApplicationSpec {
4630 Source : & v1alpha1.ApplicationSource {
@@ -51,6 +35,26 @@ func TestGetRevisionsDetails(t *testing.T) {
5135 },
5236 }
5337
38+ appServiceClient := mocks .NewApplicationClient (t )
39+ project := app .Spec .GetProject ()
40+ sourceIdx1 := int32 (0 )
41+
42+ appServiceClient .On ("RevisionMetadata" , mock .Anything , & application.RevisionMetadataQuery {
43+ Name : & app .Name ,
44+ AppNamespace : & app .Namespace ,
45+ Revision : & expectedResult [0 ].Revision ,
46+ Project : & project ,
47+ SourceIndex : & sourceIdx1 ,
48+ }).Return (expectedResult [0 ].Metadata , nil )
49+
50+ reporter := & applicationEventReporter {
51+ & cache.Cache {},
52+ & MockCodefreshClient {},
53+ newAppLister (),
54+ appServiceClient ,
55+ & metrics.MetricsServer {},
56+ }
57+
5458 result , _ := reporter .getRevisionsDetails (context .Background (), & app , []string {expectedRevision })
5559
5660 assert .Equal (t , expectedResult , result )
@@ -90,21 +94,25 @@ func TestGetRevisionsDetails(t *testing.T) {
9094 project := app .Spec .GetProject ()
9195
9296 appServiceClient := mocks .NewApplicationClient (t )
93- appServiceClient .On ("RevisionMetadata" , mock .Anything , & appclient.RevisionMetadataQuery {
97+ sourceIdx1 := int32 (0 )
98+ sourceIdx2 := int32 (1 )
99+ appServiceClient .On ("RevisionMetadata" , mock .Anything , & application.RevisionMetadataQuery {
94100 Name : & app .Name ,
95101 AppNamespace : & app .Namespace ,
96102 Revision : & expectedRevision1 ,
97103 Project : & project ,
104+ SourceIndex : & sourceIdx1 ,
98105 }).Return (expectedResult [0 ].Metadata , nil )
99- appServiceClient .On ("RevisionMetadata" , mock .Anything , & appclient .RevisionMetadataQuery {
106+ appServiceClient .On ("RevisionMetadata" , mock .Anything , & application .RevisionMetadataQuery {
100107 Name : & app .Name ,
101108 AppNamespace : & app .Namespace ,
102109 Revision : & expectedRevision2 ,
103110 Project : & project ,
111+ SourceIndex : & sourceIdx2 ,
104112 }).Return (expectedResult [1 ].Metadata , nil )
105113
106114 reporter := & applicationEventReporter {
107- & servercache .Cache {},
115+ & cache .Cache {},
108116 & MockCodefreshClient {},
109117 newAppLister (),
110118 appServiceClient ,
@@ -122,8 +130,6 @@ func TestGetRevisionsDetails(t *testing.T) {
122130 Revision : expectedRevision ,
123131 }}
124132
125- reporter := reporterWithMockedClient (t , expectedResult [0 ].Metadata , nil )
126-
127133 app := v1alpha1.Application {
128134 Spec : v1alpha1.ApplicationSpec {
129135 Source : & v1alpha1.ApplicationSource {
@@ -134,6 +140,26 @@ func TestGetRevisionsDetails(t *testing.T) {
134140 },
135141 }
136142
143+ appServiceClient := mocks .NewApplicationClient (t )
144+ project := app .Spec .GetProject ()
145+ sourceIdx1 := int32 (0 )
146+
147+ appServiceClient .On ("RevisionMetadata" , mock .Anything , & application.RevisionMetadataQuery {
148+ Name : & app .Name ,
149+ AppNamespace : & app .Namespace ,
150+ Revision : & expectedResult [0 ].Revision ,
151+ Project : & project ,
152+ SourceIndex : & sourceIdx1 ,
153+ }).Return (expectedResult [0 ].Metadata , nil )
154+
155+ reporter := & applicationEventReporter {
156+ & cache.Cache {},
157+ & MockCodefreshClient {},
158+ newAppLister (),
159+ appServiceClient ,
160+ & metrics.MetricsServer {},
161+ }
162+
137163 result , _ := reporter .getRevisionsDetails (context .Background (), & app , []string {expectedRevision })
138164
139165 assert .Equal (t , expectedResult , result )
0 commit comments