From cd0f05216763768bb63b1e4222afd57f60af9e77 Mon Sep 17 00:00:00 2001 From: Chetan Banavikalmutt Date: Thu, 30 May 2024 16:47:46 +0530 Subject: [PATCH] Fix unit tests for clusterinfoupdater Signed-off-by: Chetan Banavikalmutt --- controller/clusterinfoupdater.go | 3 ++- controller/clusterinfoupdater_test.go | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/controller/clusterinfoupdater.go b/controller/clusterinfoupdater.go index bf07f8cc709e5..6dced80b14bd9 100644 --- a/controller/clusterinfoupdater.go +++ b/controller/clusterinfoupdater.go @@ -3,9 +3,10 @@ package controller import ( "context" "fmt" - "github.com/argoproj/argo-cd/v2/common" "time" + "github.com/argoproj/argo-cd/v2/common" + "github.com/argoproj/argo-cd/v2/util/env" "github.com/argoproj/gitops-engine/pkg/cache" "github.com/argoproj/gitops-engine/pkg/utils/kube" diff --git a/controller/clusterinfoupdater_test.go b/controller/clusterinfoupdater_test.go index d11d4412bf30c..f67e6fc7775cb 100644 --- a/controller/clusterinfoupdater_test.go +++ b/controller/clusterinfoupdater_test.go @@ -36,11 +36,13 @@ func TestClusterSecretUpdater(t *testing.T) { var tests = []struct { LastCacheSyncTime *time.Time SyncError error + ConnectionStatus clustercache.ConnectionStatus ExpectedStatus v1alpha1.ConnectionStatus }{ - {nil, nil, v1alpha1.ConnectionStatusUnknown}, - {&now, nil, v1alpha1.ConnectionStatusSuccessful}, - {&now, fmt.Errorf("sync failed"), v1alpha1.ConnectionStatusFailed}, + {nil, nil, clustercache.ConnectionStatusUnknown, v1alpha1.ConnectionStatusUnknown}, + {&now, nil, clustercache.ConnectionStatusSuccessful, v1alpha1.ConnectionStatusSuccessful}, + {&now, fmt.Errorf("sync failed"), clustercache.ConnectionStatusSuccessful, v1alpha1.ConnectionStatusFailed}, + {&now, nil, clustercache.ConnectionStatusFailed, v1alpha1.ConnectionStatusFailed}, } emptyArgoCDConfigMap := &v1.ConfigMap{ @@ -78,12 +80,27 @@ func TestClusterSecretUpdater(t *testing.T) { cluster, err := argoDB.CreateCluster(ctx, &v1alpha1.Cluster{Server: "http://minikube"}) assert.NoError(t, err, "Test prepare test data create cluster failed") + fakeApp := &v1alpha1.Application{ + ObjectMeta: metav1.ObjectMeta{ + Name: "fake-app", + Namespace: fakeNamespace, + }, + Spec: v1alpha1.ApplicationSpec{ + Destination: v1alpha1.ApplicationDestination{ + Server: cluster.Server, + }, + }, + } + err = appInformer.GetIndexer().Add(fakeApp) + assert.NoError(t, err) + for _, test := range tests { info := &clustercache.ClusterInfo{ Server: cluster.Server, K8SVersion: updatedK8sVersion, LastCacheSyncTime: test.LastCacheSyncTime, SyncError: test.SyncError, + ConnectionStatus: test.ConnectionStatus, } lister := applisters.NewApplicationLister(appInformer.GetIndexer()).Applications(fakeNamespace)