forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove-legacy-repo-backend
- Loading branch information
Showing
77 changed files
with
10,988 additions
and
3,406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package admin | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" | ||
fakeapps "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned/fake" | ||
cacheutil "github.com/argoproj/argo-cd/v3/util/cache" | ||
"github.com/argoproj/argo-cd/v3/util/cache/appstate" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/fake" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func Test_loadClusters(t *testing.T) { | ||
argoCDCM := &corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "argocd-cm", | ||
Namespace: "argocd", | ||
Labels: map[string]string{ | ||
"app.kubernetes.io/part-of": "argocd", | ||
}, | ||
}, | ||
Data: map[string]string{}, | ||
} | ||
argoCDSecret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "argocd-secret", | ||
Namespace: "argocd", | ||
}, | ||
Data: map[string][]byte{ | ||
"server.secretkey": []byte("test"), | ||
}, | ||
} | ||
app := &v1alpha1.Application{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "argocd", | ||
}, | ||
Spec: v1alpha1.ApplicationSpec{ | ||
Project: "default", | ||
Destination: v1alpha1.ApplicationDestination{ | ||
Server: "https://kubernetes.default.svc", | ||
Namespace: "test", | ||
}, | ||
}, | ||
} | ||
ctx := context.Background() | ||
kubeClient := fake.NewClientset(argoCDCM, argoCDSecret) | ||
appClient := fakeapps.NewSimpleClientset(app) | ||
cacheSrc := func() (*appstate.Cache, error) { | ||
return appstate.NewCache(cacheutil.NewCache(cacheutil.NewInMemoryCache(time.Minute)), time.Minute), nil | ||
} | ||
clusters, err := loadClusters(ctx, kubeClient, appClient, 3, "", "argocd", false, cacheSrc, 0, "", "", "") | ||
require.NoError(t, err) | ||
for i := range clusters { | ||
// This changes, nil it to avoid testing it. | ||
//nolint:staticcheck | ||
clusters[i].ConnectionState.ModifiedAt = nil | ||
} | ||
|
||
expected := []ClusterWithInfo{{ | ||
Cluster: v1alpha1.Cluster{ | ||
ID: "", | ||
Server: "https://kubernetes.default.svc", | ||
Name: "in-cluster", | ||
//nolint:staticcheck | ||
ConnectionState: v1alpha1.ConnectionState{ | ||
Status: "Successful", | ||
}, | ||
//nolint:staticcheck | ||
ServerVersion: ".", | ||
Shard: ptr.To(int64(0)), | ||
}, | ||
Namespaces: []string{"test"}, | ||
}} | ||
assert.Equal(t, expected, clusters) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.