mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
Signed-off-by: Andrii Korotkov <andrii.korotkov@verkada.com>
This commit is contained in:
parent
a8b76f2951
commit
62ec9fef36
41 changed files with 344 additions and 289 deletions
|
|
@ -19,7 +19,6 @@ import (
|
|||
sessionpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/session"
|
||||
"github.com/argoproj/argo-cd/v3/server/session"
|
||||
"github.com/argoproj/argo-cd/v3/test"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/password"
|
||||
"github.com/argoproj/argo-cd/v3/util/rbac"
|
||||
sessionutil "github.com/argoproj/argo-cd/v3/util/session"
|
||||
|
|
@ -31,15 +30,17 @@ const (
|
|||
)
|
||||
|
||||
// return an AccountServer which returns fake data
|
||||
func newTestAccountServer(ctx context.Context, opts ...func(cm *corev1.ConfigMap, secret *corev1.Secret)) (*Server, *session.Server) {
|
||||
return newTestAccountServerExt(ctx, func(_ jwt.Claims, _ ...any) bool {
|
||||
func newTestAccountServer(t *testing.T, ctx context.Context, opts ...func(cm *corev1.ConfigMap, secret *corev1.Secret)) (*Server, *session.Server) {
|
||||
t.Helper()
|
||||
return newTestAccountServerExt(t, ctx, func(_ jwt.Claims, _ ...any) bool {
|
||||
return true
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
func newTestAccountServerExt(ctx context.Context, enforceFn rbac.ClaimsEnforcerFunc, opts ...func(cm *corev1.ConfigMap, secret *corev1.Secret)) (*Server, *session.Server) {
|
||||
func newTestAccountServerExt(t *testing.T, ctx context.Context, enforceFn rbac.ClaimsEnforcerFunc, opts ...func(cm *corev1.ConfigMap, secret *corev1.Secret)) (*Server, *session.Server) {
|
||||
t.Helper()
|
||||
bcrypt, err := password.HashPassword("oldpassword")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "argocd-cm",
|
||||
|
|
@ -104,7 +105,7 @@ func projTokenContext(ctx context.Context) context.Context {
|
|||
}
|
||||
|
||||
func TestUpdatePassword(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(context.Background())
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background())
|
||||
ctx := adminContext(context.Background())
|
||||
var err error
|
||||
|
||||
|
|
@ -140,7 +141,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdatePassword_AdminUpdatesAnotherUser(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := adminContext(context.Background())
|
||||
|
|
@ -158,7 +159,7 @@ func TestUpdatePassword_DoesNotHavePermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("LocalAccountUpdatesAnotherAccount", func(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServerExt(context.Background(), enforcer, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := adminContext(context.Background())
|
||||
|
|
@ -167,7 +168,7 @@ func TestUpdatePassword_DoesNotHavePermissions(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("SSOAccountWithTheSameName", func(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServerExt(context.Background(), enforcer)
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer)
|
||||
ctx := ssoAdminContext(context.Background(), time.Now())
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "admin"})
|
||||
assert.ErrorContains(t, err, "permission denied")
|
||||
|
|
@ -175,7 +176,7 @@ func TestUpdatePassword_DoesNotHavePermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdatePassword_ProjectToken(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := projTokenContext(context.Background())
|
||||
|
|
@ -184,7 +185,7 @@ func TestUpdatePassword_ProjectToken(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdatePassword_OldSSOToken(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := ssoAdminContext(context.Background(), time.Now().Add(-2*common.ChangePasswordSSOTokenMaxAge))
|
||||
|
|
@ -194,7 +195,7 @@ func TestUpdatePassword_OldSSOToken(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdatePassword_SSOUserUpdatesAnotherUser(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := ssoAdminContext(context.Background(), time.Now())
|
||||
|
|
@ -209,7 +210,7 @@ func TestUpdatePassword_SSOUserUpdatesAnotherUser(t *testing.T) {
|
|||
func TestListAccounts_NoAccountsConfigured(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
|
||||
accountServer, _ := newTestAccountServer(ctx)
|
||||
accountServer, _ := newTestAccountServer(t, ctx)
|
||||
resp, err := accountServer.ListAccounts(ctx, &account.ListAccountRequest{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, resp.Items, 1)
|
||||
|
|
@ -217,7 +218,7 @@ func TestListAccounts_NoAccountsConfigured(t *testing.T) {
|
|||
|
||||
func TestListAccounts_AccountsAreConfigured(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
cm.Data["accounts.account2"] = "login, apiKey"
|
||||
cm.Data["accounts.account2.enabled"] = "false"
|
||||
|
|
@ -235,7 +236,7 @@ func TestListAccounts_AccountsAreConfigured(t *testing.T) {
|
|||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
||||
|
|
@ -255,7 +256,7 @@ func TestGetAccount(t *testing.T) {
|
|||
|
||||
func TestCreateToken_SuccessfullyCreated(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
||||
|
|
@ -270,7 +271,7 @@ func TestCreateToken_SuccessfullyCreated(t *testing.T) {
|
|||
|
||||
func TestCreateToken_DoesNotHaveCapability(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "login"
|
||||
})
|
||||
|
||||
|
|
@ -280,7 +281,7 @@ func TestCreateToken_DoesNotHaveCapability(t *testing.T) {
|
|||
|
||||
func TestCreateToken_UserSpecifiedID(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
||||
|
|
@ -294,7 +295,7 @@ func TestCreateToken_UserSpecifiedID(t *testing.T) {
|
|||
|
||||
func TestDeleteToken_SuccessfullyRemoved(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, _ := newTestAccountServer(ctx, func(cm *corev1.ConfigMap, secret *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, secret *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
secret.Data["accounts.account1.tokens"] = []byte(`[{"id":"123","iat":1583789194,"exp":1583789194}]`)
|
||||
})
|
||||
|
|
@ -309,7 +310,7 @@ func TestDeleteToken_SuccessfullyRemoved(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCanI_GetLogsAllow(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(context.Background(), func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
})
|
||||
|
||||
ctx := projTokenContext(context.Background())
|
||||
|
|
@ -323,7 +324,7 @@ func TestCanI_GetLogsDeny(t *testing.T) {
|
|||
return false
|
||||
}
|
||||
|
||||
accountServer, _ := newTestAccountServerExt(context.Background(), enforcer, func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer, func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
})
|
||||
|
||||
ctx := projTokenContext(context.Background())
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ import (
|
|||
"github.com/argoproj/argo-cd/v3/util/cache"
|
||||
"github.com/argoproj/argo-cd/v3/util/cache/appstate"
|
||||
"github.com/argoproj/argo-cd/v3/util/db"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/grpc"
|
||||
"github.com/argoproj/argo-cd/v3/util/rbac"
|
||||
"github.com/argoproj/argo-cd/v3/util/settings"
|
||||
|
|
@ -188,9 +187,9 @@ func newTestAppServerWithEnforcerConfigure(t *testing.T, f func(*rbac.Enforcer),
|
|||
ctx := context.Background()
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(ctx, kubeclientset, testNamespace), kubeclientset)
|
||||
_, err := db.CreateRepository(ctx, fakeRepo())
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
_, err = db.CreateCluster(ctx, fakeCluster())
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockRepoClient := &mocks.Clientset{RepoServerServiceClient: fakeRepoServerClient(false)}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/argoproj/argo-cd/v3/util/argo"
|
||||
"github.com/argoproj/argo-cd/v3/util/assets"
|
||||
"github.com/argoproj/argo-cd/v3/util/db"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/rbac"
|
||||
"github.com/argoproj/argo-cd/v3/util/settings"
|
||||
)
|
||||
|
|
@ -52,26 +51,29 @@ func fakeCluster() *appsv1.Cluster {
|
|||
}
|
||||
|
||||
// return an ApplicationServiceServer which returns fake data
|
||||
func newTestAppSetServer(objects ...runtime.Object) *Server {
|
||||
func newTestAppSetServer(t *testing.T, objects ...runtime.Object) *Server {
|
||||
t.Helper()
|
||||
f := func(enf *rbac.Enforcer) {
|
||||
_ = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV)
|
||||
enf.SetDefaultRole("role:admin")
|
||||
}
|
||||
scopedNamespaces := ""
|
||||
return newTestAppSetServerWithEnforcerConfigure(f, scopedNamespaces, objects...)
|
||||
return newTestAppSetServerWithEnforcerConfigure(t, f, scopedNamespaces, objects...)
|
||||
}
|
||||
|
||||
// return an ApplicationServiceServer which returns fake data
|
||||
func newTestNamespacedAppSetServer(objects ...runtime.Object) *Server {
|
||||
func newTestNamespacedAppSetServer(t *testing.T, objects ...runtime.Object) *Server {
|
||||
t.Helper()
|
||||
f := func(enf *rbac.Enforcer) {
|
||||
_ = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV)
|
||||
enf.SetDefaultRole("role:admin")
|
||||
}
|
||||
scopedNamespaces := "argocd"
|
||||
return newTestAppSetServerWithEnforcerConfigure(f, scopedNamespaces, objects...)
|
||||
return newTestAppSetServerWithEnforcerConfigure(t, f, scopedNamespaces, objects...)
|
||||
}
|
||||
|
||||
func newTestAppSetServerWithEnforcerConfigure(f func(*rbac.Enforcer), namespace string, objects ...runtime.Object) *Server {
|
||||
func newTestAppSetServerWithEnforcerConfigure(t *testing.T, f func(*rbac.Enforcer), namespace string, objects ...runtime.Object) *Server {
|
||||
t.Helper()
|
||||
kubeclientset := fake.NewClientset(&corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
|
|
@ -93,9 +95,9 @@ func newTestAppSetServerWithEnforcerConfigure(f func(*rbac.Enforcer), namespace
|
|||
ctx := context.Background()
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(ctx, kubeclientset, testNamespace), kubeclientset)
|
||||
_, err := db.CreateRepository(ctx, fakeRepo())
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
_, err = db.CreateCluster(ctx, fakeCluster())
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
defaultProj := &appsv1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "default"},
|
||||
|
|
@ -274,7 +276,7 @@ func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.Applicat
|
|||
|
||||
func TestListAppSetsInNamespaceWithLabels(t *testing.T) {
|
||||
testNamespace := "test-namespace"
|
||||
appSetServer := newTestAppSetServer(newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appSetServer := newTestAppSetServer(t, newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appset.Name = "AppSet1"
|
||||
appset.ObjectMeta.Namespace = testNamespace
|
||||
appset.SetLabels(map[string]string{"key1": "value1", "key2": "value1"})
|
||||
|
|
@ -294,7 +296,7 @@ func TestListAppSetsInNamespaceWithLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListAppSetsInDefaultNSWithLabels(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appSetServer := newTestAppSetServer(t, newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appset.Name = "AppSet1"
|
||||
appset.SetLabels(map[string]string{"key1": "value1", "key2": "value1"})
|
||||
}), newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
|
|
@ -314,7 +316,7 @@ func TestListAppSetsInDefaultNSWithLabels(t *testing.T) {
|
|||
// default namespace must be used and not all the namespaces
|
||||
func TestListAppSetsWithoutNamespace(t *testing.T) {
|
||||
testNamespace := "test-namespace"
|
||||
appSetServer := newTestNamespacedAppSetServer(newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appSetServer := newTestNamespacedAppSetServer(t, newTestAppSet(func(appset *appsv1.ApplicationSet) {
|
||||
appset.Name = "AppSet1"
|
||||
appset.ObjectMeta.Namespace = testNamespace
|
||||
appset.SetLabels(map[string]string{"key1": "value1", "key2": "value1"})
|
||||
|
|
@ -337,7 +339,7 @@ func TestListAppSetsWithoutNamespace(t *testing.T) {
|
|||
|
||||
func TestCreateAppSet(t *testing.T) {
|
||||
testAppSet := newTestAppSet()
|
||||
appServer := newTestAppSetServer()
|
||||
appServer := newTestAppSetServer(t)
|
||||
testAppSet.Spec.Generators = []appsv1.ApplicationSetGenerator{
|
||||
{
|
||||
List: &appsv1.ListGenerator{},
|
||||
|
|
@ -352,7 +354,7 @@ func TestCreateAppSet(t *testing.T) {
|
|||
|
||||
func TestCreateAppSetTemplatedProject(t *testing.T) {
|
||||
testAppSet := newTestAppSet()
|
||||
appServer := newTestAppSetServer()
|
||||
appServer := newTestAppSetServer(t)
|
||||
testAppSet.Spec.Template.Spec.Project = "{{ .project }}"
|
||||
createReq := applicationset.ApplicationSetCreateRequest{
|
||||
Applicationset: testAppSet,
|
||||
|
|
@ -363,7 +365,7 @@ func TestCreateAppSetTemplatedProject(t *testing.T) {
|
|||
|
||||
func TestCreateAppSetWrongNamespace(t *testing.T) {
|
||||
testAppSet := newTestAppSet()
|
||||
appServer := newTestAppSetServer()
|
||||
appServer := newTestAppSetServer(t)
|
||||
testAppSet.ObjectMeta.Namespace = "NOT-ALLOWED"
|
||||
createReq := applicationset.ApplicationSetCreateRequest{
|
||||
Applicationset: testAppSet,
|
||||
|
|
@ -375,7 +377,7 @@ func TestCreateAppSetWrongNamespace(t *testing.T) {
|
|||
|
||||
func TestCreateAppSetDryRun(t *testing.T) {
|
||||
testAppSet := newTestAppSet()
|
||||
appServer := newTestAppSetServer()
|
||||
appServer := newTestAppSetServer(t)
|
||||
testAppSet.Spec.Template.Name = "{{name}}"
|
||||
testAppSet.Spec.Generators = []appsv1.ApplicationSetGenerator{
|
||||
{
|
||||
|
|
@ -406,7 +408,7 @@ func TestCreateAppSetDryRun(t *testing.T) {
|
|||
|
||||
func TestCreateAppSetDryRunWithDuplicate(t *testing.T) {
|
||||
testAppSet := newTestAppSet()
|
||||
appServer := newTestAppSetServer()
|
||||
appServer := newTestAppSetServer(t)
|
||||
testAppSet.Spec.Template.Name = "{{name}}"
|
||||
testAppSet.Spec.Generators = []appsv1.ApplicationSetGenerator{
|
||||
{
|
||||
|
|
@ -441,7 +443,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Get in default namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1"}
|
||||
|
||||
|
|
@ -451,7 +453,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Get in named namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
|
|
@ -461,7 +463,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Get in not allowed namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1", AppsetNamespace: "NOT-ALLOWED"}
|
||||
|
||||
|
|
@ -484,7 +486,7 @@ func TestDeleteAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Delete in default namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1"}
|
||||
|
||||
|
|
@ -494,7 +496,7 @@ func TestDeleteAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Delete in named namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
|
|
@ -526,7 +528,7 @@ func TestUpdateAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Update merge", func(t *testing.T) {
|
||||
appServer := newTestAppSetServer(appSet)
|
||||
appServer := newTestAppSetServer(t, appSet)
|
||||
|
||||
updated, err := appServer.updateAppSet(context.Background(), appSet, newAppSet, true)
|
||||
|
||||
|
|
@ -542,7 +544,7 @@ func TestUpdateAppSet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Update no merge", func(t *testing.T) {
|
||||
appServer := newTestAppSetServer(appSet)
|
||||
appServer := newTestAppSetServer(t, appSet)
|
||||
|
||||
updated, err := appServer.updateAppSet(context.Background(), appSet, newAppSet, false)
|
||||
|
||||
|
|
@ -611,7 +613,7 @@ func TestResourceTree(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("ResourceTree in default namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1"}
|
||||
|
||||
|
|
@ -621,7 +623,7 @@ func TestResourceTree(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ResourceTree in named namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
|
|
@ -631,7 +633,7 @@ func TestResourceTree(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ResourceTree in not allowed namespace", func(t *testing.T) {
|
||||
appSetServer := newTestAppSetServer(appSet1, appSet2, appSet3)
|
||||
appSetServer := newTestAppSetServer(t, appSet1, appSet2, appSet3)
|
||||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1", AppsetNamespace: "NOT-ALLOWED"}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import (
|
|||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
// when a app gets stuck in sync, and we try to delete it, it won't delete, instead we must then terminate it
|
||||
|
|
@ -17,7 +17,7 @@ import (
|
|||
func TestDeletingAppStuckInSync(t *testing.T) {
|
||||
Given(t).
|
||||
And(func() {
|
||||
errors.CheckError(SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
|
||||
"ConfigMap": {
|
||||
HealthLua: `return { status = obj.annotations and obj.annotations['health'] or 'Progressing' }`,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
|||
Name: &app.Name,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
})
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, manifest := range manifests.Manifests {
|
||||
assetSecretDataHidden(t, manifest)
|
||||
|
|
@ -790,7 +790,7 @@ func TestNamespacedKnownTypesInCRDDiffing(t *testing.T) {
|
|||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
When().
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"argoproj.io/Dummy": {
|
||||
KnownTypeFields: []KnownTypeField{{
|
||||
Field: "spec",
|
||||
|
|
@ -1536,7 +1536,7 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
|
|||
}
|
||||
defer func() {
|
||||
log.Infof("Ingress 'sample-ingress' deleted from %s", fixture.TestNamespace())
|
||||
errors.CheckError(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
}()
|
||||
|
||||
svc := &corev1.Service{
|
||||
|
|
@ -1974,9 +1974,9 @@ metadata:
|
|||
s := fmt.Sprintf(existingNs, updatedNamespace)
|
||||
|
||||
tmpFile, err := os.CreateTemp(t.TempDir(), "")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
_, err = tmpFile.Write([]byte(s))
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.Run("", "kubectl", "apply", "-f", tmpFile.Name())
|
||||
require.NoError(t, err)
|
||||
|
|
@ -2170,7 +2170,7 @@ definitions:
|
|||
SetTrackingMethod("annotation").
|
||||
Path("crd-subresource").
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"argoproj.io/StatusSubResource": {
|
||||
Actions: actions,
|
||||
},
|
||||
|
|
@ -2258,7 +2258,7 @@ func TestNamespacedAppWaitOperationInProgress(t *testing.T) {
|
|||
SetAppNamespace(fixture.AppNamespace()).
|
||||
SetTrackingMethod("annotation").
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"batch/Job": {
|
||||
HealthLua: `return { status = 'Running' }`,
|
||||
},
|
||||
|
|
@ -2279,7 +2279,7 @@ func TestNamespacedAppWaitOperationInProgress(t *testing.T) {
|
|||
Then().
|
||||
And(func(app *Application) {
|
||||
_, err := fixture.RunCli("app", "wait", app.QualifiedName(), "--suspended")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -2376,7 +2376,7 @@ func TestNamespacedDisableManifestGeneration(t *testing.T) {
|
|||
}).
|
||||
When().
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetEnableManifestGeneration(map[ApplicationSourceType]bool{
|
||||
require.NoError(t, fixture.SetEnableManifestGeneration(map[ApplicationSourceType]bool{
|
||||
ApplicationSourceTypeKustomize: false,
|
||||
}))
|
||||
}).
|
||||
|
|
|
|||
|
|
@ -797,7 +797,7 @@ func TestAppWithSecrets(t *testing.T) {
|
|||
assetSecretDataHidden(t, res.GetManifest())
|
||||
|
||||
manifests, err := client.GetManifests(context.Background(), &applicationpkg.ApplicationManifestQuery{Name: &app.Name})
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, manifest := range manifests.Manifests {
|
||||
assetSecretDataHidden(t, manifest)
|
||||
|
|
@ -990,7 +990,7 @@ func TestKnownTypesInCRDDiffing(t *testing.T) {
|
|||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
When().
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"argoproj.io/Dummy": {
|
||||
KnownTypeFields: []KnownTypeField{{
|
||||
Field: "spec",
|
||||
|
|
@ -2006,7 +2006,7 @@ func TestNotPermittedResources(t *testing.T) {
|
|||
}
|
||||
defer func() {
|
||||
log.Infof("Ingress 'sample-ingress' deleted from %s", fixture.TestNamespace())
|
||||
errors.CheckError(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
}()
|
||||
|
||||
svc := &corev1.Service{
|
||||
|
|
@ -2365,7 +2365,7 @@ definitions:
|
|||
Given(t).
|
||||
Path("crd-subresource").
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"argoproj.io/StatusSubResource": {
|
||||
Actions: actions,
|
||||
},
|
||||
|
|
@ -2450,7 +2450,7 @@ func TestAppWaitOperationInProgress(t *testing.T) {
|
|||
ctx := Given(t)
|
||||
ctx.
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"batch/Job": {
|
||||
HealthLua: `return { status = 'Running' }`,
|
||||
},
|
||||
|
|
@ -2470,7 +2470,7 @@ func TestAppWaitOperationInProgress(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
_, err := fixture.RunCli("app", "wait", ctx.AppName(), "--suspended")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -2559,7 +2559,7 @@ func TestDisableManifestGeneration(t *testing.T) {
|
|||
}).
|
||||
When().
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetEnableManifestGeneration(map[ApplicationSourceType]bool{
|
||||
require.NoError(t, fixture.SetEnableManifestGeneration(map[ApplicationSourceType]bool{
|
||||
ApplicationSourceTypeKustomize: false,
|
||||
}))
|
||||
}).
|
||||
|
|
@ -2763,7 +2763,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
func TestAnnotationTrackingExtraResources(t *testing.T) {
|
||||
ctx := Given(t)
|
||||
|
||||
errors.CheckError(fixture.SetTrackingMethod(string(argo.TrackingMethodAnnotation)))
|
||||
require.NoError(t, fixture.SetTrackingMethod(string(argo.TrackingMethodAnnotation)))
|
||||
ctx.
|
||||
Path("deployment").
|
||||
When().
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func TestForbiddenNamespace(t *testing.T) {
|
|||
func TestDeletingNamespacedAppStuckInSync(t *testing.T) {
|
||||
ctx := Given(t)
|
||||
ctx.And(func() {
|
||||
errors.CheckError(SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
|
||||
"ConfigMap": {
|
||||
HealthLua: `return { status = obj.annotations and obj.annotations['health'] or 'Progressing' }`,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apis/application"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/applicationsets"
|
||||
|
|
@ -925,7 +924,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletion(t *testing.T) {
|
|||
},
|
||||
},
|
||||
// We use an extra-long duration here, as we might need to wait for image pull.
|
||||
}).Then().ExpectWithDuration(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }), 6*time.Minute).
|
||||
}).Then().ExpectWithDuration(Pod(t, func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }), 6*time.Minute).
|
||||
When().
|
||||
Delete().
|
||||
And(func() {
|
||||
|
|
@ -935,7 +934,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletion(t *testing.T) {
|
|||
// that is what we are testing here.
|
||||
time.Sleep(15 * time.Second)
|
||||
// The pod should continue to exist after 15 seconds.
|
||||
}).Then().Expect(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }))
|
||||
}).Then().Expect(Pod(t, func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }))
|
||||
}
|
||||
|
||||
func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) {
|
||||
|
|
@ -986,7 +985,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) {
|
|||
},
|
||||
},
|
||||
// We use an extra-long duration here, as we might need to wait for image pull.
|
||||
}).Then().ExpectWithDuration(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }), 6*time.Minute).
|
||||
}).Then().ExpectWithDuration(Pod(t, func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }), 6*time.Minute).
|
||||
When().
|
||||
Delete().
|
||||
And(func() {
|
||||
|
|
@ -996,7 +995,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) {
|
|||
// that is what we are testing here.
|
||||
time.Sleep(15 * time.Second)
|
||||
// The pod should continue to exist after 15 seconds.
|
||||
}).Then().Expect(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }))
|
||||
}).Then().Expect(Pod(t, func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") }))
|
||||
}
|
||||
|
||||
func TestGitGeneratorPrivateRepo(t *testing.T) {
|
||||
|
|
@ -1466,7 +1465,7 @@ func TestGitGeneratorPrivateRepoWithTemplatedProjectAndProjectScopedRepo(t *test
|
|||
Addr: "localhost:6379",
|
||||
})
|
||||
all := r.FlushAll(context.Background())
|
||||
errors.CheckError(all.Err())
|
||||
require.NoError(t, all.Err())
|
||||
|
||||
generateExpectedApp := func(name string) v1alpha1.Application {
|
||||
return v1alpha1.Application{
|
||||
|
|
|
|||
|
|
@ -1766,7 +1766,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictOk(t *testing.T) {
|
|||
|
||||
Given(t).
|
||||
And(func() {
|
||||
_, err := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: fixture.TestNamespace(),
|
||||
Name: secretName,
|
||||
|
|
@ -1824,7 +1824,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictOk(t *testing.T) {
|
|||
},
|
||||
}).Then().Expect(ApplicationsExist([]v1alpha1.Application{expectedApp})).
|
||||
When().And(func() {
|
||||
err := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
@ -1871,7 +1871,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictKo(t *testing.T) {
|
|||
|
||||
Given(t).
|
||||
And(func() {
|
||||
_, err := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: fixture.TestNamespace(),
|
||||
Name: secretName,
|
||||
|
|
@ -1935,7 +1935,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictKo(t *testing.T) {
|
|||
output, err := fixture.RunCli("appset", "get", "simple-scm-provider-generator-strict-ko")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, fmt.Sprintf("scm provider: error fetching Github token: secret %s/%s is not a valid SCM creds secret", fixture.TestNamespace(), secretName))
|
||||
err2 := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
err2 := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
assert.NoError(t, err2)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ func TestCliAppCommand(t *testing.T) {
|
|||
output, err := RunCli("app", "sync", Name(), "--timeout", "90")
|
||||
require.NoError(t, err)
|
||||
vars := map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()}
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(`Pod {{.Namespace}} pod Synced Progressing pod/pod created`, vars))
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(`Pod {{.Namespace}} hook Succeeded Sync pod/hook created`, vars))
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} pod Synced Progressing pod/pod created`, vars))
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(t, `Pod {{.Namespace}} hook Succeeded Sync pod/hook created`, vars))
|
||||
}).
|
||||
Then().
|
||||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
|
|
@ -32,6 +32,7 @@ func TestCliAppCommand(t *testing.T) {
|
|||
output, err := RunCli("app", "list")
|
||||
require.NoError(t, err)
|
||||
expected := Tmpl(
|
||||
t,
|
||||
`{{.Name}} https://kubernetes.default.svc {{.Namespace}} default Synced Healthy Manual <none>`,
|
||||
map[string]any{"Name": Name(), "Namespace": DeploymentNamespace()})
|
||||
assert.Contains(t, NormalizeOutput(output), expected)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"github.com/argoproj/argo-cd/v3/common"
|
||||
"github.com/argoproj/argo-cd/v3/util/argo"
|
||||
"github.com/argoproj/argo-cd/v3/util/clusterauth"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
|
|
@ -55,7 +54,7 @@ func TestDeployment(t *testing.T) {
|
|||
func TestDeploymentWithAnnotationTrackingMode(t *testing.T) {
|
||||
ctx := Given(t)
|
||||
|
||||
errors.CheckError(SetTrackingMethod(string(argo.TrackingMethodAnnotation)))
|
||||
require.NoError(t, SetTrackingMethod(string(argo.TrackingMethodAnnotation)))
|
||||
ctx.
|
||||
Path("deployment").
|
||||
When().
|
||||
|
|
@ -78,7 +77,7 @@ func TestDeploymentWithAnnotationTrackingMode(t *testing.T) {
|
|||
|
||||
func TestDeploymentWithLabelTrackingMode(t *testing.T) {
|
||||
ctx := Given(t)
|
||||
errors.CheckError(SetTrackingMethod(string(argo.TrackingMethodLabel)))
|
||||
require.NoError(t, SetTrackingMethod(string(argo.TrackingMethodLabel)))
|
||||
ctx.
|
||||
Path("deployment").
|
||||
When().
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package project
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
// this implements the "when" part of given/when/then
|
||||
|
|
@ -47,7 +48,8 @@ func (a *Actions) prepareSetPasswordArgs(account string) []string {
|
|||
}
|
||||
|
||||
func (a *Actions) Create() *Actions {
|
||||
errors.CheckError(fixture.SetAccounts(map[string][]string{
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetAccounts(map[string][]string{
|
||||
a.context.name: {"login"},
|
||||
}))
|
||||
_, _ = fixture.RunCli(a.prepareSetPasswordArgs(a.context.name)...)
|
||||
|
|
@ -55,17 +57,20 @@ func (a *Actions) Create() *Actions {
|
|||
}
|
||||
|
||||
func (a *Actions) SetPermissions(permissions []fixture.ACL, roleName string) *Actions {
|
||||
errors.CheckError(fixture.SetPermissions(permissions, a.context.name, roleName))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetPermissions(permissions, a.context.name, roleName))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) SetParamInSettingConfigMap(key, value string) *Actions {
|
||||
errors.CheckError(fixture.SetParamInSettingConfigMap(key, value))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetParamInSettingConfigMap(key, value))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) Login() *Actions {
|
||||
errors.CheckError(fixture.LoginAs(a.context.name))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.LoginAs(a.context.name))
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apiclient/session"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apiclient/account"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
. "github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/io"
|
||||
)
|
||||
|
||||
|
|
@ -51,8 +52,9 @@ func (c *Consequences) get() (*account.Account, error) {
|
|||
}
|
||||
|
||||
func (c *Consequences) getCurrentUser() (*session.GetUserInfoResponse, error) {
|
||||
c.context.t.Helper()
|
||||
closer, client, err := fixture.ArgoCDClientset.NewSessionClient()
|
||||
CheckError(err)
|
||||
require.NoError(c.context.t, err)
|
||||
defer io.Close(closer)
|
||||
return client.GetUserInfo(context.Background(), &session.GetUserInfoRequest{})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
client "github.com/argoproj/argo-cd/v3/pkg/apiclient/application"
|
||||
. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/grpc"
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ func (a *Actions) DeleteFile(file string) *Actions {
|
|||
|
||||
func (a *Actions) WriteFile(fileName, fileContents string) *Actions {
|
||||
a.context.t.Helper()
|
||||
fixture.WriteFile(a.context.path+"/"+fileName, fileContents)
|
||||
fixture.WriteFile(a.context.t, a.context.path+"/"+fileName, fileContents)
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +91,9 @@ func (a *Actions) RemoveSubmodule() *Actions {
|
|||
func (a *Actions) CreateFromPartialFile(data string, flags ...string) *Actions {
|
||||
a.context.t.Helper()
|
||||
tmpFile, err := os.CreateTemp("", "")
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
_, err = tmpFile.Write([]byte(data))
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
|
||||
args := append([]string{
|
||||
"app", "create",
|
||||
|
|
@ -155,9 +155,9 @@ func (a *Actions) CreateFromFile(handler func(app *Application), flags ...string
|
|||
handler(app)
|
||||
data := grpc.MustMarshal(app)
|
||||
tmpFile, err := os.CreateTemp("", "")
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
_, err = tmpFile.Write(data)
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
|
||||
args := append([]string{
|
||||
"app", "create",
|
||||
|
|
@ -192,9 +192,9 @@ func (a *Actions) CreateMultiSourceAppFromFile(flags ...string) *Actions {
|
|||
|
||||
data := grpc.MustMarshal(app)
|
||||
tmpFile, err := os.CreateTemp("", "")
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
_, err = tmpFile.Write(data)
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
|
||||
args := append([]string{
|
||||
"app", "create",
|
||||
|
|
@ -322,7 +322,7 @@ func (a *Actions) DeclarativeWithCustomRepo(filename string, repoURL string) *Ac
|
|||
"Project": a.context.project,
|
||||
"RepoURL": repoURL,
|
||||
}
|
||||
a.lastOutput, a.lastError = fixture.Declarative(filename, values)
|
||||
a.lastOutput, a.lastError = fixture.Declarative(a.context.t, filename, values)
|
||||
a.verifyAction()
|
||||
return a
|
||||
}
|
||||
|
|
@ -346,12 +346,12 @@ func (a *Actions) PatchAppHttp(patch string) *Actions { //nolint:revive //FIXME(
|
|||
AppNamespace: &appNamespace,
|
||||
}
|
||||
jsonBytes, err := json.MarshalIndent(patchRequest, "", " ")
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
err = fixture.DoHttpJsonRequest("PATCH",
|
||||
fmt.Sprintf("/api/v1/applications/%v", appName),
|
||||
&application,
|
||||
jsonBytes...)
|
||||
errors.CheckError(err)
|
||||
require.NoError(a.context.t, err)
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
@ -479,7 +479,8 @@ func (a *Actions) Wait(args ...string) *Actions {
|
|||
}
|
||||
|
||||
func (a *Actions) SetParamInSettingConfigMap(key, value string) *Actions {
|
||||
errors.CheckError(fixture.SetParamInSettingConfigMap(key, value))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetParamInSettingConfigMap(key, value))
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
@ -508,30 +509,35 @@ func (a *Actions) verifyAction() {
|
|||
}
|
||||
|
||||
func (a *Actions) SetTrackingMethod(trackingMethod string) *Actions {
|
||||
errors.CheckError(fixture.SetTrackingMethod(trackingMethod))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetTrackingMethod(trackingMethod))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) SetInstallationID(installationID string) *Actions {
|
||||
errors.CheckError(fixture.SetInstallationID(installationID))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetInstallationID(installationID))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) SetTrackingLabel(trackingLabel string) *Actions {
|
||||
errors.CheckError(fixture.SetTrackingLabel(trackingLabel))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetTrackingLabel(trackingLabel))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) WithImpersonationEnabled(serviceAccountName string, policyRules []rbacv1.PolicyRule) *Actions {
|
||||
errors.CheckError(fixture.SetImpersonationEnabled("true"))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetImpersonationEnabled("true"))
|
||||
if serviceAccountName == "" || policyRules == nil {
|
||||
return a
|
||||
}
|
||||
errors.CheckError(fixture.CreateRBACResourcesForImpersonation(serviceAccountName, policyRules))
|
||||
require.NoError(a.context.t, fixture.CreateRBACResourcesForImpersonation(serviceAccountName, policyRules))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Actions) WithImpersonationDisabled() *Actions {
|
||||
errors.CheckError(fixture.SetImpersonationEnabled("false"))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetImpersonationEnabled("false"))
|
||||
return a
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import (
|
|||
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
applicationpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/application"
|
||||
. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
util "github.com/argoproj/argo-cd/v3/util/io"
|
||||
)
|
||||
|
||||
|
|
@ -105,8 +105,9 @@ func (c *Consequences) When() *Actions {
|
|||
}
|
||||
|
||||
func (c *Consequences) app() *Application {
|
||||
c.context.t.Helper()
|
||||
app, err := c.get()
|
||||
errors.CheckError(err)
|
||||
require.NoError(c.context.t, err)
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
@ -115,15 +116,16 @@ func (c *Consequences) get() (*Application, error) {
|
|||
}
|
||||
|
||||
func (c *Consequences) resource(kind, name, namespace string) ResourceStatus {
|
||||
c.context.t.Helper()
|
||||
closer, client, err := fixture.ArgoCDClientset.NewApplicationClient()
|
||||
errors.CheckError(err)
|
||||
require.NoError(c.context.t, err)
|
||||
defer util.Close(closer)
|
||||
app, err := client.Get(context.Background(), &applicationpkg.ApplicationQuery{
|
||||
Name: ptr.To(c.context.AppName()),
|
||||
Projects: []string{c.context.project},
|
||||
AppNamespace: ptr.To(c.context.appNamespace),
|
||||
})
|
||||
errors.CheckError(err)
|
||||
require.NoError(c.context.t, err)
|
||||
for _, r := range app.Status.Resources {
|
||||
if r.Kind == kind && r.Name == name && (namespace == "" || namespace == r.Namespace) {
|
||||
return r
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture/certs"
|
||||
|
|
@ -11,7 +13,6 @@ import (
|
|||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture/repos"
|
||||
"github.com/argoproj/argo-cd/v3/util/argo"
|
||||
"github.com/argoproj/argo-cd/v3/util/env"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/settings"
|
||||
)
|
||||
|
||||
|
|
@ -218,7 +219,8 @@ func (c *Context) SSHCredentialsAdded() *Context {
|
|||
}
|
||||
|
||||
func (c *Context) ProjectSpec(spec v1alpha1.AppProjectSpec) *Context {
|
||||
errors.CheckError(fixture.SetProjectSpec(c.project, spec))
|
||||
c.t.Helper()
|
||||
require.NoError(c.t, fixture.SetProjectSpec(c.project, spec))
|
||||
return c
|
||||
}
|
||||
|
||||
|
|
@ -330,12 +332,14 @@ func (c *Context) NameSuffix(nameSuffix string) *Context {
|
|||
}
|
||||
|
||||
func (c *Context) ResourceOverrides(overrides map[string]v1alpha1.ResourceOverride) *Context {
|
||||
errors.CheckError(fixture.SetResourceOverrides(overrides))
|
||||
c.t.Helper()
|
||||
require.NoError(c.t, fixture.SetResourceOverrides(overrides))
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Context) ResourceFilter(filter settings.ResourcesFilter) *Context {
|
||||
errors.CheckError(fixture.SetResourceFilter(filter))
|
||||
c.t.Helper()
|
||||
require.NoError(c.t, fixture.SetResourceFilter(filter))
|
||||
return c
|
||||
}
|
||||
|
||||
|
|
@ -404,12 +408,14 @@ func (c *Context) HelmSkipTests() *Context {
|
|||
}
|
||||
|
||||
func (c *Context) SetTrackingMethod(trackingMethod string) *Context {
|
||||
errors.CheckError(fixture.SetTrackingMethod(trackingMethod))
|
||||
c.t.Helper()
|
||||
require.NoError(c.t, fixture.SetTrackingMethod(trackingMethod))
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Context) SetInstallationID(installationID string) *Context {
|
||||
errors.CheckError(fixture.SetInstallationID(installationID))
|
||||
c.t.Helper()
|
||||
require.NoError(c.t, fixture.SetInstallationID(installationID))
|
||||
return c
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ func (a *Actions) SwitchToArgoCDNamespace() *Actions {
|
|||
// CreateClusterSecret creates a faux cluster secret, with the given cluster server and cluster name (this cluster
|
||||
// will not actually be used by the Argo CD controller, but that's not needed for our E2E tests)
|
||||
func (a *Actions) CreateClusterSecret(secretName string, clusterName string, clusterServer string) *Actions {
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
a.context.t.Helper()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
var serviceAccountName string
|
||||
|
||||
|
|
@ -152,7 +153,8 @@ func (a *Actions) CreateClusterSecret(secretName string, clusterName string, clu
|
|||
|
||||
// DeleteClusterSecret deletes a faux cluster secret
|
||||
func (a *Actions) DeleteClusterSecret(secretName string) *Actions {
|
||||
err := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
a.context.t.Helper()
|
||||
err := utils.GetE2EFixtureK8sClient(a.context.t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
|
||||
a.describeAction = fmt.Sprintf("deleting cluster Secret '%s'", secretName)
|
||||
a.lastOutput, a.lastError = "", err
|
||||
|
|
@ -163,7 +165,8 @@ func (a *Actions) DeleteClusterSecret(secretName string) *Actions {
|
|||
|
||||
// DeleteConfigMap deletes a faux cluster secret
|
||||
func (a *Actions) DeleteConfigMap(configMapName string) *Actions {
|
||||
err := utils.GetE2EFixtureK8sClient().KubeClientset.CoreV1().ConfigMaps(fixture.TestNamespace()).Delete(context.Background(), configMapName, metav1.DeleteOptions{})
|
||||
a.context.t.Helper()
|
||||
err := utils.GetE2EFixtureK8sClient(a.context.t).KubeClientset.CoreV1().ConfigMaps(fixture.TestNamespace()).Delete(context.Background(), configMapName, metav1.DeleteOptions{})
|
||||
|
||||
a.describeAction = fmt.Sprintf("deleting configMap '%s'", configMapName)
|
||||
a.lastOutput, a.lastError = "", err
|
||||
|
|
@ -174,7 +177,8 @@ func (a *Actions) DeleteConfigMap(configMapName string) *Actions {
|
|||
|
||||
// DeletePlacementDecision deletes a faux cluster secret
|
||||
func (a *Actions) DeletePlacementDecision(placementDecisionName string) *Actions {
|
||||
err := utils.GetE2EFixtureK8sClient().DynamicClientset.Resource(pdGVR).Namespace(fixture.TestNamespace()).Delete(context.Background(), placementDecisionName, metav1.DeleteOptions{})
|
||||
a.context.t.Helper()
|
||||
err := utils.GetE2EFixtureK8sClient(a.context.t).DynamicClientset.Resource(pdGVR).Namespace(fixture.TestNamespace()).Delete(context.Background(), placementDecisionName, metav1.DeleteOptions{})
|
||||
|
||||
a.describeAction = fmt.Sprintf("deleting placement decision '%s'", placementDecisionName)
|
||||
a.lastOutput, a.lastError = "", err
|
||||
|
|
@ -188,7 +192,7 @@ func (a *Actions) DeletePlacementDecision(placementDecisionName string) *Actions
|
|||
func (a *Actions) CreateNamespace(namespace string) *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
_, err := fixtureClient.KubeClientset.CoreV1().Namespaces().Create(context.Background(),
|
||||
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
|
||||
|
|
@ -204,7 +208,7 @@ func (a *Actions) CreateNamespace(namespace string) *Actions {
|
|||
func (a *Actions) Create(appSet v1alpha1.ApplicationSet) *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
appSet.APIVersion = "argoproj.io/v1alpha1"
|
||||
appSet.Kind = "ApplicationSet"
|
||||
|
|
@ -238,7 +242,8 @@ func (a *Actions) Create(appSet v1alpha1.ApplicationSet) *Actions {
|
|||
|
||||
// Create Role/RoleBinding to allow ApplicationSet to list the PlacementDecisions
|
||||
func (a *Actions) CreatePlacementRoleAndRoleBinding() *Actions {
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
a.context.t.Helper()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
var err error
|
||||
|
||||
|
|
@ -289,7 +294,7 @@ func (a *Actions) CreatePlacementRoleAndRoleBinding() *Actions {
|
|||
func (a *Actions) CreatePlacementDecisionConfigMap(configMapName string) *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
_, err := fixtureClient.KubeClientset.CoreV1().ConfigMaps(fixture.TestNamespace()).Get(context.Background(), configMapName, metav1.GetOptions{})
|
||||
|
||||
|
|
@ -321,7 +326,7 @@ func (a *Actions) CreatePlacementDecisionConfigMap(configMapName string) *Action
|
|||
func (a *Actions) CreatePlacementDecision(placementDecisionName string) *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient().DynamicClientset
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t).DynamicClientset
|
||||
|
||||
_, err := fixtureClient.Resource(pdGVR).Namespace(fixture.TestNamespace()).Get(
|
||||
context.Background(),
|
||||
|
|
@ -359,7 +364,7 @@ func (a *Actions) CreatePlacementDecision(placementDecisionName string) *Actions
|
|||
func (a *Actions) StatusUpdatePlacementDecision(placementDecisionName string, clusterList []any) *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient().DynamicClientset
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t).DynamicClientset
|
||||
placementDecision, err := fixtureClient.Resource(pdGVR).Namespace(fixture.TestNamespace()).Get(
|
||||
context.Background(),
|
||||
placementDecisionName,
|
||||
|
|
@ -386,7 +391,7 @@ func (a *Actions) StatusUpdatePlacementDecision(placementDecisionName string, cl
|
|||
func (a *Actions) Delete() *Actions {
|
||||
a.context.t.Helper()
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
var appSetClientSet dynamic.ResourceInterface
|
||||
|
||||
|
|
@ -414,7 +419,7 @@ func (a *Actions) Delete() *Actions {
|
|||
func (a *Actions) get() (*v1alpha1.ApplicationSet, error) {
|
||||
appSet := v1alpha1.ApplicationSet{}
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
var appSetClientSet dynamic.ResourceInterface
|
||||
|
||||
|
|
@ -477,7 +482,7 @@ func (a *Actions) Update(toUpdate func(*v1alpha1.ApplicationSet)) *Actions {
|
|||
toUpdate(appSet)
|
||||
a.describeAction = fmt.Sprintf("updating ApplicationSet '%s/%s'", appSet.Namespace, appSet.Name)
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(a.context.t)
|
||||
|
||||
var appSetClientSet dynamic.ResourceInterface
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ func (c *Consequences) app(name string) *v1alpha1.Application {
|
|||
}
|
||||
|
||||
func (c *Consequences) apps() []v1alpha1.Application {
|
||||
c.context.t.Helper()
|
||||
var namespace string
|
||||
if c.context.switchToNamespace != "" {
|
||||
namespace = string(c.context.switchToNamespace)
|
||||
|
|
@ -94,7 +95,7 @@ func (c *Consequences) apps() []v1alpha1.Application {
|
|||
namespace = fixture.TestNamespace()
|
||||
}
|
||||
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.t)
|
||||
list, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(namespace).List(context.Background(), metav1.ListOptions{})
|
||||
errors.CheckError(err)
|
||||
|
||||
|
|
@ -106,7 +107,8 @@ func (c *Consequences) apps() []v1alpha1.Application {
|
|||
}
|
||||
|
||||
func (c *Consequences) applicationSet(applicationSetName string) *v1alpha1.ApplicationSet {
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
c.context.t.Helper()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.t)
|
||||
|
||||
var appSetClientSet dynamic.ResourceInterface
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/gitops-engine/pkg/diff"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
|
@ -115,9 +116,10 @@ func ApplicationsDoNotExist(expectedApps []v1alpha1.Application) Expectation {
|
|||
}
|
||||
|
||||
// Pod checks whether a specified condition is true for any of the pods in the namespace
|
||||
func Pod(predicate func(p corev1.Pod) bool) Expectation {
|
||||
func Pod(t *testing.T, predicate func(p corev1.Pod) bool) Expectation {
|
||||
t.Helper()
|
||||
return func(_ *Consequences) (state, string) {
|
||||
pods, err := pods(utils.ApplicationsResourcesNamespace)
|
||||
pods, err := pods(t, utils.ApplicationsResourcesNamespace)
|
||||
if err != nil {
|
||||
return failed, err.Error()
|
||||
}
|
||||
|
|
@ -130,8 +132,9 @@ func Pod(predicate func(p corev1.Pod) bool) Expectation {
|
|||
}
|
||||
}
|
||||
|
||||
func pods(namespace string) (*corev1.PodList, error) {
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient()
|
||||
func pods(t *testing.T, namespace string) (*corev1.PodList, error) {
|
||||
t.Helper()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(t)
|
||||
|
||||
pods, err := fixtureClient.KubeClientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{})
|
||||
return pods, err
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/equality"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
|
@ -85,11 +86,12 @@ func TestNamespace() string {
|
|||
|
||||
// GetE2EFixtureK8sClient initializes the Kubernetes clients (if needed), and returns the most recently initialized value.
|
||||
// Note: this requires a local Kubernetes configuration (for example, while running the E2E tests).
|
||||
func GetE2EFixtureK8sClient() *E2EFixtureK8sClient {
|
||||
func GetE2EFixtureK8sClient(t *testing.T) *E2EFixtureK8sClient {
|
||||
t.Helper()
|
||||
// Initialize the Kubernetes clients only on first use
|
||||
clientInitialized.Do(func() {
|
||||
// set-up variables
|
||||
config := getKubeConfig("", clientcmd.ConfigOverrides{})
|
||||
config := getKubeConfig(t, "", clientcmd.ConfigOverrides{})
|
||||
|
||||
internalClientVars = &E2EFixtureK8sClient{
|
||||
AppClientset: appclientset.NewForConfigOrDie(config),
|
||||
|
|
@ -111,7 +113,7 @@ func EnsureCleanState(t *testing.T) {
|
|||
t.Helper()
|
||||
start := time.Now()
|
||||
|
||||
fixtureClient := GetE2EFixtureK8sClient()
|
||||
fixtureClient := GetE2EFixtureK8sClient(t)
|
||||
|
||||
policy := metav1.DeletePropagationForeground
|
||||
|
||||
|
|
@ -203,26 +205,27 @@ func EnsureCleanState(t *testing.T) {
|
|||
}
|
||||
return nil
|
||||
}, time.Now().Add(120*time.Second))
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
errors.CheckError(waitForExpectedClusterState())
|
||||
require.NoError(t, waitForExpectedClusterState(t))
|
||||
|
||||
// remove tmp dir
|
||||
errors.CheckError(os.RemoveAll(TmpDir))
|
||||
require.NoError(t, os.RemoveAll(TmpDir))
|
||||
|
||||
// create tmp dir
|
||||
errors.NewHandler(t).FailOnErr(Run("", "mkdir", "-p", TmpDir))
|
||||
|
||||
// We can switch user and as result in previous state we will have non-admin user, this case should be reset
|
||||
errors.CheckError(fixture.LoginAs("admin"))
|
||||
require.NoError(t, fixture.LoginAs("admin"))
|
||||
|
||||
log.WithFields(log.Fields{"duration": time.Since(start), "name": t.Name(), "id": id, "username": "admin", "password": "password"}).Info("clean state")
|
||||
}
|
||||
|
||||
func waitForExpectedClusterState() error {
|
||||
fixtureClient := GetE2EFixtureK8sClient()
|
||||
func waitForExpectedClusterState(t *testing.T) error {
|
||||
t.Helper()
|
||||
fixtureClient := GetE2EFixtureK8sClient(t)
|
||||
|
||||
SetProjectSpec(fixtureClient, "default", v1alpha1.AppProjectSpec{
|
||||
SetProjectSpec(t, fixtureClient, "default", v1alpha1.AppProjectSpec{
|
||||
OrphanedResources: nil,
|
||||
SourceRepos: []string{"*"},
|
||||
Destinations: []v1alpha1.ApplicationDestination{{Namespace: "*", Server: "*"}},
|
||||
|
|
@ -274,12 +277,13 @@ func waitForExpectedClusterState() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func SetProjectSpec(fixtureClient *E2EFixtureK8sClient, project string, spec v1alpha1.AppProjectSpec) {
|
||||
func SetProjectSpec(t *testing.T, fixtureClient *E2EFixtureK8sClient, project string, spec v1alpha1.AppProjectSpec) {
|
||||
t.Helper()
|
||||
proj, err := fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Get(context.Background(), project, metav1.GetOptions{})
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
proj.Spec = spec
|
||||
_, err = fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Update(context.Background(), proj, metav1.UpdateOptions{})
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func cleanUpNamespace(fixtureClient *E2EFixtureK8sClient, namespace string) error {
|
||||
|
|
@ -345,13 +349,14 @@ func waitForSuccess(condition func() error, expireTime time.Time) error {
|
|||
}
|
||||
|
||||
// getKubeConfig creates new kubernetes client config using specified config path and config overrides variables
|
||||
func getKubeConfig(configPath string, overrides clientcmd.ConfigOverrides) *rest.Config {
|
||||
func getKubeConfig(t *testing.T, configPath string, overrides clientcmd.ConfigOverrides) *rest.Config {
|
||||
t.Helper()
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
loadingRules.ExplicitPath = configPath
|
||||
clientConfig := clientcmd.NewInteractiveDeferredLoadingClientConfig(loadingRules, &overrides, os.Stdin)
|
||||
|
||||
restConfig, err := clientConfig.ClientConfig()
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
return restConfig
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
|
@ -14,7 +16,7 @@ import (
|
|||
func AddCustomCACert(t *testing.T) {
|
||||
t.Helper()
|
||||
caCertPath, err := filepath.Abs("../fixture/certs/argocd-test-ca.crt")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
// We need to setup TLS certs according to whether we are running tests
|
||||
// against a local workload (repositories available as localhost) and
|
||||
// against remote workloads (repositories available as argocd-e2e-server)
|
||||
|
|
@ -24,11 +26,11 @@ func AddCustomCACert(t *testing.T) {
|
|||
args = []string{"cert", "add-tls", "127.0.0.1", "--from", caCertPath}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
certData, err := os.ReadFile(caCertPath)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(fixture.TmpDir+"/app/config/tls/localhost", certData, 0o644)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(fixture.TmpDir+"/app/config/tls/127.0.0.1", certData, 0o644)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
args := []string{"cert", "add-tls", "argocd-e2e-server", "--from", caCertPath}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
|
|
@ -47,15 +49,15 @@ func AddCustomSSHKnownHostsKeys(t *testing.T) {
|
|||
source = "../fixture/testrepos/ssh_known_hosts"
|
||||
}
|
||||
knownHostsPath, err := filepath.Abs(source)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
args := []string{"cert", "add-ssh", "--upsert", "--batch", "--from", knownHostsPath}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
|
||||
if fixture.IsLocal() {
|
||||
knownHostsData, err := os.ReadFile(knownHostsPath)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(fixture.TmpDir+"/app/config/ssh/ssh_known_hosts", knownHostsData, 0o644)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
fixture.RestartAPIServer(t)
|
||||
fixture.RestartRepoServer(t)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
|
@ -1040,30 +1041,30 @@ func Patch(t *testing.T, path string, jsonPatch string) {
|
|||
|
||||
filename := filepath.Join(repoDirectory(), path)
|
||||
bytes, err := os.ReadFile(filename)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
patch, err := jsonpatch.DecodePatch([]byte(jsonPatch))
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
isYaml := strings.HasSuffix(filename, ".yaml")
|
||||
if isYaml {
|
||||
log.Info("converting YAML to JSON")
|
||||
bytes, err = yaml.YAMLToJSON(bytes)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{"bytes": string(bytes)}).Info("JSON")
|
||||
|
||||
bytes, err = patch.Apply(bytes)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
if isYaml {
|
||||
log.Info("converting JSON back to YAML")
|
||||
bytes, err = yaml.JSONToYAML(bytes)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
errors.CheckError(os.WriteFile(filename, bytes, 0o644))
|
||||
require.NoError(t, os.WriteFile(filename, bytes, 0o644))
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "diff"))
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "commit", "-am", "patch"))
|
||||
if IsRemote() {
|
||||
|
|
@ -1075,7 +1076,7 @@ func Delete(t *testing.T, path string) {
|
|||
t.Helper()
|
||||
log.WithFields(log.Fields{"path": path}).Info("deleting")
|
||||
|
||||
errors.CheckError(os.Remove(filepath.Join(repoDirectory(), path)))
|
||||
require.NoError(t, os.Remove(filepath.Join(repoDirectory(), path)))
|
||||
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "diff"))
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "commit", "-am", "delete"))
|
||||
|
|
@ -1084,15 +1085,16 @@ func Delete(t *testing.T, path string) {
|
|||
}
|
||||
}
|
||||
|
||||
func WriteFile(path, contents string) {
|
||||
func WriteFile(t *testing.T, path, contents string) {
|
||||
t.Helper()
|
||||
log.WithFields(log.Fields{"path": path}).Info("adding")
|
||||
|
||||
errors.CheckError(os.WriteFile(filepath.Join(repoDirectory(), path), []byte(contents), 0o644))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(repoDirectory(), path), []byte(contents), 0o644))
|
||||
}
|
||||
|
||||
func AddFile(t *testing.T, path, contents string) {
|
||||
t.Helper()
|
||||
WriteFile(path, contents)
|
||||
WriteFile(t, path, contents)
|
||||
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "diff"))
|
||||
errors.NewHandler(t).FailOnErr(Run(repoDirectory(), "git", "add", "."))
|
||||
|
|
@ -1105,7 +1107,7 @@ func AddFile(t *testing.T, path, contents string) {
|
|||
|
||||
func AddSignedFile(t *testing.T, path, contents string) {
|
||||
t.Helper()
|
||||
WriteFile(path, contents)
|
||||
WriteFile(t, path, contents)
|
||||
|
||||
prevGnuPGHome := os.Getenv("GNUPGHOME")
|
||||
t.Setenv("GNUPGHOME", TmpDir+"/gpg")
|
||||
|
|
@ -1141,14 +1143,15 @@ func AddTag(t *testing.T, name string) {
|
|||
}
|
||||
|
||||
// create the resource by creating using "kubectl apply", with bonus templating
|
||||
func Declarative(filename string, values any) (string, error) {
|
||||
func Declarative(t *testing.T, filename string, values any) (string, error) {
|
||||
t.Helper()
|
||||
bytes, err := os.ReadFile(path.Join("testdata", filename))
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpFile, err := os.CreateTemp("", "")
|
||||
errors.CheckError(err)
|
||||
_, err = tmpFile.WriteString(Tmpl(string(bytes), values))
|
||||
errors.CheckError(err)
|
||||
tmpFile, err := os.CreateTemp(t.TempDir(), "")
|
||||
require.NoError(t, err)
|
||||
_, err = tmpFile.WriteString(Tmpl(t, string(bytes), values))
|
||||
require.NoError(t, err)
|
||||
defer tmpFile.Close()
|
||||
return Run("", "kubectl", "-n", TestNamespace(), "apply", "-f", tmpFile.Name())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
|
@ -14,15 +16,15 @@ import (
|
|||
func AddGPGPublicKey(t *testing.T) {
|
||||
t.Helper()
|
||||
keyPath, err := filepath.Abs("../fixture/gpg/" + fixture.GpgGoodKeyID)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
args := []string{"gpg", "add", "--from", keyPath}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
|
||||
if fixture.IsLocal() {
|
||||
keyData, err := os.ReadFile(keyPath)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(fmt.Sprintf("%s/app/config/gpg/source/%s", fixture.TmpDir, fixture.GpgGoodKeyID), keyData, 0o644)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
fixture.RestartRepoServer(t)
|
||||
}
|
||||
|
|
@ -33,7 +35,7 @@ func DeleteGPGPublicKey(t *testing.T) {
|
|||
args := []string{"gpg", "rm", fixture.GpgGoodKeyID}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
if fixture.IsLocal() {
|
||||
errors.CheckError(os.Remove(fmt.Sprintf("%s/app/config/gpg/source/%s", fixture.TmpDir, fixture.GpgGoodKeyID)))
|
||||
require.NoError(t, os.Remove(fmt.Sprintf("%s/app/config/gpg/source/%s", fixture.TmpDir, fixture.GpgGoodKeyID)))
|
||||
} else {
|
||||
fixture.RestartRepoServer(t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
// this implements the "when" part of given/when/then
|
||||
|
|
@ -16,7 +17,8 @@ type Actions struct {
|
|||
}
|
||||
|
||||
func (a *Actions) SetParamInNotificationConfigMap(key, value string) *Actions {
|
||||
errors.CheckError(fixture.SetParamInNotificationsConfigMap(key, value))
|
||||
a.context.t.Helper()
|
||||
require.NoError(a.context.t, fixture.SetParamInNotificationsConfigMap(key, value))
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,26 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
CertPath = mustToAbsPath("../fixture/certs/argocd-test-client.crt")
|
||||
CertKeyPath = mustToAbsPath("../fixture/certs/argocd-test-client.key")
|
||||
)
|
||||
func CertPath(t *testing.T) string {
|
||||
t.Helper()
|
||||
return mustToAbsPath(t, "../fixture/certs/argocd-test-client.crt")
|
||||
}
|
||||
|
||||
func mustToAbsPath(relativePath string) string {
|
||||
func CertKeyPath(t *testing.T) string {
|
||||
t.Helper()
|
||||
return mustToAbsPath(t, "../fixture/certs/argocd-test-client.key")
|
||||
}
|
||||
|
||||
func mustToAbsPath(t *testing.T, relativePath string) string {
|
||||
t.Helper()
|
||||
res, err := filepath.Abs(relativePath)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +33,7 @@ func mustToAbsPath(relativePath string) string {
|
|||
func AddSSHRepo(t *testing.T, insecure bool, credentials bool, repoURLType fixture.RepoURLType) {
|
||||
t.Helper()
|
||||
keyPath, err := filepath.Abs("../fixture/testrepos/id_rsa")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
args := []string{"repo", "add", fixture.RepoURL(repoURLType)}
|
||||
if credentials {
|
||||
args = append(args, "--ssh-private-key-path", keyPath)
|
||||
|
|
@ -62,8 +70,8 @@ func AddHTTPSRepoClientCert(t *testing.T, insecure bool) {
|
|||
fixture.RepoURL(fixture.RepoURLTypeHTTPSClientCert),
|
||||
"--username", fixture.GitUsername,
|
||||
"--password", fixture.GitPassword,
|
||||
"--tls-client-cert-path", CertPath,
|
||||
"--tls-client-cert-key-path", CertKeyPath,
|
||||
"--tls-client-cert-path", CertPath(t),
|
||||
"--tls-client-cert-key-path", CertKeyPath(t),
|
||||
}
|
||||
if insecure {
|
||||
args = append(args, "--insecure-skip-server-verification")
|
||||
|
|
@ -79,8 +87,8 @@ func AddHelmRepo(t *testing.T, name string) {
|
|||
fixture.RepoURL(fixture.RepoURLTypeHelm),
|
||||
"--username", fixture.GitUsername,
|
||||
"--password", fixture.GitPassword,
|
||||
"--tls-client-cert-path", CertPath,
|
||||
"--tls-client-cert-key-path", CertKeyPath,
|
||||
"--tls-client-cert-path", CertPath(t),
|
||||
"--tls-client-cert-key-path", CertKeyPath(t),
|
||||
"--type", "helm",
|
||||
"--name", name,
|
||||
}
|
||||
|
|
@ -112,9 +120,9 @@ func AddHTTPSCredentialsUserPass(t *testing.T) {
|
|||
func AddHTTPSCredentialsTLSClientCert(t *testing.T) {
|
||||
t.Helper()
|
||||
certPath, err := filepath.Abs("../fixture/certs/argocd-test-client.crt")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
keyPath, err := filepath.Abs("../fixture/certs/argocd-test-client.key")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
args := []string{
|
||||
"repocreds",
|
||||
"add",
|
||||
|
|
@ -131,9 +139,9 @@ func AddHTTPSCredentialsTLSClientCert(t *testing.T) {
|
|||
func AddHelmHTTPSCredentialsTLSClientCert(t *testing.T) {
|
||||
t.Helper()
|
||||
certPath, err := filepath.Abs("../fixture/certs/argocd-test-client.crt")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
keyPath, err := filepath.Abs("../fixture/certs/argocd-test-client.key")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
args := []string{
|
||||
"repocreds",
|
||||
"add",
|
||||
|
|
@ -161,7 +169,7 @@ func AddHelmoOCICredentialsWithoutUserPass(t *testing.T) {
|
|||
func AddSSHCredentials(t *testing.T) {
|
||||
t.Helper()
|
||||
keyPath, err := filepath.Abs("../fixture/testrepos/id_rsa")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
var repoURLType fixture.RepoURLType = fixture.RepoURLTypeSSH
|
||||
args := []string{"repocreds", "add", fixture.RepoBaseURL(repoURLType), "--ssh-private-key-path", keyPath}
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli(args...))
|
||||
|
|
@ -172,11 +180,11 @@ func PushChartToOCIRegistry(t *testing.T, chartPathName, chartName, chartVersion
|
|||
t.Helper()
|
||||
// create empty temp directory to extract chart from the registry
|
||||
tempDest, err1 := os.MkdirTemp("", "helm")
|
||||
errors.CheckError(err1)
|
||||
require.NoError(t, err1)
|
||||
defer func() { _ = os.RemoveAll(tempDest) }()
|
||||
|
||||
chartAbsPath, err2 := filepath.Abs("./testdata/" + chartPathName)
|
||||
errors.CheckError(err2)
|
||||
require.NoError(t, err2)
|
||||
|
||||
t.Setenv("HELM_EXPERIMENTAL_OCI", "1")
|
||||
errors.NewHandler(t).FailOnErr(fixture.Run("", "helm", "dependency", "build", chartAbsPath))
|
||||
|
|
|
|||
|
|
@ -4,18 +4,20 @@ import (
|
|||
"bytes"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// utility method to template a string using a map
|
||||
func Tmpl(text string, values any) string {
|
||||
func Tmpl(t *testing.T, text string, values any) string {
|
||||
t.Helper()
|
||||
parse, err := template.New(text).Parse(text)
|
||||
CheckError(err)
|
||||
require.NoError(t, err)
|
||||
buf := new(bytes.Buffer)
|
||||
err = parse.Execute(buf, values)
|
||||
CheckError(err)
|
||||
require.NoError(t, err)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
|
@ -33,5 +33,5 @@ func RunFunctionsInParallelAndCheckErrors(t *testing.T, functions []func() error
|
|||
for _, function := range functions {
|
||||
eg.Go(function)
|
||||
}
|
||||
errors.CheckError(eg.Wait())
|
||||
require.NoError(t, eg.Wait())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/argoproj/gitops-engine/pkg/cache"
|
||||
"github.com/argoproj/gitops-engine/pkg/utils/kube"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/util/argo"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
|
|
@ -34,7 +35,7 @@ func GetVersions(t *testing.T) *Versions {
|
|||
t.Helper()
|
||||
output := errors.NewHandler(t).FailOnErr(Run(".", "kubectl", "version", "-o", "json")).(string)
|
||||
version := &Versions{}
|
||||
errors.CheckError(json.Unmarshal([]byte(output), version))
|
||||
require.NoError(t, json.Unmarshal([]byte(output), version))
|
||||
return version
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apiclient/settings"
|
||||
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
func checkHealth(t *testing.T, requireHealthy bool) {
|
||||
|
|
@ -37,7 +36,7 @@ func TestAPIServerGracefulRestart(t *testing.T) {
|
|||
// Should be healthy.
|
||||
checkHealth(t, true)
|
||||
// Should trigger API server restart.
|
||||
errors.CheckError(fixture.SetParamInSettingConfigMap("url", "http://test-api-server-graceful-restart"))
|
||||
require.NoError(t, fixture.SetParamInSettingConfigMap("url", "http://test-api-server-graceful-restart"))
|
||||
|
||||
// Wait for ~5 seconds
|
||||
for i := 0; i < 50; i++ {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import (
|
|||
. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
|
||||
. "github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/argoproj/argo-cd/v3/util/lua"
|
||||
)
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ func TestPostDeleteHook(t *testing.T) {
|
|||
Expect(DoesNotExist()).
|
||||
AndAction(func() {
|
||||
hooks, err := KubeClientset.CoreV1().Pods(DeploymentNamespace()).List(context.Background(), metav1.ListOptions{})
|
||||
CheckError(err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, hooks.Items, 1)
|
||||
assert.Equal(t, "hook", hooks.Items[0].Name)
|
||||
})
|
||||
|
|
@ -334,7 +333,7 @@ func TestHookBeforeHookCreation(t *testing.T) {
|
|||
And(func(_ *Application) {
|
||||
var err error
|
||||
creationTimestamp1, err = getCreationTimestamp()
|
||||
CheckError(err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, creationTimestamp1)
|
||||
// pause to ensure that timestamp will change
|
||||
time.Sleep(1 * time.Second)
|
||||
|
|
@ -349,7 +348,7 @@ func TestHookBeforeHookCreation(t *testing.T) {
|
|||
Expect(Pod(func(p corev1.Pod) bool { return p.Name == "hook" })).
|
||||
And(func(_ *Application) {
|
||||
creationTimestamp2, err := getCreationTimestamp()
|
||||
CheckError(err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, creationTimestamp2)
|
||||
assert.NotEqual(t, creationTimestamp1, creationTimestamp2)
|
||||
})
|
||||
|
|
@ -446,7 +445,7 @@ func testHookFinalizer(t *testing.T, hookType HookType) {
|
|||
t.Helper()
|
||||
Given(t).
|
||||
And(func() {
|
||||
CheckError(SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
|
||||
lua.GetConfigMapKey(schema.FromAPIVersionAndKind("batch/v1", "Job")): {
|
||||
HealthLua: `
|
||||
local hs = {}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
|||
func TestGetRepoWithInheritedCreds(t *testing.T) {
|
||||
app.Given(t).And(func() {
|
||||
// create repo credentials
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli("repocreds", "add", fixture.RepoURL(fixture.RepoURLTypeHTTPSOrg), "--github-app-id", fixture.GithubAppID, "--github-app-installation-id", fixture.GithubAppInstallationID, "--github-app-private-key-path", repos.CertKeyPath))
|
||||
errors.NewHandler(t).FailOnErr(fixture.RunCli("repocreds", "add", fixture.RepoURL(fixture.RepoURLTypeHTTPSOrg), "--github-app-id", fixture.GithubAppID, "--github-app-installation-id", fixture.GithubAppInstallationID, "--github-app-private-key-path", repos.CertKeyPath(t)))
|
||||
|
||||
repoURL := fixture.RepoURL(fixture.RepoURLTypeHTTPS)
|
||||
|
||||
|
|
@ -107,8 +107,8 @@ func TestAddRemoveHelmRepo(t *testing.T) {
|
|||
"--type", "helm",
|
||||
"--username", fixture.GitUsername,
|
||||
"--password", fixture.GitPassword,
|
||||
"--tls-client-cert-path", repos.CertPath,
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath)
|
||||
"--tls-client-cert-path", repos.CertPath(t),
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath(t))
|
||||
require.NoError(t, err)
|
||||
|
||||
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
||||
|
|
@ -151,8 +151,8 @@ func TestAddHelmRepoInsecureSkipVerify(t *testing.T) {
|
|||
"--username", fixture.GitUsername,
|
||||
"--password", fixture.GitPassword,
|
||||
"--insecure-skip-server-verification",
|
||||
"--tls-client-cert-path", repos.CertPath,
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath)
|
||||
"--tls-client-cert-path", repos.CertPath(t),
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath(t))
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -197,8 +197,8 @@ func TestFailOnCreatePrivateNonGitRepoWithBearerToken(t *testing.T) {
|
|||
repoURL := fixture.RepoURL(fixture.RepoURLTypeHelm)
|
||||
_, err := fixture.RunCli("repo", "add", repoURL, "--bearer-token", fixture.GitBearerToken,
|
||||
"--insecure-skip-server-verification",
|
||||
"--tls-client-cert-path", repos.CertPath,
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath,
|
||||
"--tls-client-cert-path", repos.CertPath(t),
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath(t),
|
||||
"--name", "testrepo",
|
||||
"--type", "helm")
|
||||
require.ErrorContains(t, err, "--bearer-token is only supported for Git repositories")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ func TestSyncWithStatusIgnored(t *testing.T) {
|
|||
Path(guestbookPath).
|
||||
When().
|
||||
And(func() {
|
||||
errors.CheckError(fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{
|
||||
"/": {
|
||||
IgnoreDifferences: OverrideIgnoreDiff{JSONPointers: []string{"/status"}},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import (
|
|||
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture"
|
||||
. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
func TestFixingDegradedApp(t *testing.T) {
|
||||
|
|
@ -20,7 +20,7 @@ func TestFixingDegradedApp(t *testing.T) {
|
|||
IgnoreErrors().
|
||||
CreateApp().
|
||||
And(func() {
|
||||
errors.CheckError(SetResourceOverrides(map[string]ResourceOverride{
|
||||
require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
|
||||
"ConfigMap": {
|
||||
HealthLua: `return { status = obj.metadata.annotations and obj.metadata.annotations['health'] or 'Degraded' }`,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type AddBinDirToPath struct {
|
||||
|
|
@ -17,11 +18,11 @@ func (h AddBinDirToPath) Close() {
|
|||
}
|
||||
|
||||
// add the hack path which has the argocd binary
|
||||
func NewBinDirToPath() AddBinDirToPath {
|
||||
func NewBinDirToPath(t *testing.T) AddBinDirToPath {
|
||||
t.Helper()
|
||||
originalPath := os.Getenv("PATH")
|
||||
binDir, err := filepath.Abs("../../dist")
|
||||
errors.CheckError(err)
|
||||
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", originalPath, binDir))
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
t.Setenv("PATH", fmt.Sprintf("%s:%s", originalPath, binDir))
|
||||
return AddBinDirToPath{originalPath}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ import (
|
|||
"k8s.io/client-go/kubernetes/fake"
|
||||
kubetesting "k8s.io/client-go/testing"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -38,21 +36,23 @@ var testClaims = ServiceAccountClaims{
|
|||
},
|
||||
}
|
||||
|
||||
func newServiceAccount() *corev1.ServiceAccount {
|
||||
func newServiceAccount(t *testing.T) *corev1.ServiceAccount {
|
||||
t.Helper()
|
||||
saBytes, err := os.ReadFile("./testdata/argocd-manager-sa.yaml")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
var sa corev1.ServiceAccount
|
||||
err = yaml.Unmarshal(saBytes, &sa)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
return &sa
|
||||
}
|
||||
|
||||
func newServiceAccountSecret() *corev1.Secret {
|
||||
func newServiceAccountSecret(t *testing.T) *corev1.Secret {
|
||||
t.Helper()
|
||||
secretBytes, err := os.ReadFile("./testdata/argocd-manager-sa-token.yaml")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
var secret corev1.Secret
|
||||
err = yaml.Unmarshal(secretBytes, &secret)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
return &secret
|
||||
}
|
||||
|
||||
|
|
@ -175,17 +175,17 @@ func TestInstallClusterManagerRBAC(t *testing.T) {
|
|||
|
||||
func TestUninstallClusterManagerRBAC(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
cs := fake.NewClientset(newServiceAccountSecret())
|
||||
cs := fake.NewClientset(newServiceAccountSecret(t))
|
||||
err := UninstallClusterManagerRBAC(cs)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGenerateNewClusterManagerSecret(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(newServiceAccountSecret())
|
||||
kubeclientset := fake.NewClientset(newServiceAccountSecret(t))
|
||||
kubeclientset.ReactionChain = nil
|
||||
|
||||
generatedSecret := newServiceAccountSecret()
|
||||
generatedSecret := newServiceAccountSecret(t)
|
||||
generatedSecret.Name = "argocd-manager-token-abc123"
|
||||
generatedSecret.Data = map[string][]byte{
|
||||
"token": []byte("fake-token"),
|
||||
|
|
@ -202,13 +202,13 @@ func TestGenerateNewClusterManagerSecret(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRotateServiceAccountSecrets(t *testing.T) {
|
||||
generatedSecret := newServiceAccountSecret()
|
||||
generatedSecret := newServiceAccountSecret(t)
|
||||
generatedSecret.Name = "argocd-manager-token-abc123"
|
||||
generatedSecret.Data = map[string][]byte{
|
||||
"token": []byte("fake-token"),
|
||||
}
|
||||
|
||||
kubeclientset := fake.NewClientset(newServiceAccount(), newServiceAccountSecret(), generatedSecret)
|
||||
kubeclientset := fake.NewClientset(newServiceAccount(t), newServiceAccountSecret(t), generatedSecret)
|
||||
|
||||
err := RotateServiceAccountSecrets(kubeclientset, &testClaims, generatedSecret)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -228,8 +228,8 @@ func TestRotateServiceAccountSecrets(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetServiceAccountBearerToken(t *testing.T) {
|
||||
sa := newServiceAccount()
|
||||
tokenSecret := newServiceAccountSecret()
|
||||
sa := newServiceAccount(t)
|
||||
tokenSecret := newServiceAccountSecret(t)
|
||||
dockercfgSecret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "argocd-manager-dockercfg-d8j66",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -12,13 +13,6 @@ const (
|
|||
ErrorGeneric = 20
|
||||
)
|
||||
|
||||
// CheckError logs a fatal message and exits with ErrorGeneric if err is not nil
|
||||
func CheckError(err error) {
|
||||
if err != nil {
|
||||
Fatal(ErrorGeneric, err)
|
||||
}
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
t *testing.T
|
||||
}
|
||||
|
|
@ -32,12 +26,17 @@ func NewHandler(t *testing.T) *Handler {
|
|||
// text := FailOrErr(Foo).(string)
|
||||
func (h *Handler) FailOnErr(v any, err error) any {
|
||||
h.t.Helper()
|
||||
if err != nil {
|
||||
h.t.Fatal(err)
|
||||
}
|
||||
require.NoError(h.t, err)
|
||||
return v
|
||||
}
|
||||
|
||||
// CheckError logs a fatal message and exits with ErrorGeneric if err is not nil
|
||||
func CheckError(err error) {
|
||||
if err != nil {
|
||||
Fatal(ErrorGeneric, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Fatal is a wrapper for logrus.Fatal() to exit with custom code
|
||||
func Fatal(exitcode int, args ...any) {
|
||||
exitfunc := func() {
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ func TestVerifyCommitSignature(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewFactory(t *testing.T) {
|
||||
addBinDirToPath := path.NewBinDirToPath()
|
||||
addBinDirToPath := path.NewBinDirToPath(t)
|
||||
defer addBinDirToPath.Close()
|
||||
closer := log.Debug()
|
||||
defer closer()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
appsv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/util/cli"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
type testNormalizer struct{}
|
||||
|
|
@ -121,7 +120,7 @@ func TestLuaResourceActionsScript(t *testing.T) {
|
|||
vm := VM{
|
||||
UseOpenLibs: true,
|
||||
}
|
||||
obj := getObj(filepath.Join(dir, test.InputPath))
|
||||
obj := getObj(t, filepath.Join(dir, test.InputPath))
|
||||
discoveryLua, err := vm.GetResourceActionDiscovery(obj)
|
||||
require.NoError(t, err)
|
||||
result, err := vm.ExecuteResourceActionDiscovery(obj, discoveryLua)
|
||||
|
|
@ -142,7 +141,7 @@ func TestLuaResourceActionsScript(t *testing.T) {
|
|||
// privileges that API server has.
|
||||
// UseOpenLibs: true,
|
||||
}
|
||||
sourceObj := getObj(filepath.Join(dir, test.InputPath))
|
||||
sourceObj := getObj(t, filepath.Join(dir, test.InputPath))
|
||||
action, err := vm.GetResourceAction(sourceObj, test.Action)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
|
@ -208,14 +207,14 @@ func TestLuaResourceActionsScript(t *testing.T) {
|
|||
func getExpectedObjectList(t *testing.T, path string) *unstructured.UnstructuredList {
|
||||
t.Helper()
|
||||
yamlBytes, err := os.ReadFile(path)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
unstructuredList := &unstructured.UnstructuredList{}
|
||||
yamlString := bytes.NewBuffer(yamlBytes).String()
|
||||
if yamlString[0] == '-' {
|
||||
// The string represents a new-style action array output, where each member is a wrapper around a k8s unstructured resource
|
||||
objList := make([]map[string]any, 5)
|
||||
err = yaml.Unmarshal(yamlBytes, &objList)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
unstructuredList.Items = make([]unstructured.Unstructured, len(objList))
|
||||
// Append each map in objList to the Items field of the new object
|
||||
for i, obj := range objList {
|
||||
|
|
@ -227,7 +226,7 @@ func getExpectedObjectList(t *testing.T, path string) *unstructured.Unstructured
|
|||
// The string represents an old-style action object output, which is a k8s unstructured resource
|
||||
obj := make(map[string]any)
|
||||
err = yaml.Unmarshal(yamlBytes, &obj)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
unstructuredList.Items = make([]unstructured.Unstructured, 1)
|
||||
unstructuredList.Items[0] = unstructured.Unstructured{Object: obj}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ import (
|
|||
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
)
|
||||
|
||||
type TestStructure struct {
|
||||
|
|
@ -23,12 +22,13 @@ type IndividualTest struct {
|
|||
HealthStatus health.HealthStatus `yaml:"healthStatus"`
|
||||
}
|
||||
|
||||
func getObj(path string) *unstructured.Unstructured {
|
||||
func getObj(t *testing.T, path string) *unstructured.Unstructured {
|
||||
t.Helper()
|
||||
yamlBytes, err := os.ReadFile(path)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
obj := make(map[string]any)
|
||||
err = yaml.Unmarshal(yamlBytes, &obj)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
return &unstructured.Unstructured{Object: obj}
|
||||
}
|
||||
|
|
@ -38,24 +38,24 @@ func TestLuaHealthScript(t *testing.T) {
|
|||
if !strings.Contains(path, "health.lua") {
|
||||
return nil
|
||||
}
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
dir := filepath.Dir(path)
|
||||
yamlBytes, err := os.ReadFile(dir + "/health_test.yaml")
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
var resourceTest TestStructure
|
||||
err = yaml.Unmarshal(yamlBytes, &resourceTest)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
for i := range resourceTest.Tests {
|
||||
test := resourceTest.Tests[i]
|
||||
t.Run(test.InputPath, func(t *testing.T) {
|
||||
vm := VM{
|
||||
UseOpenLibs: true,
|
||||
}
|
||||
obj := getObj(filepath.Join(dir, test.InputPath))
|
||||
obj := getObj(t, filepath.Join(dir, test.InputPath))
|
||||
script, _, err := vm.GetHealthScript(obj)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
result, err := vm.ExecuteHealthLua(obj, script)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &test.HealthStatus, result)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func TestRandomPasswordVerificationDelay(t *testing.T) {
|
|||
// the maximum time limit required by `TestRandomPasswordVerificationDelay`.
|
||||
|
||||
var sleptFor time.Duration
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("password", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "password", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
mgr.verificationDelayNoiseEnabled = true
|
||||
mgr.sleep = func(d time.Duration) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import (
|
|||
"github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v3/test"
|
||||
claimsutil "github.com/argoproj/argo-cd/v3/util/claims"
|
||||
"github.com/argoproj/argo-cd/v3/util/errors"
|
||||
jwtutil "github.com/argoproj/argo-cd/v3/util/jwt"
|
||||
"github.com/argoproj/argo-cd/v3/util/password"
|
||||
"github.com/argoproj/argo-cd/v3/util/settings"
|
||||
|
|
@ -41,11 +40,12 @@ func getProjLister(objects ...runtime.Object) v1alpha1.AppProjectNamespaceLister
|
|||
return test.NewFakeProjListerFromInterface(apps.NewSimpleClientset(objects...).ArgoprojV1alpha1().AppProjects("argocd"))
|
||||
}
|
||||
|
||||
func getKubeClient(pass string, enabled bool, capabilities ...settings.AccountCapability) *fake.Clientset {
|
||||
func getKubeClient(t *testing.T, pass string, enabled bool, capabilities ...settings.AccountCapability) *fake.Clientset {
|
||||
t.Helper()
|
||||
const defaultSecretKey = "Hello, world!"
|
||||
|
||||
bcrypt, err := password.HashPassword(pass)
|
||||
errors.CheckError(err)
|
||||
require.NoError(t, err)
|
||||
if len(capabilities) == 0 {
|
||||
capabilities = []settings.AccountCapability{settings.AccountCapabilityLogin, settings.AccountCapabilityApiKey}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ func TestSessionManager_AdminToken(t *testing.T) {
|
|||
redisClient, closer := test.NewInMemoryRedis()
|
||||
defer closer()
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(redisClient))
|
||||
|
||||
token, err := mgr.Create("admin:login", 0, "123")
|
||||
|
|
@ -110,7 +110,7 @@ func TestSessionManager_AdminToken_ExpiringSoon(t *testing.T) {
|
|||
redisClient, closer := test.NewInMemoryRedis()
|
||||
defer closer()
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(redisClient))
|
||||
|
||||
token, err := mgr.Create("admin:login", int64(autoRegenerateTokenDuration.Seconds()-1), "123")
|
||||
|
|
@ -138,7 +138,7 @@ func TestSessionManager_AdminToken_Revoked(t *testing.T) {
|
|||
redisClient, closer := test.NewInMemoryRedis()
|
||||
defer closer()
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", true), "argocd")
|
||||
storage := NewUserStateStorage(redisClient)
|
||||
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), storage)
|
||||
|
|
@ -154,7 +154,7 @@ func TestSessionManager_AdminToken_Revoked(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSessionManager_AdminToken_Deactivated(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", false), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", false), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
|
||||
token, err := mgr.Create("admin:login", 0, "abc")
|
||||
|
|
@ -165,7 +165,7 @@ func TestSessionManager_AdminToken_Deactivated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSessionManager_AdminToken_LoginCapabilityDisabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", true, settings.AccountCapabilityLogin), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", true, settings.AccountCapabilityLogin), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
|
||||
token, err := mgr.Create("admin", 0, "abc")
|
||||
|
|
@ -176,7 +176,7 @@ func TestSessionManager_AdminToken_LoginCapabilityDisabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSessionManager_ProjectToken(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("pass", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "pass", true), "argocd")
|
||||
|
||||
t.Run("Valid Token", func(t *testing.T) {
|
||||
proj := appv1.AppProject{
|
||||
|
|
@ -422,7 +422,7 @@ func TestVerifyUsernamePassword(t *testing.T) {
|
|||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(password, !tc.disabled), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, password, !tc.disabled), "argocd")
|
||||
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
|
||||
|
|
@ -492,7 +492,7 @@ func TestCacheValueGetters(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLoginRateLimiter(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("password", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "password", true), "argocd")
|
||||
storage := NewUserStateStorage(nil)
|
||||
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), storage)
|
||||
|
|
@ -533,14 +533,14 @@ func TestMaxUsernameLength(t *testing.T) {
|
|||
for i := 0; i < maxUsernameLength+1; i++ {
|
||||
username += "a"
|
||||
}
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("password", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "password", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
err := mgr.VerifyUsernamePassword(username, "password")
|
||||
assert.ErrorContains(t, err, fmt.Sprintf(usernameTooLongError, maxUsernameLength))
|
||||
}
|
||||
|
||||
func TestMaxCacheSize(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("password", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "password", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
|
||||
invalidUsers := []string{"invalid1", "invalid2", "invalid3", "invalid4", "invalid5", "invalid6", "invalid7"}
|
||||
|
|
@ -556,7 +556,7 @@ func TestMaxCacheSize(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFailedAttemptsExpiry(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient("password", true), "argocd")
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), getKubeClient(t, "password", true), "argocd")
|
||||
mgr := newSessionManager(settingsMgr, getProjLister(), NewUserStateStorage(nil))
|
||||
|
||||
invalidUsers := []string{"invalid1", "invalid2", "invalid3", "invalid4", "invalid5", "invalid6", "invalid7"}
|
||||
|
|
|
|||
Loading…
Reference in a new issue