@@ -48,7 +48,6 @@ import (
4848 appinformer "github.com/argoproj/argo-cd/v2/pkg/client/informers/externalversions"
4949 "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
5050 "github.com/argoproj/argo-cd/v2/reposerver/apiclient/mocks"
51- appmocks "github.com/argoproj/argo-cd/v2/server/application/mocks"
5251 servercache "github.com/argoproj/argo-cd/v2/server/cache"
5352 "github.com/argoproj/argo-cd/v2/server/rbacpolicy"
5453 "github.com/argoproj/argo-cd/v2/test"
@@ -71,6 +70,35 @@ const (
7170
7271var testEnableEventList []string = argo .DefaultEnableEventList ()
7372
73+ type broadcasterMock struct {
74+ objects []runtime.Object
75+ }
76+
77+ func (b broadcasterMock ) Subscribe (ch chan * appv1.ApplicationWatchEvent , filters ... func (event * appv1.ApplicationWatchEvent ) bool ) func () {
78+ // Simulate the broadcaster notifying the subscriber of an application update.
79+ // The second parameter to Subscribe is filters. For the purposes of tests, we ignore the filters. Future tests
80+ // might require implementing those.
81+ go func () {
82+ for _ , obj := range b .objects {
83+ app , ok := obj .(* appsv1.Application )
84+ if ok {
85+ oldVersion , err := strconv .Atoi (app .ResourceVersion )
86+ if err != nil {
87+ oldVersion = 0
88+ }
89+ clonedApp := app .DeepCopy ()
90+ clonedApp .ResourceVersion = strconv .Itoa (oldVersion + 1 )
91+ ch <- & appsv1.ApplicationWatchEvent {Type : watch .Added , Application : * clonedApp }
92+ }
93+ }
94+ }()
95+ return func () {}
96+ }
97+
98+ func (broadcasterMock ) OnAdd (interface {}, bool ) {}
99+ func (broadcasterMock ) OnUpdate (interface {}, interface {}) {}
100+ func (broadcasterMock ) OnDelete (interface {}) {}
101+
74102func fakeRepo () * appsv1.Repository {
75103 return & appsv1.Repository {
76104 Repo : fakeRepoURL ,
@@ -225,30 +253,9 @@ func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T,
225253 panic ("Timed out waiting for caches to sync" )
226254 }
227255
228- broadcaster := new (appmocks.Broadcaster )
229- broadcaster .On ("Subscribe" , mock .Anything , mock .Anything ).Return (func () {}).Run (func (args mock.Arguments ) {
230- // Simulate the broadcaster notifying the subscriber of an application update.
231- // The second parameter to Subscribe is filters. For the purposes of tests, we ignore the filters. Future tests
232- // might require implementing those.
233- go func () {
234- events := args .Get (0 ).(chan * appsv1.ApplicationWatchEvent )
235- for _ , obj := range objects {
236- app , ok := obj .(* appsv1.Application )
237- if ok {
238- oldVersion , err := strconv .Atoi (app .ResourceVersion )
239- if err != nil {
240- oldVersion = 0
241- }
242- clonedApp := app .DeepCopy ()
243- clonedApp .ResourceVersion = fmt .Sprintf ("%d" , oldVersion + 1 )
244- events <- & appsv1.ApplicationWatchEvent {Type : watch .Added , Application : * clonedApp }
245- }
246- }
247- }()
248- })
249- broadcaster .On ("OnAdd" , mock .Anything , mock .Anything ).Return ()
250- broadcaster .On ("OnUpdate" , mock .Anything , mock .Anything ).Return ()
251- broadcaster .On ("OnDelete" , mock .Anything ).Return ()
256+ broadcaster := broadcasterMock {
257+ objects : objects ,
258+ }
252259
253260 appStateCache := appstate .NewCache (cache .NewCache (cache .NewInMemoryCache (time .Hour )), time .Hour )
254261 // pre-populate the app cache
@@ -406,31 +413,9 @@ func newTestAppServerWithEnforcerConfigureWithBenchmark(f func(*rbac.Enforcer),
406413 panic ("Timed out waiting for caches to sync" )
407414 }
408415
409- broadcaster := new (appmocks.Broadcaster )
410- broadcaster .On ("Subscribe" , mock .Anything , mock .Anything ).Return (func () {}).Run (func (args mock.Arguments ) {
411- // Simulate the broadcaster notifying the subscriber of an application update.
412- // The second parameter to Subscribe is filters. For the purposes of tests, we ignore the filters. Future tests
413- // might require implementing those.
414- go func () {
415- events := args .Get (0 ).(chan * appsv1.ApplicationWatchEvent )
416- for _ , obj := range objects {
417- app , ok := obj .(* appsv1.Application )
418- if ok {
419- oldVersion , err := strconv .Atoi (app .ResourceVersion )
420- if err != nil {
421- oldVersion = 0
422- }
423- clonedApp := app .DeepCopy ()
424- clonedApp .ResourceVersion = fmt .Sprintf ("%d" , oldVersion + 1 )
425- events <- & appsv1.ApplicationWatchEvent {Type : watch .Added , Application : * clonedApp }
426- }
427- }
428- }()
429- })
430- broadcaster .On ("OnAdd" , mock .Anything , mock .Anything ).Return ()
431- broadcaster .On ("OnUpdate" , mock .Anything , mock .Anything ).Return ()
432- broadcaster .On ("OnDelete" , mock .Anything ).Return ()
433-
416+ broadcaster := broadcasterMock {
417+ objects : objects ,
418+ }
434419 appStateCache := appstate .NewCache (cache .NewCache (cache .NewInMemoryCache (time .Hour )), time .Hour )
435420 // pre-populate the app cache
436421 for _ , obj := range objects {
0 commit comments