Skip to content

Commit

Permalink
Fix unit tests for clusterinfoupdater
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <[email protected]>
  • Loading branch information
chetan-rns committed May 30, 2024
1 parent 8dde212 commit cd0f052
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion controller/clusterinfoupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 20 additions & 3 deletions controller/clusterinfoupdater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cd0f052

Please sign in to comment.