@@ -320,11 +320,11 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) {
320320 t .Run (testCaseCopy .name , func (t * testing.T ) {
321321 t .Parallel ()
322322
323- argoCDServiceMock := mocks.Repos {}
323+ argoCDServiceMock := mocks .NewRepos ( t )
324324
325325 argoCDServiceMock .On ("GetDirectories" , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (testCaseCopy .repoApps , testCaseCopy .repoError )
326326
327- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
327+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
328328 applicationSetInfo := v1alpha1.ApplicationSet {
329329 ObjectMeta : metav1.ObjectMeta {
330330 Name : "set" ,
@@ -623,11 +623,11 @@ func TestGitGenerateParamsFromDirectoriesGoTemplate(t *testing.T) {
623623 t .Run (testCaseCopy .name , func (t * testing.T ) {
624624 t .Parallel ()
625625
626- argoCDServiceMock := mocks.Repos {}
626+ argoCDServiceMock := mocks .NewRepos ( t )
627627
628628 argoCDServiceMock .On ("GetDirectories" , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (testCaseCopy .repoApps , testCaseCopy .repoError )
629629
630- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
630+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
631631 applicationSetInfo := v1alpha1.ApplicationSet {
632632 ObjectMeta : metav1.ObjectMeta {
633633 Name : "set" ,
@@ -1000,11 +1000,11 @@ cluster:
10001000 t .Run (testCaseCopy .name , func (t * testing.T ) {
10011001 t .Parallel ()
10021002
1003- argoCDServiceMock := mocks.Repos {}
1003+ argoCDServiceMock := mocks .NewRepos ( t )
10041004 argoCDServiceMock .On ("GetFiles" , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
10051005 Return (testCaseCopy .repoFileContents , testCaseCopy .repoPathsError )
10061006
1007- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
1007+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
10081008 applicationSetInfo := v1alpha1.ApplicationSet {
10091009 ObjectMeta : metav1.ObjectMeta {
10101010 Name : "set" ,
@@ -1331,7 +1331,7 @@ env: testing
13311331 t .Run (testCaseCopy .name , func (t * testing.T ) {
13321332 t .Parallel ()
13331333
1334- argoCDServiceMock := mocks.Repos {}
1334+ argoCDServiceMock := mocks .NewRepos ( t )
13351335
13361336 // IMPORTANT: we try to get the files from the repo server that matches the patterns
13371337 // If we find those files also satisfy the exclude pattern, we remove them from map
@@ -1350,7 +1350,7 @@ env: testing
13501350 Return (testCaseCopy .includeFiles , testCaseCopy .repoPathsError )
13511351 }
13521352
1353- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
1353+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
13541354 applicationSetInfo := v1alpha1.ApplicationSet {
13551355 ObjectMeta : metav1.ObjectMeta {
13561356 Name : "set" ,
@@ -1672,7 +1672,7 @@ env: testing
16721672 t .Run (testCaseCopy .name , func (t * testing.T ) {
16731673 t .Parallel ()
16741674
1675- argoCDServiceMock := mocks.Repos {}
1675+ argoCDServiceMock := mocks .NewRepos ( t )
16761676
16771677 // IMPORTANT: we try to get the files from the repo server that matches the patterns
16781678 // If we find those files also satisfy the exclude pattern, we remove them from map
@@ -1691,7 +1691,7 @@ env: testing
16911691 Return (testCaseCopy .includeFiles , testCaseCopy .repoPathsError )
16921692 }
16931693
1694- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
1694+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
16951695 applicationSetInfo := v1alpha1.ApplicationSet {
16961696 ObjectMeta : metav1.ObjectMeta {
16971697 Name : "set" ,
@@ -1908,7 +1908,7 @@ func TestGitGeneratorParamsFromFilesWithExcludeOptionGoTemplate(t *testing.T) {
19081908 t .Run (testCaseCopy .name , func (t * testing.T ) {
19091909 t .Parallel ()
19101910
1911- argoCDServiceMock := mocks.Repos {}
1911+ argoCDServiceMock := mocks .NewRepos ( t )
19121912 // IMPORTANT: we try to get the files from the repo server that matches the patterns
19131913 // If we find those files also satisfy the exclude pattern, we remove them from map
19141914 // This is generally done by the g.repos.GetFiles() function.
@@ -1926,7 +1926,7 @@ func TestGitGeneratorParamsFromFilesWithExcludeOptionGoTemplate(t *testing.T) {
19261926 Return (testCaseCopy .includeFiles , testCaseCopy .repoPathsError )
19271927 }
19281928
1929- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
1929+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
19301930 applicationSetInfo := v1alpha1.ApplicationSet {
19311931 ObjectMeta : metav1.ObjectMeta {
19321932 Name : "set" ,
@@ -2279,11 +2279,11 @@ cluster:
22792279 t .Run (testCaseCopy .name , func (t * testing.T ) {
22802280 t .Parallel ()
22812281
2282- argoCDServiceMock := mocks.Repos {}
2282+ argoCDServiceMock := mocks .NewRepos ( t )
22832283 argoCDServiceMock .On ("GetFiles" , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
22842284 Return (testCaseCopy .repoFileContents , testCaseCopy .repoPathsError )
22852285
2286- gitGenerator := NewGitGenerator (& argoCDServiceMock , "" )
2286+ gitGenerator := NewGitGenerator (argoCDServiceMock , "" )
22872287 applicationSetInfo := v1alpha1.ApplicationSet {
22882288 ObjectMeta : metav1.ObjectMeta {
22892289 Name : "set" ,
@@ -2482,35 +2482,37 @@ func TestGitGenerator_GenerateParams(t *testing.T) {
24822482 },
24832483 }
24842484 for _ , testCase := range cases {
2485- argoCDServiceMock := mocks.Repos {}
2485+ t .Run (testCase .name , func (t * testing.T ) {
2486+ argoCDServiceMock := mocks .NewRepos (t )
2487+
2488+ if testCase .callGetDirectories {
2489+ var project any
2490+ if testCase .expectedProject != nil {
2491+ project = * testCase .expectedProject
2492+ } else {
2493+ project = mock .Anything
2494+ }
24862495
2487- if testCase .callGetDirectories {
2488- var project any
2489- if testCase .expectedProject != nil {
2490- project = * testCase .expectedProject
2491- } else {
2492- project = mock .Anything
2496+ argoCDServiceMock .On ("GetDirectories" , mock .Anything , mock .Anything , mock .Anything , project , mock .Anything , mock .Anything ).Return (testCase .repoApps , testCase .repoPathsError )
24932497 }
2498+ gitGenerator := NewGitGenerator (argoCDServiceMock , "argocd" )
24942499
2495- argoCDServiceMock .On ("GetDirectories" , mock .Anything , mock .Anything , mock .Anything , project , mock .Anything , mock .Anything ).Return (testCase .repoApps , testCase .repoPathsError )
2496- }
2497- gitGenerator := NewGitGenerator (& argoCDServiceMock , "argocd" )
2498-
2499- scheme := runtime .NewScheme ()
2500- err := v1alpha1 .AddToScheme (scheme )
2501- require .NoError (t , err )
2500+ scheme := runtime .NewScheme ()
2501+ err := v1alpha1 .AddToScheme (scheme )
2502+ require .NoError (t , err )
25022503
2503- client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& testCase .appProject ).Build ()
2504+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& testCase .appProject ).Build ()
25042505
2505- got , err := gitGenerator .GenerateParams (& testCase .appset .Spec .Generators [0 ], & testCase .appset , client )
2506+ got , err := gitGenerator .GenerateParams (& testCase .appset .Spec .Generators [0 ], & testCase .appset , client )
25062507
2507- if testCase .expectedError != nil {
2508- require .EqualError (t , err , testCase .expectedError .Error ())
2509- } else {
2510- require .NoError (t , err )
2511- assert .Equal (t , testCase .expected , got )
2512- }
2508+ if testCase .expectedError != nil {
2509+ require .EqualError (t , err , testCase .expectedError .Error ())
2510+ } else {
2511+ require .NoError (t , err )
2512+ assert .Equal (t , testCase .expected , got )
2513+ }
25132514
2514- argoCDServiceMock .AssertExpectations (t )
2515+ argoCDServiceMock .AssertExpectations (t )
2516+ })
25152517 }
25162518}
0 commit comments