@@ -276,6 +276,72 @@ func TestGitHubCommitEvent_AppsInOtherNamespaces(t *testing.T) {
276
276
hook .Reset ()
277
277
}
278
278
279
+ // TestGitHubCommitEvent_Hydrate makes sure that a webhook will hydrate an app when dry source changed.
280
+ func TestGitHubCommitEvent_Hydrate (t * testing.T ) {
281
+ hook := test .NewGlobal ()
282
+ var patched bool
283
+ reaction := func (action kubetesting.Action ) (handled bool , ret runtime.Object , err error ) {
284
+ patchAction := action .(kubetesting.PatchAction )
285
+ assert .Equal (t , "app-to-hydrate" , patchAction .GetName ())
286
+ patched = true
287
+ return true , nil , nil
288
+ }
289
+ h := NewMockHandler (& reactorDef {"patch" , "applications" , reaction }, []string {}, & v1alpha1.Application {
290
+ ObjectMeta : metav1.ObjectMeta {
291
+ Name : "app-to-hydrate" ,
292
+ Namespace : "argocd" ,
293
+ },
294
+ Spec : v1alpha1.ApplicationSpec {
295
+ SourceHydrator : & v1alpha1.SourceHydrator {
296
+ DrySource : v1alpha1.DrySource {
297
+ RepoURL : "https://github.com/jessesuen/test-repo" ,
298
+ TargetRevision : "HEAD" ,
299
+ Path : "." ,
300
+ },
301
+ SyncSource : v1alpha1.SyncSource {
302
+ TargetBranch : "environments/dev" ,
303
+ Path : "." ,
304
+ },
305
+ HydrateTo : nil ,
306
+ },
307
+ },
308
+ }, & v1alpha1.Application {
309
+ ObjectMeta : metav1.ObjectMeta {
310
+ Name : "app-to-ignore" ,
311
+ },
312
+ Spec : v1alpha1.ApplicationSpec {
313
+ Sources : v1alpha1.ApplicationSources {
314
+ {
315
+ RepoURL : "https://github.com/some/unrelated-repo" ,
316
+ Path : "." ,
317
+ },
318
+ },
319
+ },
320
+ },
321
+ )
322
+ req := httptest .NewRequest (http .MethodPost , "/api/webhook" , nil )
323
+ req .Header .Set ("X-GitHub-Event" , "push" )
324
+ eventJSON , err := os .ReadFile ("testdata/github-commit-event.json" )
325
+ require .NoError (t , err )
326
+ req .Body = io .NopCloser (bytes .NewReader (eventJSON ))
327
+ w := httptest .NewRecorder ()
328
+ h .Handler (w , req )
329
+ close (h .queue )
330
+ h .Wait ()
331
+ assert .Equal (t , http .StatusOK , w .Code )
332
+ assert .True (t , patched )
333
+
334
+ logMessages := make ([]string , 0 , len (hook .Entries ))
335
+ for _ , entry := range hook .Entries {
336
+ logMessages = append (logMessages , entry .Message )
337
+ }
338
+
339
+ assert .Contains (t , logMessages , "webhook trigger refresh app to hydrate 'app-to-hydrate'" )
340
+ assert .NotContains (t , logMessages , "webhook trigger refresh app to hydrate 'app-to-ignore'" )
341
+
342
+ hook .Reset ()
343
+ }
344
+
279
345
func TestGitHubTagEvent (t * testing.T ) {
280
346
hook := test .NewGlobal ()
281
347
h := NewMockHandler (nil , []string {})
0 commit comments