@@ -1894,12 +1894,6 @@ func TestValidateGeneratedApplications(t *testing.T) {
1894
1894
err := v1alpha1 .AddToScheme (scheme )
1895
1895
require .NoError (t , err )
1896
1896
1897
- // Valid cluster
1898
- myCluster := v1alpha1.Cluster {
1899
- Server : "https://kubernetes.default.svc" ,
1900
- Name : "my-cluster" ,
1901
- }
1902
-
1903
1897
// Valid project
1904
1898
myProject := & v1alpha1.AppProject {
1905
1899
ObjectMeta : metav1.ObjectMeta {Name : "default" , Namespace : "namespace" },
@@ -2066,18 +2060,12 @@ func TestValidateGeneratedApplications(t *testing.T) {
2066
2060
objects := append ([]runtime.Object {}, secret )
2067
2061
kubeclientset := kubefake .NewSimpleClientset (objects ... )
2068
2062
2069
- argoDBMock := dbmocks.ArgoDB {}
2070
- argoDBMock .On ("GetCluster" , mock .Anything , "https://kubernetes.default.svc" ).Return (& myCluster , nil )
2071
- argoDBMock .On ("ListClusters" , mock .Anything ).Return (& v1alpha1.ClusterList {Items : []v1alpha1.Cluster {
2072
- myCluster ,
2073
- }}, nil )
2074
-
2075
2063
r := ApplicationSetReconciler {
2076
2064
Client : client ,
2077
2065
Scheme : scheme ,
2078
2066
Recorder : record .NewFakeRecorder (1 ),
2079
2067
Generators : map [string ]generators.Generator {},
2080
- ArgoDB : & argoDBMock ,
2068
+ ArgoDB : & dbmocks. ArgoDB {} ,
2081
2069
ArgoCDNamespace : "namespace" ,
2082
2070
KubeClientset : kubeclientset ,
2083
2071
Metrics : metrics ,
@@ -2159,17 +2147,9 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
2159
2147
}
2160
2148
2161
2149
kubeclientset := kubefake .NewSimpleClientset ()
2162
- argoDBMock := dbmocks.ArgoDB {}
2163
2150
2164
2151
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& appSet , & project ).WithStatusSubresource (& appSet ).WithIndex (& v1alpha1.Application {}, ".metadata.controller" , appControllerIndexer ).Build ()
2165
2152
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
2166
- goodCluster := v1alpha1.Cluster {Server : "https://good-cluster" , Name : "good-cluster" }
2167
- badCluster := v1alpha1.Cluster {Server : "https://bad-cluster" , Name : "bad-cluster" }
2168
- argoDBMock .On ("GetCluster" , mock .Anything , "https://good-cluster" ).Return (& goodCluster , nil )
2169
- argoDBMock .On ("GetCluster" , mock .Anything , "https://bad-cluster" ).Return (& badCluster , nil )
2170
- argoDBMock .On ("ListClusters" , mock .Anything ).Return (& v1alpha1.ClusterList {Items : []v1alpha1.Cluster {
2171
- goodCluster ,
2172
- }}, nil )
2173
2153
2174
2154
r := ApplicationSetReconciler {
2175
2155
Client : client ,
@@ -2179,7 +2159,7 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
2179
2159
Generators : map [string ]generators.Generator {
2180
2160
"List" : generators .NewListGenerator (),
2181
2161
},
2182
- ArgoDB : & argoDBMock ,
2162
+ ArgoDB : & dbmocks. ArgoDB {} ,
2183
2163
KubeClientset : kubeclientset ,
2184
2164
Policy : v1alpha1 .ApplicationsSyncPolicySync ,
2185
2165
ArgoCDNamespace : "argocd" ,
@@ -2363,7 +2343,6 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
2363
2343
}
2364
2344
2365
2345
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
2366
- argoDBMock := dbmocks.ArgoDB {}
2367
2346
2368
2347
for _ , testCase := range testCases {
2369
2348
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& testCase .appset ).WithIndex (& v1alpha1.Application {}, ".metadata.controller" , appControllerIndexer ).WithStatusSubresource (& testCase .appset ).Build ()
@@ -2377,7 +2356,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
2377
2356
Generators : map [string ]generators.Generator {
2378
2357
"List" : generators .NewListGenerator (),
2379
2358
},
2380
- ArgoDB : & argoDBMock ,
2359
+ ArgoDB : & dbmocks. ArgoDB {} ,
2381
2360
KubeClientset : kubeclientset ,
2382
2361
Metrics : metrics ,
2383
2362
}
@@ -2433,16 +2412,28 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
2433
2412
},
2434
2413
}
2435
2414
2436
- kubeclientset := kubefake .NewSimpleClientset ()
2437
- argoDBMock := dbmocks.ArgoDB {}
2415
+ secret := & corev1.Secret {
2416
+ ObjectMeta : metav1.ObjectMeta {
2417
+ Name : "my-cluster" ,
2418
+ Namespace : "argocd" ,
2419
+ Labels : map [string ]string {
2420
+ argocommon .LabelKeySecretType : argocommon .LabelValueSecretTypeCluster ,
2421
+ },
2422
+ },
2423
+ Data : map [string ][]byte {
2424
+ // Since this test requires the cluster to be an invalid destination, we
2425
+ // always return a cluster named 'my-cluster2' (different from app 'my-cluster', above)
2426
+ "name" : []byte ("good-cluster" ),
2427
+ "server" : []byte ("https://good-cluster" ),
2428
+ "config" : []byte ("{\" username\" :\" foo\" ,\" password\" :\" foo\" }" ),
2429
+ },
2430
+ }
2431
+
2432
+ objects := append ([]runtime.Object {}, secret )
2433
+ kubeclientset := kubefake .NewSimpleClientset (objects ... )
2438
2434
2439
2435
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& appSet , & defaultProject ).WithStatusSubresource (& appSet ).WithIndex (& v1alpha1.Application {}, ".metadata.controller" , appControllerIndexer ).Build ()
2440
2436
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
2441
- goodCluster := v1alpha1.Cluster {Server : "https://good-cluster" , Name : "good-cluster" }
2442
- argoDBMock .On ("GetCluster" , mock .Anything , "https://good-cluster" ).Return (& goodCluster , nil )
2443
- argoDBMock .On ("ListClusters" , mock .Anything ).Return (& v1alpha1.ClusterList {Items : []v1alpha1.Cluster {
2444
- goodCluster ,
2445
- }}, nil )
2446
2437
2447
2438
r := ApplicationSetReconciler {
2448
2439
Client : client ,
@@ -2452,7 +2443,7 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
2452
2443
Generators : map [string ]generators.Generator {
2453
2444
"List" : generators .NewListGenerator (),
2454
2445
},
2455
- ArgoDB : & argoDBMock ,
2446
+ ArgoDB : & dbmocks. ArgoDB {} ,
2456
2447
ArgoCDNamespace : "argocd" ,
2457
2448
KubeClientset : kubeclientset ,
2458
2449
Policy : v1alpha1 .ApplicationsSyncPolicySync ,
@@ -2595,16 +2586,28 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
2595
2586
},
2596
2587
}
2597
2588
2598
- kubeclientset := kubefake .NewSimpleClientset ()
2599
- argoDBMock := dbmocks.ArgoDB {}
2589
+ secret := & corev1.Secret {
2590
+ ObjectMeta : metav1.ObjectMeta {
2591
+ Name : "my-cluster" ,
2592
+ Namespace : "argocd" ,
2593
+ Labels : map [string ]string {
2594
+ argocommon .LabelKeySecretType : argocommon .LabelValueSecretTypeCluster ,
2595
+ },
2596
+ },
2597
+ Data : map [string ][]byte {
2598
+ // Since this test requires the cluster to be an invalid destination, we
2599
+ // always return a cluster named 'my-cluster2' (different from app 'my-cluster', above)
2600
+ "name" : []byte ("good-cluster" ),
2601
+ "server" : []byte ("https://good-cluster" ),
2602
+ "config" : []byte ("{\" username\" :\" foo\" ,\" password\" :\" foo\" }" ),
2603
+ },
2604
+ }
2605
+
2606
+ objects := append ([]runtime.Object {}, secret )
2607
+ kubeclientset := kubefake .NewSimpleClientset (objects ... )
2600
2608
2601
2609
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& appSet , & defaultProject ).WithStatusSubresource (& appSet ).WithIndex (& v1alpha1.Application {}, ".metadata.controller" , appControllerIndexer ).Build ()
2602
2610
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
2603
- goodCluster := v1alpha1.Cluster {Server : "https://good-cluster" , Name : "good-cluster" }
2604
- argoDBMock .On ("GetCluster" , mock .Anything , "https://good-cluster" ).Return (& goodCluster , nil )
2605
- argoDBMock .On ("ListClusters" , mock .Anything ).Return (& v1alpha1.ClusterList {Items : []v1alpha1.Cluster {
2606
- goodCluster ,
2607
- }}, nil )
2608
2611
2609
2612
r := ApplicationSetReconciler {
2610
2613
Client : client ,
@@ -2614,7 +2617,7 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
2614
2617
Generators : map [string ]generators.Generator {
2615
2618
"List" : generators .NewListGenerator (),
2616
2619
},
2617
- ArgoDB : & argoDBMock ,
2620
+ ArgoDB : & dbmocks. ArgoDB {} ,
2618
2621
ArgoCDNamespace : "argocd" ,
2619
2622
KubeClientset : kubeclientset ,
2620
2623
Policy : v1alpha1 .ApplicationsSyncPolicySync ,
@@ -2689,23 +2692,23 @@ func TestDeletePerformedWithSyncPolicyCreateDelete(t *testing.T) {
2689
2692
2690
2693
apps := applicationsDeleteSyncPolicyTest (t , applicationsSyncPolicy , 3 , true )
2691
2694
2692
- assert .Empty (t , apps .Items )
2695
+ assert .NotNil (t , apps .Items [ 0 ]. DeletionTimestamp )
2693
2696
}
2694
2697
2695
2698
func TestDeletePerformedWithSyncPolicySync (t * testing.T ) {
2696
2699
applicationsSyncPolicy := v1alpha1 .ApplicationsSyncPolicySync
2697
2700
2698
2701
apps := applicationsDeleteSyncPolicyTest (t , applicationsSyncPolicy , 3 , true )
2699
2702
2700
- assert .Empty (t , apps .Items )
2703
+ assert .NotNil (t , apps .Items [ 0 ]. DeletionTimestamp )
2701
2704
}
2702
2705
2703
2706
func TestDeletePerformedWithSyncPolicyCreateOnlyAndAllowPolicyOverrideFalse (t * testing.T ) {
2704
2707
applicationsSyncPolicy := v1alpha1 .ApplicationsSyncPolicyCreateOnly
2705
2708
2706
2709
apps := applicationsDeleteSyncPolicyTest (t , applicationsSyncPolicy , 3 , false )
2707
2710
2708
- assert .Empty (t , apps .Items )
2711
+ assert .NotNil (t , apps .Items [ 0 ]. DeletionTimestamp )
2709
2712
}
2710
2713
2711
2714
func TestPolicies (t * testing.T ) {
@@ -2717,14 +2720,8 @@ func TestPolicies(t *testing.T) {
2717
2720
ObjectMeta : metav1.ObjectMeta {Name : "default" , Namespace : "argocd" },
2718
2721
Spec : v1alpha1.AppProjectSpec {SourceRepos : []string {"*" }, Destinations : []v1alpha1.ApplicationDestination {{Namespace : "*" , Server : "https://kubernetes.default.svc" }}},
2719
2722
}
2720
- myCluster := v1alpha1.Cluster {
2721
- Server : "https://kubernetes.default.svc" ,
2722
- Name : "my-cluster" ,
2723
- }
2724
2723
2725
2724
kubeclientset := kubefake .NewSimpleClientset ()
2726
- argoDBMock := dbmocks.ArgoDB {}
2727
- argoDBMock .On ("GetCluster" , mock .Anything , "https://kubernetes.default.svc" ).Return (& myCluster , nil )
2728
2725
2729
2726
for _ , c := range []struct {
2730
2727
name string
@@ -2807,7 +2804,7 @@ func TestPolicies(t *testing.T) {
2807
2804
Generators : map [string ]generators.Generator {
2808
2805
"List" : generators .NewListGenerator (),
2809
2806
},
2810
- ArgoDB : & argoDBMock ,
2807
+ ArgoDB : & dbmocks. ArgoDB {} ,
2811
2808
ArgoCDNamespace : "argocd" ,
2812
2809
KubeClientset : kubeclientset ,
2813
2810
Policy : policy ,
@@ -2881,7 +2878,6 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
2881
2878
require .NoError (t , err )
2882
2879
2883
2880
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
2884
- argoDBMock := dbmocks.ArgoDB {}
2885
2881
2886
2882
for _ , cc := range []struct {
2887
2883
name string
@@ -2965,7 +2961,7 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
2965
2961
Generators : map [string ]generators.Generator {
2966
2962
"List" : generators .NewListGenerator (),
2967
2963
},
2968
- ArgoDB : & argoDBMock ,
2964
+ ArgoDB : & dbmocks. ArgoDB {} ,
2969
2965
KubeClientset : kubeclientset ,
2970
2966
Metrics : metrics ,
2971
2967
}
@@ -3714,14 +3710,13 @@ func TestBuildAppDependencyList(t *testing.T) {
3714
3710
} {
3715
3711
t .Run (cc .name , func (t * testing.T ) {
3716
3712
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
3717
- argoDBMock := dbmocks.ArgoDB {}
3718
3713
3719
3714
r := ApplicationSetReconciler {
3720
3715
Client : client ,
3721
3716
Scheme : scheme ,
3722
3717
Recorder : record .NewFakeRecorder (1 ),
3723
3718
Generators : map [string ]generators.Generator {},
3724
- ArgoDB : & argoDBMock ,
3719
+ ArgoDB : & dbmocks. ArgoDB {} ,
3725
3720
KubeClientset : kubeclientset ,
3726
3721
Metrics : metrics ,
3727
3722
}
@@ -4381,14 +4376,13 @@ func TestBuildAppSyncMap(t *testing.T) {
4381
4376
} {
4382
4377
t .Run (cc .name , func (t * testing.T ) {
4383
4378
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
4384
- argoDBMock := dbmocks.ArgoDB {}
4385
4379
4386
4380
r := ApplicationSetReconciler {
4387
4381
Client : client ,
4388
4382
Scheme : scheme ,
4389
4383
Recorder : record .NewFakeRecorder (1 ),
4390
4384
Generators : map [string ]generators.Generator {},
4391
- ArgoDB : & argoDBMock ,
4385
+ ArgoDB : & dbmocks. ArgoDB {} ,
4392
4386
KubeClientset : kubeclientset ,
4393
4387
Metrics : metrics ,
4394
4388
}
@@ -5326,7 +5320,6 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
5326
5320
} {
5327
5321
t .Run (cc .name , func (t * testing.T ) {
5328
5322
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
5329
- argoDBMock := dbmocks.ArgoDB {}
5330
5323
5331
5324
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& cc .appSet ).WithStatusSubresource (& cc .appSet ).Build ()
5332
5325
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
@@ -5336,7 +5329,7 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
5336
5329
Scheme : scheme ,
5337
5330
Recorder : record .NewFakeRecorder (1 ),
5338
5331
Generators : map [string ]generators.Generator {},
5339
- ArgoDB : & argoDBMock ,
5332
+ ArgoDB : & dbmocks. ArgoDB {} ,
5340
5333
KubeClientset : kubeclientset ,
5341
5334
Metrics : metrics ,
5342
5335
}
@@ -6075,7 +6068,6 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
6075
6068
} {
6076
6069
t .Run (cc .name , func (t * testing.T ) {
6077
6070
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
6078
- argoDBMock := dbmocks.ArgoDB {}
6079
6071
6080
6072
client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& cc .appSet ).WithStatusSubresource (& cc .appSet ).Build ()
6081
6073
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
@@ -6085,7 +6077,7 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
6085
6077
Scheme : scheme ,
6086
6078
Recorder : record .NewFakeRecorder (1 ),
6087
6079
Generators : map [string ]generators.Generator {},
6088
- ArgoDB : & argoDBMock ,
6080
+ ArgoDB : & dbmocks. ArgoDB {} ,
6089
6081
KubeClientset : kubeclientset ,
6090
6082
Metrics : metrics ,
6091
6083
}
@@ -6286,7 +6278,6 @@ func TestUpdateResourceStatus(t *testing.T) {
6286
6278
} {
6287
6279
t .Run (cc .name , func (t * testing.T ) {
6288
6280
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
6289
- argoDBMock := dbmocks.ArgoDB {}
6290
6281
6291
6282
client := fake .NewClientBuilder ().WithScheme (scheme ).WithStatusSubresource (& cc .appSet ).WithObjects (& cc .appSet ).Build ()
6292
6283
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
@@ -6296,7 +6287,7 @@ func TestUpdateResourceStatus(t *testing.T) {
6296
6287
Scheme : scheme ,
6297
6288
Recorder : record .NewFakeRecorder (1 ),
6298
6289
Generators : map [string ]generators.Generator {},
6299
- ArgoDB : & argoDBMock ,
6290
+ ArgoDB : & dbmocks. ArgoDB {} ,
6300
6291
KubeClientset : kubeclientset ,
6301
6292
Metrics : metrics ,
6302
6293
}
@@ -6376,7 +6367,6 @@ func TestResourceStatusAreOrdered(t *testing.T) {
6376
6367
} {
6377
6368
t .Run (cc .name , func (t * testing.T ) {
6378
6369
kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
6379
- argoDBMock := dbmocks.ArgoDB {}
6380
6370
6381
6371
client := fake .NewClientBuilder ().WithScheme (scheme ).WithStatusSubresource (& cc .appSet ).WithObjects (& cc .appSet ).Build ()
6382
6372
metrics := appsetmetrics .NewFakeAppsetMetrics (client )
@@ -6386,7 +6376,7 @@ func TestResourceStatusAreOrdered(t *testing.T) {
6386
6376
Scheme : scheme ,
6387
6377
Recorder : record .NewFakeRecorder (1 ),
6388
6378
Generators : map [string ]generators.Generator {},
6389
- ArgoDB : & argoDBMock ,
6379
+ ArgoDB : & dbmocks. ArgoDB {} ,
6390
6380
KubeClientset : kubeclientset ,
6391
6381
Metrics : metrics ,
6392
6382
}
0 commit comments