diff --git a/controllers/argocd/applicationset_test.go b/controllers/argocd/applicationset_test.go index d956638e1..df3bb742d 100644 --- a/controllers/argocd/applicationset_test.go +++ b/controllers/argocd/applicationset_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -45,10 +45,10 @@ func TestReconcileApplicationSet_CreateDeployments(t *testing.T) { sa := corev1.ServiceAccount{} - assert.NilError(t, r.reconcileApplicationSetDeployment(a, &sa)) + assert.NoError(t, r.reconcileApplicationSetDeployment(a, &sa)) deployment := &appsv1.Deployment{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -176,10 +176,10 @@ func TestReconcileApplicationSet_UpdateExistingDeployments(t *testing.T) { sa := corev1.ServiceAccount{} - assert.NilError(t, r.reconcileApplicationSetDeployment(a, &sa)) + assert.NoError(t, r.reconcileApplicationSetDeployment(a, &sa)) deployment := &appsv1.Deployment{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -200,10 +200,10 @@ func TestReconcileApplicationSet_Deployments_resourceRequirements(t *testing.T) sa := corev1.ServiceAccount{} - assert.NilError(t, r.reconcileApplicationSetDeployment(a, &sa)) + assert.NoError(t, r.reconcileApplicationSetDeployment(a, &sa)) deployment := &appsv1.Deployment{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -312,10 +312,10 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) { a.Spec.ApplicationSet = test.appSetField sa := corev1.ServiceAccount{} - assert.NilError(t, r.reconcileApplicationSetDeployment(a, &sa)) + assert.NoError(t, r.reconcileApplicationSetDeployment(a, &sa)) deployment := &appsv1.Deployment{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -337,10 +337,10 @@ func TestReconcileApplicationSet_ServiceAccount(t *testing.T) { r := makeTestReconciler(t, a) retSa, err := r.reconcileApplicationSetServiceAccount(a) - assert.NilError(t, err) + assert.NoError(t, err) sa := &corev1.ServiceAccount{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -359,10 +359,10 @@ func TestReconcileApplicationSet_Role(t *testing.T) { r := makeTestReconciler(t, a) roleRet, err := r.reconcileApplicationSetRole(a) - assert.NilError(t, err) + assert.NoError(t, err) role := &rbacv1.Role{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", @@ -396,7 +396,7 @@ func TestReconcileApplicationSet_Role(t *testing.T) { sort.Strings(expectedResources) sort.Strings(foundResources) - assert.DeepEqual(t, expectedResources, foundResources) + assert.Equal(t, expectedResources, foundResources) } func TestReconcileApplicationSet_RoleBinding(t *testing.T) { @@ -408,10 +408,10 @@ func TestReconcileApplicationSet_RoleBinding(t *testing.T) { sa := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: "sa-name"}} err := r.reconcileApplicationSetRoleBinding(a, role, sa) - assert.NilError(t, err) + assert.NoError(t, err) roleBinding := &rbacv1.RoleBinding{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "argocd-applicationset-controller", diff --git a/controllers/argocd/argocd_controller_test.go b/controllers/argocd/argocd_controller_test.go index cf5e0a19a..c643da43a 100644 --- a/controllers/argocd/argocd_controller_test.go +++ b/controllers/argocd/argocd_controller_test.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -50,7 +50,7 @@ func TestReconcileArgoCD_Reconcile_with_deleted(t *testing.T) { a := makeTestArgoCD(deletedAt(time.Now())) r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -59,7 +59,7 @@ func TestReconcileArgoCD_Reconcile_with_deleted(t *testing.T) { }, } res, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) if res.Requeue { t.Fatal("reconcile requeued request") } @@ -78,7 +78,7 @@ func TestReconcileArgoCD_Reconcile(t *testing.T) { a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -88,7 +88,7 @@ func TestReconcileArgoCD_Reconcile(t *testing.T) { } res, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) if res.Requeue { t.Fatal("reconcile requeued request") } @@ -116,7 +116,7 @@ func TestReconcileArgoCD_CleanUp(t *testing.T) { resources := []runtime.Object{a} resources = append(resources, clusterResources(a)...) r := makeTestReconciler(t, resources...) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -125,7 +125,7 @@ func TestReconcileArgoCD_CleanUp(t *testing.T) { }, } res, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) if res.Requeue { t.Fatal("reconcile requeued request") } @@ -163,7 +163,7 @@ func TestReconcileArgoCD_CleanUp(t *testing.T) { // check if namespace label was removed ns := &corev1.Namespace{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: a.Namespace}, ns)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: a.Namespace}, ns)) if _, ok := ns.Labels[common.ArgoCDManagedByLabel]; ok { t.Errorf("Expected the label[%v] to be removed from the namespace[%v]", common.ArgoCDManagedByLabel, a.Namespace) } diff --git a/controllers/argocd/configmap_test.go b/controllers/argocd/configmap_test.go index 4f15f1ab3..a997f38ea 100644 --- a/controllers/argocd/configmap_test.go +++ b/controllers/argocd/configmap_test.go @@ -22,8 +22,8 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" - "gotest.tools/assert" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -42,10 +42,10 @@ func TestReconcileArgoCD_reconcileTLSCerts(t *testing.T) { a := makeTestArgoCD(initialCerts(t, "root-ca.example.com")) r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileTLSCerts(a)) + assert.NoError(t, r.reconcileTLSCerts(a)) configMap := &corev1.ConfigMap{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: common.ArgoCDTLSCertsConfigMapName, @@ -63,13 +63,13 @@ func TestReconcileArgoCD_reconcileTLSCerts_withUpdate(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileTLSCerts(a)) + assert.NoError(t, r.reconcileTLSCerts(a)) a = makeTestArgoCD(initialCerts(t, "testing.example.com")) - assert.NilError(t, r.reconcileTLSCerts(a)) + assert.NoError(t, r.reconcileTLSCerts(a)) configMap := &corev1.ConfigMap{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: common.ArgoCDTLSCertsConfigMapName, @@ -89,14 +89,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap(t *testing.T) { r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) want := map[string]string{ "application.instanceLabelKey": common.ArgoCDDefaultApplicationInstanceLabelKey, @@ -137,17 +137,17 @@ func TestReconcileArgoCD_reconcileEmptyArgoConfigMap(t *testing.T) { } err := r.Client.Create(context.TODO(), emptyArgoConfigmap) - assert.NilError(t, err) + assert.NoError(t, err) err = r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) } func TestReconcileArgoCDCM_withRepoCredentials(t *testing.T) { @@ -175,13 +175,13 @@ func TestReconcileArgoCDCM_withRepoCredentials(t *testing.T) { r := makeTestReconciler(t, a, cm) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if got := cm.Data[common.ArgoCDKeyRepositoryCredentials]; got != a.Spec.RepositoryCredentials { t.Fatalf("reconcileArgoConfigMap failed: got %s, want %s", got, a.Spec.RepositoryCredentials) @@ -196,14 +196,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withDisableAdmin(t *testing.T) { r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c := cm.Data["admin.enabled"]; c != "false" { t.Fatalf("reconcileArgoConfigMap failed got %q, want %q", c, "false") @@ -227,14 +227,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withDexConnector(t *testing.T) { secret := argoutil.NewSecretWithName(a, "token") r := makeTestReconciler(t, a, sa, secret) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) dex, ok := cm.Data["dex.config"] if !ok { @@ -243,7 +243,7 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withDexConnector(t *testing.T) { m := make(map[string]interface{}) err = yaml.Unmarshal([]byte(dex), &m) - assert.NilError(t, err, fmt.Sprintf("failed to unmarshal %s", dex)) + assert.NoError(t, err, fmt.Sprintf("failed to unmarshal %s", dex)) connectors, ok := m["connectors"] if !ok { @@ -262,14 +262,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withDexDisabled(t *testing.T) { os.Setenv("DISABLE_DEX", "true") err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c, ok := cm.Data["dex.config"]; ok { t.Fatalf("reconcileArgoConfigMap failed, dex.config = %q", c) @@ -281,14 +281,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withMultipleSSOConfigured(t *tes r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c, ok := cm.Data["dex.openShiftOAuth"]; !ok && len(c) != 0 { t.Fatalf("reconcileArgoConfigMap didn't skip setting dex when keycloak is configured, dex.openShiftOAuth = %q", c) @@ -309,14 +309,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withKustomizeVersions(t *testing r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if diff := cmp.Diff(cm.Data["kustomize.version.v4.1.0"], "/path/to/kustomize-4.1"); diff != "" { t.Fatalf("failed to reconcile configmap:\n%s", diff) @@ -331,14 +331,14 @@ func TestReconcileArgoCD_reconcileGPGKeysConfigMap(t *testing.T) { r := makeTestReconciler(t, a) err := r.reconcileGPGKeysConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDGPGKeysConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) // Currently the gpg keys configmap is empty } @@ -353,14 +353,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withResourceInclusions(t *testin r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c := cm.Data["resource.inclusions"]; c != customizations { t.Fatalf("reconcileArgoConfigMap failed got %q, want %q", c, customizations) @@ -368,13 +368,13 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withResourceInclusions(t *testin a.Spec.ResourceInclusions = updatedCustomizations err = r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c := cm.Data["resource.inclusions"]; c != updatedCustomizations { t.Fatalf("reconcileArgoConfigMap failed got %q, want %q", c, updatedCustomizations) @@ -391,14 +391,14 @@ func TestReconcileArgoCD_reconcileArgoConfigMap_withResourceCustomizations(t *te r := makeTestReconciler(t, a) err := r.reconcileArgoConfigMap(a) - assert.NilError(t, err) + assert.NoError(t, err) cm := &corev1.ConfigMap{} err = r.Client.Get(context.TODO(), types.NamespacedName{ Name: common.ArgoCDConfigMapName, Namespace: testNamespace, }, cm) - assert.NilError(t, err) + assert.NoError(t, err) if c := cm.Data["resource.customizations"]; c != customizations { t.Fatalf("reconcileArgoConfigMap failed got %q, want %q", c, customizations) diff --git a/controllers/argocd/custommapper_test.go b/controllers/argocd/custommapper_test.go index 9528486ed..7f30fc82d 100644 --- a/controllers/argocd/custommapper_test.go +++ b/controllers/argocd/custommapper_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" "github.com/argoproj-labs/argocd-operator/api/v1alpha1" "github.com/argoproj-labs/argocd-operator/common" @@ -327,7 +327,7 @@ func TestReconcileArgoCD_namespaceResourceMapper(t *testing.T) { // Fake client returns an error if ResourceVersion is not nil a.ResourceVersion = "" - assert.NilError(t, r.Client.Create(context.TODO(), a)) + assert.NoError(t, r.Client.Create(context.TODO(), a)) type test struct { name string diff --git a/controllers/argocd/hooks_test.go b/controllers/argocd/hooks_test.go index 90158bebd..9ad9235dc 100644 --- a/controllers/argocd/hooks_test.go +++ b/controllers/argocd/hooks_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/rbac/v1" @@ -52,9 +52,9 @@ func TestReconcileArgoCD_testDeploymentHook(t *testing.T) { testDeployment := makeTestDeployment() - assert.NilError(t, applyReconcilerHook(a, testDeployment, "")) + assert.NoError(t, applyReconcilerHook(a, testDeployment, "")) var expectedReplicas int32 = 3 - assert.DeepEqual(t, &expectedReplicas, testDeployment.Spec.Replicas) + assert.Equal(t, &expectedReplicas, testDeployment.Spec.Replicas) } func TestReconcileArgoCD_testMultipleHooks(t *testing.T) { @@ -67,16 +67,16 @@ func TestReconcileArgoCD_testMultipleHooks(t *testing.T) { Register(testDeploymentHook) Register(testClusterRoleHook) - assert.NilError(t, applyReconcilerHook(a, testDeployment, "")) - assert.NilError(t, applyReconcilerHook(a, testClusterRole, "")) + assert.NoError(t, applyReconcilerHook(a, testDeployment, "")) + assert.NoError(t, applyReconcilerHook(a, testClusterRole, "")) // Verify if testDeploymentHook is executed successfully var expectedReplicas int32 = 3 - assert.DeepEqual(t, &expectedReplicas, testDeployment.Spec.Replicas) + assert.Equal(t, &expectedReplicas, testDeployment.Spec.Replicas) // Verify if testClusterRoleHook is executed successfully want := append(makeTestPolicyRules(), policyRuleForApplicationController()...) - assert.DeepEqual(t, want, testClusterRole.Rules) + assert.Equal(t, want, testClusterRole.Rules) } func TestReconcileArgoCD_hooks_end_upon_error(t *testing.T) { @@ -87,7 +87,7 @@ func TestReconcileArgoCD_hooks_end_upon_error(t *testing.T) { testClusterRole := makeTestClusterRole() assert.Error(t, applyReconcilerHook(a, testClusterRole, ""), "this is a test error") - assert.DeepEqual(t, makeTestPolicyRules(), testClusterRole.Rules) + assert.Equal(t, makeTestPolicyRules(), testClusterRole.Rules) } func resetHooks() func() { diff --git a/controllers/argocd/keycloak_client_test.go b/controllers/argocd/keycloak_client_test.go index d00e179e2..f9888c64c 100644 --- a/controllers/argocd/keycloak_client_test.go +++ b/controllers/argocd/keycloak_client_test.go @@ -9,7 +9,7 @@ import ( jsoniter "github.com/json-iterator/go" keycloakv1alpha1 "github.com/keycloak/keycloak-operator/pkg/apis/keycloak/v1alpha1" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" ) func TestKeycloak_testRealmCreation(t *testing.T) { @@ -30,7 +30,7 @@ func TestKeycloak_testRealmCreation(t *testing.T) { realm, _ := createRealmConfig(data) _, err := h.post(realm, "test") - assert.NilError(t, err) + assert.NoError(t, err) } func TestKeycloak_testLogin(t *testing.T) { @@ -43,10 +43,10 @@ func TestKeycloak_testLogin(t *testing.T) { } json, err := jsoniter.Marshal(response) - assert.NilError(t, err) + assert.NoError(t, err) size, err := w.Write(json) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, size, len(json)) w.WriteHeader(204) @@ -62,7 +62,7 @@ func TestKeycloak_testLogin(t *testing.T) { err := h.login("dummy", "dummy") - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, h.token, "dummy") } @@ -80,29 +80,29 @@ func TestClient_useKeycloakServerCertificate(t *testing.T) { pemCert := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: ts.Certificate().Raw}) requester, err := defaultRequester(pemCert, true) - assert.NilError(t, err) + assert.NoError(t, err) httpClient, ok := requester.(*http.Client) - assert.Check(t, ok) + assert.Equal(t, true, ok) assert.Equal(t, httpClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, insecure) request, err := http.NewRequest("GET", ts.URL, nil) - assert.NilError(t, err) + assert.NoError(t, err) resp, err := requester.Do(request) - assert.NilError(t, err) + assert.NoError(t, err) defer resp.Body.Close() assert.Equal(t, resp.StatusCode, 200) // Set verifyTLS=false, verify an insecure TLS connection is returned even the serverCertificate is available. requester, err = defaultRequester(pemCert, false) - assert.NilError(t, err) + assert.NoError(t, err) httpClient, ok = requester.(*http.Client) - assert.Check(t, ok) + assert.Equal(t, true, ok) assert.Equal(t, httpClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, !insecure) request, err = http.NewRequest("GET", ts.URL, nil) - assert.NilError(t, err) + assert.NoError(t, err) resp, err = requester.Do(request) - assert.NilError(t, err) + assert.NoError(t, err) defer resp.Body.Close() assert.Equal(t, resp.StatusCode, 200) diff --git a/controllers/argocd/keycloak_test.go b/controllers/argocd/keycloak_test.go index c662272fe..6b1c82ebe 100644 --- a/controllers/argocd/keycloak_test.go +++ b/controllers/argocd/keycloak_test.go @@ -21,7 +21,7 @@ import ( appsv1 "github.com/openshift/api/apps/v1" routev1 "github.com/openshift/api/route/v1" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" resourcev1 "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -88,7 +88,7 @@ func TestKeycloakContainerImage(t *testing.T) { // When ENV variable is set. err := os.Setenv(common.ArgoCDKeycloakImageEnvName, "envImage:latest") defer os.Unsetenv(common.ArgoCDKeycloakImageEnvName) - assert.NilError(t, err) + assert.NoError(t, err) testImage = getKeycloakContainerImage(cr) assert.Equal(t, testImage, "envImage:latest") @@ -107,7 +107,7 @@ func TestNewKeycloakTemplateInstance(t *testing.T) { Provider: "keycloak", } tmplInstance, err := newKeycloakTemplateInstance(a) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, tmplInstance.Name, "rhsso") assert.Equal(t, tmplInstance.Namespace, a.Namespace) @@ -119,7 +119,7 @@ func TestNewKeycloakTemplate(t *testing.T) { Provider: "keycloak", } tmpl, err := newKeycloakTemplate(a) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, tmpl.Name, "rhsso") assert.Equal(t, tmpl.Namespace, a.Namespace) @@ -147,10 +147,10 @@ func TestNewKeycloakTemplate_testDeploymentConfig(t *testing.T) { }, }, } - assert.DeepEqual(t, dc.Spec.Strategy, strategy) + assert.Equal(t, dc.Spec.Strategy, strategy) assert.Equal(t, dc.Spec.Template.ObjectMeta.Name, "${APPLICATION_NAME}") - assert.DeepEqual(t, dc.Spec.Template.Spec.Volumes, fakeVolumes) + assert.Equal(t, dc.Spec.Template.Spec.Volumes, fakeVolumes) } func TestNewKeycloakTemplate_testKeycloakContainer(t *testing.T) { @@ -173,14 +173,14 @@ func TestKeycloakResources(t *testing.T) { kc := getKeycloakContainer(a) // Verify resource requirements are set to default. - assert.DeepEqual(t, kc.Resources, defaultKeycloakResources()) + assert.Equal(t, kc.Resources, defaultKeycloakResources()) // Verify resource requirements are overridden by ArgoCD CR(.spec.SSO.Resources) fR := getFakeKeycloakResources() a.Spec.SSO.Resources = &fR kc = getKeycloakContainer(a) - assert.DeepEqual(t, kc.Resources, getFakeKeycloakResources()) + assert.Equal(t, kc.Resources, getFakeKeycloakResources()) } func TestNewKeycloakTemplate_testConfigmap(t *testing.T) { @@ -193,7 +193,7 @@ func TestNewKeycloakTemplate_testService(t *testing.T) { svc := getKeycloakServiceTemplate(fakeNs) assert.Equal(t, svc.Name, "${APPLICATION_NAME}") assert.Equal(t, svc.Namespace, fakeNs) - assert.DeepEqual(t, svc.Spec.Selector, map[string]string{ + assert.Equal(t, svc.Spec.Selector, map[string]string{ "deploymentConfig": "${APPLICATION_NAME}"}) } @@ -201,9 +201,9 @@ func TestNewKeycloakTemplate_testRoute(t *testing.T) { route := getKeycloakRouteTemplate(fakeNs) assert.Equal(t, route.Name, "${APPLICATION_NAME}") assert.Equal(t, route.Namespace, fakeNs) - assert.DeepEqual(t, route.Spec.To, + assert.Equal(t, route.Spec.To, routev1.RouteTargetReference{Name: "${APPLICATION_NAME}"}) - assert.DeepEqual(t, route.Spec.TLS, + assert.Equal(t, route.Spec.TLS, &routev1.TLSConfig{Termination: "reencrypt"}) } @@ -218,7 +218,7 @@ func TestKeycloak_testRealmConfigCreation(t *testing.T) { } _, err := createRealmConfig(cfg) - assert.NilError(t, err) + assert.NoError(t, err) } func TestKeycloak_testServerCert(t *testing.T) { @@ -238,13 +238,13 @@ func TestKeycloak_testServerCert(t *testing.T) { r.Client.Create(context.TODO(), sslCertsSecret) _, err := r.getKCServerCert(a) - assert.NilError(t, err) + assert.NoError(t, err) sslCertsSecret.Data["tls.crt"] = nil - assert.NilError(t, r.Client.Update(context.TODO(), sslCertsSecret)) + assert.NoError(t, r.Client.Update(context.TODO(), sslCertsSecret)) _, err = r.getKCServerCert(a) - assert.NilError(t, err) + assert.NoError(t, err) } func TestKeycloak_NodeLabelSelector(t *testing.T) { @@ -255,6 +255,6 @@ func TestKeycloak_NodeLabelSelector(t *testing.T) { } dc := getKeycloakDeploymentConfigTemplate(a) - assert.DeepEqual(t, dc.Spec.Template.Spec.NodeSelector, a.Spec.NodePlacement.NodeSelector) - assert.DeepEqual(t, dc.Spec.Template.Spec.Tolerations, a.Spec.NodePlacement.Tolerations) + assert.Equal(t, dc.Spec.Template.Spec.NodeSelector, a.Spec.NodePlacement.NodeSelector) + assert.Equal(t, dc.Spec.Template.Spec.Tolerations, a.Spec.NodePlacement.Tolerations) } diff --git a/controllers/argocd/role_test.go b/controllers/argocd/role_test.go index 654450ae8..2cad1dc8d 100644 --- a/controllers/argocd/role_test.go +++ b/controllers/argocd/role_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" v1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -19,56 +19,60 @@ func TestReconcileArgoCD_reconcileRole(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) - assert.NilError(t, createNamespace(r, "newNamespaceTest", a.Namespace)) + assert.NoError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, "newNamespaceTest", a.Namespace)) workloadIdentifier := "x" expectedRules := policyRuleForApplicationController() _, err := r.reconcileRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, err) + assert.NoError(t, err) expectedName := fmt.Sprintf("%s-%s", a.Name, workloadIdentifier) reconciledRole := &v1.Role{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) // check if roles are created for the new namespace as well - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "newNamespaceTest"}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "newNamespaceTest"}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) // update reconciledRole policy rules to RedisHa policy rules reconciledRole.Rules = policyRuleForRedisHa(a) - assert.NilError(t, r.Client.Update(context.TODO(), reconciledRole)) + assert.NoError(t, r.Client.Update(context.TODO(), reconciledRole)) // Check if the RedisHa policy rules are overwritten to Application Controller // policy rules by the reconciler _, err = r.reconcileRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, err) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) } func TestReconcileArgoCD_reconcileRole_dex_disabled(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) rules := policyRuleForDexServer() role := newRole(dexServer, rules, a) // Dex is enabled _, err := r.reconcileRole(dexServer, rules, a) - assert.NilError(t, err) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role)) - assert.DeepEqual(t, rules, role.Rules) + assert.NoError(t, err) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role)) + assert.Equal(t, rules, role.Rules) // Disable Dex os.Setenv("DISABLE_DEX", "true") defer os.Unsetenv("DISABLE_DEX") _, err = r.reconcileRole(dexServer, rules, a) - assert.NilError(t, err) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role), "not found") + assert.NoError(t, err) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: a.Namespace}, role).Error(), "not found") } func TestReconcileArgoCD_reconcileClusterRole(t *testing.T) { @@ -80,80 +84,88 @@ func TestReconcileArgoCD_reconcileClusterRole(t *testing.T) { clusterRoleName := GenerateUniqueResourceName(workloadIdentifier, a) expectedRules := policyRuleForApplicationController() _, err := r.reconcileClusterRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, err) + assert.NoError(t, err) // cluster role should not be created - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, &v1.ClusterRole{}), "not found") + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, &v1.ClusterRole{}), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, &v1.ClusterRole{})) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, &v1.ClusterRole{}).Error(), "not found") os.Setenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES", a.Namespace) _, err = r.reconcileClusterRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, err) + assert.NoError(t, err) reconciledClusterRole := &v1.ClusterRole{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole)) - assert.DeepEqual(t, expectedRules, reconciledClusterRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole)) + assert.Equal(t, expectedRules, reconciledClusterRole.Rules) // update reconciledRole policy rules to RedisHa policy rules reconciledClusterRole.Rules = policyRuleForRedisHa(a) - assert.NilError(t, r.Client.Update(context.TODO(), reconciledClusterRole)) + assert.NoError(t, r.Client.Update(context.TODO(), reconciledClusterRole)) // Check if the RedisHa policy rules are overwritten to Application Controller // policy rules for cluster role by the reconciler _, err = r.reconcileClusterRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole)) - assert.DeepEqual(t, expectedRules, reconciledClusterRole.Rules) + assert.NoError(t, err) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole)) + assert.Equal(t, expectedRules, reconciledClusterRole.Rules) // Check if the CLuster Role gets deleted os.Unsetenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES") _, err = r.reconcileClusterRole(workloadIdentifier, expectedRules, a) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole), "not found") + assert.NoError(t, err) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName}, reconciledClusterRole).Error(), "not found") } func TestReconcileArgoCD_RoleHooks(t *testing.T) { defer resetHooks()() a := makeTestArgoCD() r := makeTestReconciler(t) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) Register(testRoleHook) roles, err := r.reconcileRole(applicationController, []v1.PolicyRule{}, a) role := roles[0] - assert.NilError(t, err) - assert.DeepEqual(t, role.Rules, testRules()) + assert.NoError(t, err) + assert.Equal(t, role.Rules, testRules()) roles, err = r.reconcileRole("test", []v1.PolicyRule{}, a) role = roles[0] - assert.NilError(t, err) - assert.DeepEqual(t, role.Rules, []v1.PolicyRule{}) + assert.NoError(t, err) + assert.Equal(t, role.Rules, []v1.PolicyRule{}) } func TestReconcileArgoCD_reconcileRole_custom_role(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) - assert.NilError(t, createNamespace(r, "namespace-custom-role", a.Namespace)) + assert.NoError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, "namespace-custom-role", a.Namespace)) workloadIdentifier := "argocd-application-controller" expectedRules := policyRuleForApplicationController() _, err := r.reconcileRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, err) + assert.NoError(t, err) expectedName := fmt.Sprintf("%s-%s", a.Name, workloadIdentifier) reconciledRole := &v1.Role{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) // check if roles are created for the new namespace as well - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "namespace-custom-role"}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "namespace-custom-role"}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) // set the custom role as env variable - assert.NilError(t, os.Setenv(common.ArgoCDControllerClusterRoleEnvName, "custom-role")) + assert.NoError(t, os.Setenv(common.ArgoCDControllerClusterRoleEnvName, "custom-role")) defer os.Unsetenv(common.ArgoCDControllerClusterRoleEnvName) _, err = r.reconcileRole(workloadIdentifier, expectedRules, a) - assert.NilError(t, err) + assert.NoError(t, err) // check if the default cluster roles are removed err = r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole) diff --git a/controllers/argocd/rolebinding_test.go b/controllers/argocd/rolebinding_test.go index 6523054c1..ca0a93058 100644 --- a/controllers/argocd/rolebinding_test.go +++ b/controllers/argocd/rolebinding_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/argoproj-labs/argocd-operator/common" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -21,51 +21,54 @@ func TestReconcileArgoCD_reconcileRoleBinding(t *testing.T) { r := makeTestReconciler(t, a) p := policyRuleForApplicationController() - assert.NilError(t, createNamespace(r, a.Namespace, "")) - assert.NilError(t, createNamespace(r, "newTestNamespace", a.Namespace)) + assert.NoError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, "newTestNamespace", a.Namespace)) workloadIdentifier := "xrb" - assert.NilError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) + assert.NoError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) roleBinding := &rbacv1.RoleBinding{} expectedName := fmt.Sprintf("%s-%s", a.Name, workloadIdentifier) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "newTestNamespace"}, roleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: "newTestNamespace"}, roleBinding)) // update role reference and subject of the rolebinding roleBinding.RoleRef.Name = "not-xrb" roleBinding.Subjects[0].Name = "not-xrb" - assert.NilError(t, r.Client.Update(context.TODO(), roleBinding)) + assert.NoError(t, r.Client.Update(context.TODO(), roleBinding)) // try reconciling it again and verify if the changes are overwritten - assert.NilError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) + assert.NoError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) roleBinding = &rbacv1.RoleBinding{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) } func TestReconcileArgoCD_reconcileRoleBinding_dex_disabled(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) rules := policyRuleForDexServer() rb := newRoleBindingWithname(dexServer, a) // Dex is enabled, creates a role binding - assert.NilError(t, r.reconcileRoleBinding(dexServer, rules, a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb)) + assert.NoError(t, r.reconcileRoleBinding(dexServer, rules, a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb)) // Disable Dex, deletes the existing role binding os.Setenv("DISABLE_DEX", "true") defer os.Unsetenv("DISABLE_DEX") _, err := r.reconcileRole(dexServer, rules, a) - assert.NilError(t, err) - assert.NilError(t, r.reconcileRoleBinding(dexServer, rules, a)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb), "not found") + assert.NoError(t, err) + assert.NoError(t, r.reconcileRoleBinding(dexServer, rules, a)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: rb.Name, Namespace: a.Namespace}, rb).Error(), "not found") } func TestReconcileArgoCD_reconcileClusterRoleBinding(t *testing.T) { @@ -77,22 +80,22 @@ func TestReconcileArgoCD_reconcileClusterRoleBinding(t *testing.T) { expectedClusterRole := &rbacv1.ClusterRole{ObjectMeta: metav1.ObjectMeta{Name: workloadIdentifier}} expectedServiceAccount := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: workloadIdentifier, Namespace: a.Namespace}} - assert.NilError(t, r.reconcileClusterRoleBinding(workloadIdentifier, expectedClusterRole, expectedServiceAccount, a)) + assert.NoError(t, r.reconcileClusterRoleBinding(workloadIdentifier, expectedClusterRole, expectedServiceAccount, a)) clusterRoleBinding := &rbacv1.ClusterRoleBinding{} expectedName := fmt.Sprintf("%s-%s-%s", a.Name, a.Namespace, workloadIdentifier) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName}, clusterRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName}, clusterRoleBinding)) // update role reference and subject of the clusterrolebinding clusterRoleBinding.RoleRef.Name = "not-x" clusterRoleBinding.Subjects[0].Name = "not-x" - assert.NilError(t, r.Client.Update(context.TODO(), clusterRoleBinding)) + assert.NoError(t, r.Client.Update(context.TODO(), clusterRoleBinding)) // try reconciling it again and verify if the changes are overwritten - assert.NilError(t, r.reconcileClusterRoleBinding(workloadIdentifier, expectedClusterRole, expectedServiceAccount, a)) + assert.NoError(t, r.reconcileClusterRoleBinding(workloadIdentifier, expectedClusterRole, expectedServiceAccount, a)) clusterRoleBinding = &rbacv1.ClusterRoleBinding{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName}, clusterRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName}, clusterRoleBinding)) } func TestReconcileArgoCD_reconcileRoleBinding_custom_role(t *testing.T) { @@ -101,19 +104,19 @@ func TestReconcileArgoCD_reconcileRoleBinding_custom_role(t *testing.T) { r := makeTestReconciler(t, a) p := policyRuleForApplicationController() - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) workloadIdentifier := "argocd-application-controller" expectedName := fmt.Sprintf("%s-%s", a.Name, workloadIdentifier) namespaceWithCustomRole := "namespace-with-custom-role" - assert.NilError(t, createNamespace(r, namespaceWithCustomRole, a.Namespace)) - assert.NilError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) + assert.NoError(t, createNamespace(r, namespaceWithCustomRole, a.Namespace)) + assert.NoError(t, r.reconcileRoleBinding(workloadIdentifier, p, a)) // check if the default rolebindings are created - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, &rbacv1.RoleBinding{})) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, &rbacv1.RoleBinding{})) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: namespaceWithCustomRole}, &rbacv1.RoleBinding{})) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: namespaceWithCustomRole}, &rbacv1.RoleBinding{})) checkForUpdatedRoleRef := func(t *testing.T, roleName, expectedName string) { t.Helper() @@ -123,23 +126,23 @@ func TestReconcileArgoCD_reconcileRoleBinding_custom_role(t *testing.T) { Name: roleName, } roleBinding := &rbacv1.RoleBinding{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) - assert.DeepEqual(t, roleBinding.RoleRef, expectedRoleRef) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, roleBinding)) + assert.Equal(t, roleBinding.RoleRef, expectedRoleRef) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: namespaceWithCustomRole}, roleBinding)) - assert.DeepEqual(t, roleBinding.RoleRef, expectedRoleRef) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: namespaceWithCustomRole}, roleBinding)) + assert.Equal(t, roleBinding.RoleRef, expectedRoleRef) } - assert.NilError(t, os.Setenv(common.ArgoCDControllerClusterRoleEnvName, "custom-controller-role")) + assert.NoError(t, os.Setenv(common.ArgoCDControllerClusterRoleEnvName, "custom-controller-role")) defer os.Unsetenv(common.ArgoCDControllerClusterRoleEnvName) - assert.NilError(t, r.reconcileRoleBinding(applicationController, p, a)) + assert.NoError(t, r.reconcileRoleBinding(applicationController, p, a)) expectedName = fmt.Sprintf("%s-%s", a.Name, "argocd-application-controller") checkForUpdatedRoleRef(t, "custom-controller-role", expectedName) - assert.NilError(t, os.Setenv(common.ArgoCDServerClusterRoleEnvName, "custom-server-role")) + assert.NoError(t, os.Setenv(common.ArgoCDServerClusterRoleEnvName, "custom-server-role")) defer os.Unsetenv(common.ArgoCDServerClusterRoleEnvName) - assert.NilError(t, r.reconcileRoleBinding("argocd-server", p, a)) + assert.NoError(t, r.reconcileRoleBinding("argocd-server", p, a)) expectedName = fmt.Sprintf("%s-%s", a.Name, "argocd-server") checkForUpdatedRoleRef(t, "custom-server-role", expectedName) diff --git a/controllers/argocd/route_test.go b/controllers/argocd/route_test.go index f7babfb89..0f1e8e555 100644 --- a/controllers/argocd/route_test.go +++ b/controllers/argocd/route_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -36,7 +36,7 @@ func TestReconcileRouteSetLabels(t *testing.T) { argoCD, } r := makeReconciler(t, argoCD, objs...) - assert.NilError(t, createNamespace(r, argoCD.Namespace, "")) + assert.NoError(t, createNamespace(r, argoCD.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -46,7 +46,7 @@ func TestReconcileRouteSetLabels(t *testing.T) { } _, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) loaded := &routev1.Route{} err = r.Client.Get(ctx, types.NamespacedName{Name: testArgoCDName + "-server", Namespace: testNamespace}, loaded) @@ -68,7 +68,7 @@ func TestReconcileRouteSetsInsecure(t *testing.T) { argoCD, } r := makeReconciler(t, argoCD, objs...) - assert.NilError(t, createNamespace(r, argoCD.Namespace, "")) + assert.NoError(t, createNamespace(r, argoCD.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -78,7 +78,7 @@ func TestReconcileRouteSetsInsecure(t *testing.T) { } _, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) loaded := &routev1.Route{} err = r.Client.Get(ctx, types.NamespacedName{Name: testArgoCDName + "-server", Namespace: testNamespace}, loaded) @@ -140,7 +140,7 @@ func TestReconcileRouteUnsetsInsecure(t *testing.T) { argoCD, } r := makeReconciler(t, argoCD, objs...) - assert.NilError(t, createNamespace(r, argoCD.Namespace, "")) + assert.NoError(t, createNamespace(r, argoCD.Namespace, "")) req := reconcile.Request{ NamespacedName: types.NamespacedName{ @@ -150,7 +150,7 @@ func TestReconcileRouteUnsetsInsecure(t *testing.T) { } _, err := r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) loaded := &routev1.Route{} err = r.Client.Get(ctx, types.NamespacedName{Name: testArgoCDName + "-server", Namespace: testNamespace}, loaded) @@ -179,7 +179,7 @@ func TestReconcileRouteUnsetsInsecure(t *testing.T) { fatalIfError(t, err, "failed to update the ArgoCD: %s", err) _, err = r.Reconcile(context.TODO(), req) - assert.NilError(t, err) + assert.NoError(t, err) loaded = &routev1.Route{} err = r.Client.Get(ctx, types.NamespacedName{Name: testArgoCDName + "-server", Namespace: testNamespace}, loaded) diff --git a/controllers/argocd/secret_test.go b/controllers/argocd/secret_test.go index 5121b91dc..4faa492e6 100644 --- a/controllers/argocd/secret_test.go +++ b/controllers/argocd/secret_test.go @@ -9,7 +9,7 @@ import ( "sort" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" @@ -212,34 +212,40 @@ func Test_ReconcileArgoCD_ClusterPermissionsSecret(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) testSecret := argoutil.NewSecretWithSuffix(a, "default-cluster-config") - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret), "not found") + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret).Error(), "not found") - assert.NilError(t, r.reconcileClusterPermissionsSecret(a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) - assert.DeepEqual(t, string(testSecret.Data["namespaces"]), a.Namespace) + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Equal(t, string(testSecret.Data["namespaces"]), a.Namespace) want := "argocd,someRandomNamespace" testSecret.Data["namespaces"] = []byte("someRandomNamespace") r.Client.Update(context.TODO(), testSecret) // reconcile to check namespace with the label gets added - assert.NilError(t, r.reconcileClusterPermissionsSecret(a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) - assert.DeepEqual(t, string(testSecret.Data["namespaces"]), want) + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Equal(t, string(testSecret.Data["namespaces"]), want) - assert.NilError(t, createNamespace(r, "xyz", a.Namespace)) + assert.NoError(t, createNamespace(r, "xyz", a.Namespace)) want = "argocd,someRandomNamespace,xyz" // reconcile to check namespace with the label gets added - assert.NilError(t, r.reconcileClusterPermissionsSecret(a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) - assert.DeepEqual(t, string(testSecret.Data["namespaces"]), want) + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Equal(t, string(testSecret.Data["namespaces"]), want) os.Setenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES", a.Namespace) defer os.Unsetenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES") - assert.NilError(t, r.reconcileClusterPermissionsSecret(a)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret), "not found") + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret).Error(), "not found") } diff --git a/controllers/argocd/service_account_test.go b/controllers/argocd/service_account_test.go index 2714c5053..13591430c 100644 --- a/controllers/argocd/service_account_test.go +++ b/controllers/argocd/service_account_test.go @@ -20,7 +20,7 @@ import ( "os" "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/types" @@ -31,40 +31,40 @@ func TestReconcileArgoCD_reconcileServiceAccountPermissions(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) // objective is to verify if the right rule associations have happened. expectedRules := policyRuleForApplicationController() workloadIdentifier := "xrb" - assert.NilError(t, r.reconcileServiceAccountPermissions(workloadIdentifier, expectedRules, a)) + assert.NoError(t, r.reconcileServiceAccountPermissions(workloadIdentifier, expectedRules, a)) reconciledServiceAccount := &corev1.ServiceAccount{} reconciledRole := &v1.Role{} reconcileRoleBinding := &v1.RoleBinding{} expectedName := fmt.Sprintf("%s-%s", a.Name, workloadIdentifier) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconcileRoleBinding)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledServiceAccount)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconcileRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledServiceAccount)) + assert.Equal(t, expectedRules, reconciledRole.Rules) // undesirable changes reconciledRole.Rules = policyRuleForRedisHa(a) - assert.NilError(t, r.Client.Update(context.TODO(), reconciledRole)) + assert.NoError(t, r.Client.Update(context.TODO(), reconciledRole)) // fetch it dirtyRole := &v1.Role{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, dirtyRole)) - assert.DeepEqual(t, reconciledRole.Rules, dirtyRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, dirtyRole)) + assert.Equal(t, reconciledRole.Rules, dirtyRole.Rules) // Have the reconciler override them - assert.NilError(t, r.reconcileServiceAccountPermissions(workloadIdentifier, expectedRules, a)) + assert.NoError(t, r.reconcileServiceAccountPermissions(workloadIdentifier, expectedRules, a)) // fetch it - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) - assert.DeepEqual(t, expectedRules, reconciledRole.Rules) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedName, Namespace: a.Namespace}, reconciledRole)) + assert.Equal(t, expectedRules, reconciledRole.Rules) } func TestReconcileArgoCD_reconcileServiceAccountClusterPermissions(t *testing.T) { @@ -82,64 +82,79 @@ func TestReconcileArgoCD_reconcileServiceAccountClusterPermissions(t *testing.T) reconcileClusterRole := &v1.ClusterRole{} //reconcile ServiceAccountClusterPermissions with no policy rules - assert.NilError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) + assert.NoError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) //Service account should be created but no ClusterRole/ClusterRoleBinding should be created - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedNameSA, Namespace: a.Namespace}, reconcileServiceAccount)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding), "not found") - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole), "not found") + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedNameSA, Namespace: a.Namespace}, reconcileServiceAccount)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding).Error(), "not found") + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole).Error(), "not found") os.Setenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES", a.Namespace) // objective is to verify if the right SA associations have happened. - assert.NilError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) + assert.NoError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedNameSA, Namespace: a.Namespace}, reconcileServiceAccount)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedNameSA, Namespace: a.Namespace}, reconcileServiceAccount)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) // undesirable changes reconcileClusterRoleBinding.RoleRef.Name = "z" reconcileClusterRoleBinding.Subjects[0].Name = "z" - assert.NilError(t, r.Client.Update(context.TODO(), reconcileClusterRoleBinding)) + assert.NoError(t, r.Client.Update(context.TODO(), reconcileClusterRoleBinding)) // fetch it dirtyClusterRoleBinding := &v1.ClusterRoleBinding{} - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, dirtyClusterRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, dirtyClusterRoleBinding)) assert.Equal(t, reconcileClusterRoleBinding.RoleRef.Name, dirtyClusterRoleBinding.RoleRef.Name) // Have the reconciler override them - assert.NilError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) + assert.NoError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) // fetch it - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) assert.Equal(t, expectedClusterRoleName, reconcileClusterRoleBinding.RoleRef.Name) // Check if cluster role and rolebinding gets deleted os.Unsetenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES") - assert.NilError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding), "not found") - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole), "not found") + assert.NoError(t, r.reconcileServiceAccountClusterPermissions(workloadIdentifier, testRules(), a)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleBindingName}, reconcileClusterRoleBinding).Error(), "not found") + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: expectedClusterRoleName}, reconcileClusterRole).Error(), "not found") } func TestReconcileArgoCD_reconcileServiceAccount_dex_disabled(t *testing.T) { logf.SetLogger(ZapLogger(true)) a := makeTestArgoCD() r := makeTestReconciler(t, a) - assert.NilError(t, createNamespace(r, a.Namespace, "")) + assert.NoError(t, createNamespace(r, a.Namespace, "")) // Dex is enabled, creates a new Service Account for it sa, err := r.reconcileServiceAccount(dexServer, a) - assert.NilError(t, err) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa)) + assert.NoError(t, err) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa)) //Disable dex, deletes any existing Service Account for it os.Setenv("DISABLE_DEX", "true") defer os.Unsetenv("DISABLE_DEX") sa, err = r.reconcileServiceAccount(dexServer, a) - assert.NilError(t, err) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa), "not found") + assert.NoError(t, err) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: sa.Name, Namespace: a.Namespace}, sa).Error(), "not found") } func testRules() []v1.PolicyRule { diff --git a/controllers/argocd/service_test.go b/controllers/argocd/service_test.go index 32d11d5a7..45e90f28a 100644 --- a/controllers/argocd/service_test.go +++ b/controllers/argocd/service_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/argoproj-labs/argocd-operator/common" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/types" logf "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -18,8 +18,8 @@ func TestReconcileArgoCD_reconcileDexService_Dex_Enabled(t *testing.T) { s := newServiceWithSuffix("dex-server", "dex-server", a) - assert.NilError(t, r.reconcileDexService(a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) + assert.NoError(t, r.reconcileDexService(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) } func TestReconcileArgoCD_reconcileDexService_Dex_Disabled(t *testing.T) { @@ -30,8 +30,8 @@ func TestReconcileArgoCD_reconcileDexService_Dex_Disabled(t *testing.T) { s := newServiceWithSuffix("dex-server", "dex-server", a) // Create Service for Dex - assert.NilError(t, r.reconcileDexService(a)) - assert.NilError(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) + assert.NoError(t, r.reconcileDexService(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) // Disable Dex, existing service should be deleted os.Setenv("DISABLE_DEX", "true") @@ -39,12 +39,18 @@ func TestReconcileArgoCD_reconcileDexService_Dex_Disabled(t *testing.T) { os.Unsetenv("DISABLE_DEX") }) - assert.NilError(t, r.reconcileDexService(a)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s), "not found") + assert.NoError(t, r.reconcileDexService(a)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s).Error(), "not found") // Service for Dex should not be created on reconciliation when disabled - assert.NilError(t, r.reconcileDexService(a)) - assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s), "not found") + assert.NoError(t, r.reconcileDexService(a)) + //assert.ErrorContains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s), "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s)) + assert.Contains(t, r.Client.Get(context.TODO(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s).Error(), "not found") } func TestEnsureAutoTLSAnnotation(t *testing.T) { diff --git a/controllers/argocd/sso_test.go b/controllers/argocd/sso_test.go index 53d007921..98934bb0e 100644 --- a/controllers/argocd/sso_test.go +++ b/controllers/argocd/sso_test.go @@ -22,7 +22,7 @@ import ( oappsv1 "github.com/openshift/api/apps/v1" routev1 "github.com/openshift/api/route/v1" templatev1 "github.com/openshift/api/template/v1" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" k8sappsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" @@ -40,7 +40,7 @@ func makeFakeReconciler(t *testing.T, acd *argov1alpha1.ArgoCD, objs ...runtime. // Register template scheme s.AddKnownTypes(templatev1.SchemeGroupVersion, objs...) s.AddKnownTypes(oappsv1.SchemeGroupVersion, objs...) - assert.NilError(t, argov1alpha1.AddToScheme(s)) + assert.NoError(t, argov1alpha1.AddToScheme(s)) templatev1.Install(s) oappsv1.Install(s) routev1.Install(s) @@ -59,10 +59,10 @@ func TestReconcile_testKeycloakTemplateInstance(t *testing.T) { templateAPIFound = true r := makeFakeReconciler(t, a) - assert.NilError(t, r.reconcileSSO(a)) + assert.NoError(t, r.reconcileSSO(a)) templateInstance := &templatev1.TemplateInstance{} - assert.NilError(t, r.Client.Get( + assert.NoError(t, r.Client.Get( context.TODO(), types.NamespacedName{ Name: "rhsso", @@ -82,7 +82,7 @@ func TestReconcile_noTemplateInstance(t *testing.T) { a := makeTestArgoCDForKeycloak() r := makeFakeReconciler(t, a) - assert.NilError(t, r.reconcileSSO(a)) + assert.NoError(t, r.reconcileSSO(a)) } func TestReconcile_testKeycloakK8sInstance(t *testing.T) { @@ -93,7 +93,7 @@ func TestReconcile_testKeycloakK8sInstance(t *testing.T) { templateAPIFound = false r := makeReconciler(t, a) - assert.NilError(t, r.reconcileSSO(a)) + assert.NoError(t, r.reconcileSSO(a)) } func TestReconcile_testKeycloakInstanceResources(t *testing.T) { @@ -104,12 +104,12 @@ func TestReconcile_testKeycloakInstanceResources(t *testing.T) { templateAPIFound = false r := makeReconciler(t, a) - assert.NilError(t, r.reconcileSSO(a)) + assert.NoError(t, r.reconcileSSO(a)) // Keycloak Deployment deployment := &k8sappsv1.Deployment{} err := r.Client.Get(context.TODO(), types.NamespacedName{Name: defaultKeycloakIdentifier, Namespace: a.Namespace}, deployment) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, deployment.Name, defaultKeycloakIdentifier) assert.Equal(t, deployment.Namespace, a.Namespace) @@ -117,16 +117,16 @@ func TestReconcile_testKeycloakInstanceResources(t *testing.T) { testLabels := map[string]string{ "app": defaultKeycloakIdentifier, } - assert.DeepEqual(t, deployment.Labels, testLabels) + assert.Equal(t, deployment.Labels, testLabels) testSelector := &v1.LabelSelector{ MatchLabels: map[string]string{ "app": defaultKeycloakIdentifier, }, } - assert.DeepEqual(t, deployment.Spec.Selector, testSelector) + assert.Equal(t, deployment.Spec.Selector, testSelector) - assert.DeepEqual(t, deployment.Spec.Template.ObjectMeta.Labels, testLabels) + assert.Equal(t, deployment.Spec.Template.ObjectMeta.Labels, testLabels) assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Name, defaultKeycloakIdentifier) assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Image, @@ -137,26 +137,26 @@ func TestReconcile_testKeycloakInstanceResources(t *testing.T) { {Name: "KEYCLOAK_PASSWORD", Value: defaultKeycloakAdminPassword}, {Name: "PROXY_ADDRESS_FORWARDING", Value: "true"}, } - assert.DeepEqual(t, deployment.Spec.Template.Spec.Containers[0].Env, + assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Env, testEnv) // Keycloak Service svc := &corev1.Service{} err = r.Client.Get(context.TODO(), types.NamespacedName{Name: defaultKeycloakIdentifier, Namespace: a.Namespace}, svc) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, svc.Name, defaultKeycloakIdentifier) assert.Equal(t, svc.Namespace, a.Namespace) - assert.DeepEqual(t, svc.Labels, testLabels) + assert.Equal(t, svc.Labels, testLabels) - assert.DeepEqual(t, svc.Spec.Selector, testLabels) - assert.DeepEqual(t, svc.Spec.Type, corev1.ServiceType("LoadBalancer")) + assert.Equal(t, svc.Spec.Selector, testLabels) + assert.Equal(t, svc.Spec.Type, corev1.ServiceType("LoadBalancer")) // Keycloak Ingress ing := &networkingv1.Ingress{} testPathType := networkingv1.PathTypeImplementationSpecific err = r.Client.Get(context.TODO(), types.NamespacedName{Name: defaultKeycloakIdentifier, Namespace: a.Namespace}, ing) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, ing.Name, defaultKeycloakIdentifier) assert.Equal(t, ing.Namespace, a.Namespace) @@ -166,7 +166,7 @@ func TestReconcile_testKeycloakInstanceResources(t *testing.T) { Hosts: []string{keycloakIngressHost}, }, } - assert.DeepEqual(t, ing.Spec.TLS, testTLS) + assert.Equal(t, ing.Spec.TLS, testTLS) testRules := []networkingv1.IngressRule{ { @@ -192,5 +192,5 @@ func TestReconcile_testKeycloakInstanceResources(t *testing.T) { }, } - assert.DeepEqual(t, ing.Spec.Rules, testRules) + assert.Equal(t, ing.Spec.Rules, testRules) } diff --git a/controllers/argocd/status_test.go b/controllers/argocd/status_test.go index 973a17a8d..60e0cd16e 100644 --- a/controllers/argocd/status_test.go +++ b/controllers/argocd/status_test.go @@ -3,7 +3,7 @@ package argocd import ( "testing" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" logf "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -13,7 +13,7 @@ func TestReconcileArgoCD_reconcileStatusSSOConfig_multi_sso_configured(t *testin templateAPIFound = true r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileStatusSSOConfig(a)) + assert.NoError(t, r.reconcileStatusSSOConfig(a)) assert.Equal(t, a.Status.SSOConfig, "Failed") } func TestReconcileArgoCD_reconcileStatusSSOConfig_only_keycloak_configured(t *testing.T) { @@ -22,7 +22,7 @@ func TestReconcileArgoCD_reconcileStatusSSOConfig_only_keycloak_configured(t *te templateAPIFound = true r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileStatusSSOConfig(a)) + assert.NoError(t, r.reconcileStatusSSOConfig(a)) assert.Equal(t, a.Status.SSOConfig, "Success") } func TestReconcileArgoCD_reconcileStatusSSOConfig_only_dex_configured(t *testing.T) { @@ -31,7 +31,7 @@ func TestReconcileArgoCD_reconcileStatusSSOConfig_only_dex_configured(t *testing templateAPIFound = true r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileStatusSSOConfig(a)) + assert.NoError(t, r.reconcileStatusSSOConfig(a)) assert.Equal(t, a.Status.SSOConfig, "Success") } func TestReconcileArgoCD_reconcileStatusSSOConfig_no_sso_configured(t *testing.T) { @@ -40,6 +40,6 @@ func TestReconcileArgoCD_reconcileStatusSSOConfig_no_sso_configured(t *testing.T templateAPIFound = true r := makeTestReconciler(t, a) - assert.NilError(t, r.reconcileStatusSSOConfig(a)) + assert.NoError(t, r.reconcileStatusSSOConfig(a)) assert.Equal(t, a.Status.SSOConfig, "Unknown") } diff --git a/controllers/argocd/testing.go b/controllers/argocd/testing.go index 725bd9a76..07744d55c 100644 --- a/controllers/argocd/testing.go +++ b/controllers/argocd/testing.go @@ -23,7 +23,7 @@ import ( "github.com/argoproj-labs/argocd-operator/common" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/rbac/v1" @@ -51,7 +51,7 @@ func ZapLogger(development bool) logr.Logger { func makeTestReconciler(t *testing.T, objs ...runtime.Object) *ReconcileArgoCD { s := scheme.Scheme - assert.NilError(t, argoprojv1alpha1.AddToScheme(s)) + assert.NoError(t, argoprojv1alpha1.AddToScheme(s)) cl := fake.NewFakeClientWithScheme(s, objs...) return &ReconcileArgoCD{ @@ -216,9 +216,9 @@ func initialCerts(t *testing.T, host string) argoCDOpt { t.Helper() return func(a *argoprojv1alpha1.ArgoCD) { key, err := argoutil.NewPrivateKey() - assert.NilError(t, err) + assert.NoError(t, err) cert, err := argoutil.NewSelfSignedCACertificate(key) - assert.NilError(t, err) + assert.NoError(t, err) encoded := argoutil.EncodeCertificatePEM(cert) a.Spec.TLS.InitialCerts = map[string]string{ diff --git a/controllers/argocd/util_test.go b/controllers/argocd/util_test.go index 40a44736a..c17dea7b4 100644 --- a/controllers/argocd/util_test.go +++ b/controllers/argocd/util_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" argoprojv1alpha1 "github.com/argoproj-labs/argocd-operator/api/v1alpha1" "github.com/argoproj-labs/argocd-operator/common" @@ -259,7 +259,7 @@ func TestRemoveDeletionFinalizer(t *testing.T) { a := makeTestArgoCD(addFinalizer(common.ArgoCDDeletionFinalizer)) r := makeTestReconciler(t, a) err := r.removeDeletionFinalizer(a) - assert.NilError(t, err) + assert.NoError(t, err) if a.IsDeletionFinalizerPresent() { t.Fatal("Expected deletion finalizer to be removed") } @@ -277,7 +277,7 @@ func TestAddDeletionFinalizer(t *testing.T) { a := makeTestArgoCD() r := makeTestReconciler(t, a) err := r.addDeletionFinalizer(a) - assert.NilError(t, err) + assert.NoError(t, err) if !a.IsDeletionFinalizerPresent() { t.Fatal("Expected deletion finalizer to be added") } @@ -294,13 +294,17 @@ func TestArgoCDInstanceSelector(t *testing.T) { t.Run("Selector for a Valid name", func(t *testing.T) { validName := "argocd-server" selector, err := argocdInstanceSelector(validName) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, selector.String(), "app.kubernetes.io/managed-by=argocd-server") }) t.Run("Selector for an Invalid name", func(t *testing.T) { invalidName := "argocd-*/" selector, err := argocdInstanceSelector(invalidName) - assert.ErrorContains(t, err, `failed to create a requirement for values[0][app.kubernetes.io/managed-by]: Invalid value: "argocd-*/`) + //assert.ErrorContains(t, err, `failed to create a requirement for values[0][app.kubernetes.io/managed-by]: Invalid value: "argocd-*/`) + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, err) + assert.Contains(t, err.Error(), `failed to create a requirement for values[0][app.kubernetes.io/managed-by]: Invalid value: "argocd-*/`) + assert.Equal(t, selector, nil) }) } @@ -440,7 +444,7 @@ func TestDeleteRBACsForNamespace(t *testing.T) { // create role with label _, err := testClient.RbacV1().Roles(testNameSpace).Create(context.TODO(), role, metav1.CreateOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) role2 := newRole("abc", policyRuleForApplicationController(), a) role2.Namespace = testNameSpace @@ -448,14 +452,14 @@ func TestDeleteRBACsForNamespace(t *testing.T) { // create role without label _, err = testClient.RbacV1().Roles(testNameSpace).Create(context.TODO(), role2, metav1.CreateOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) roleBinding := newRoleBindingWithname("xyz", a) roleBinding.Namespace = testNameSpace // create roleBinding with label _, err = testClient.RbacV1().RoleBindings(testNameSpace).Create(context.TODO(), roleBinding, metav1.CreateOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) roleBinding2 := newRoleBindingWithname("abc", a) roleBinding2.Namespace = testNameSpace @@ -463,24 +467,32 @@ func TestDeleteRBACsForNamespace(t *testing.T) { // create RoleBinding without label _, err = testClient.RbacV1().RoleBindings(testNameSpace).Create(context.TODO(), roleBinding2, metav1.CreateOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) // run deleteRBACsForNamespace - assert.NilError(t, deleteRBACsForNamespace(a.Namespace, testNameSpace, testClient)) + assert.NoError(t, deleteRBACsForNamespace(a.Namespace, testNameSpace, testClient)) // role with the label should be deleted _, err = testClient.RbacV1().Roles(testNameSpace).Get(context.TODO(), role.Name, metav1.GetOptions{}) - assert.ErrorContains(t, err, "not found") + //assert.ErrorContains(t, err, "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, err) + assert.Contains(t, err.Error(), "not found") + // role without the label should still exists, no error _, err = testClient.RbacV1().Roles(testNameSpace).Get(context.TODO(), role2.Name, metav1.GetOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) // roleBinding with the label should be deleted _, err = testClient.RbacV1().Roles(testNameSpace).Get(context.TODO(), roleBinding.Name, metav1.GetOptions{}) - assert.ErrorContains(t, err, "not found") + //assert.ErrorContains(t, err, "not found") + //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available + assert.Error(t, err) + assert.Contains(t, err.Error(), "not found") + // roleBinding without the label should still exists, no error _, err = testClient.RbacV1().Roles(testNameSpace).Get(context.TODO(), roleBinding2.Name, metav1.GetOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) } @@ -498,15 +510,15 @@ func TestRemoveManagedNamespaceFromClusterSecretAfterDeletion(t *testing.T) { // create secret with the label _, err := testClient.CoreV1().Secrets(a.Namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) - assert.NilError(t, err) + assert.NoError(t, err) // run deleteManagedNamespaceFromClusterSecret - assert.NilError(t, deleteManagedNamespaceFromClusterSecret(a.Namespace, testNameSpace, testClient)) + assert.NoError(t, deleteManagedNamespaceFromClusterSecret(a.Namespace, testNameSpace, testClient)) // secret should still exists with updated list of namespaces s, err := testClient.CoreV1().Secrets(a.Namespace).Get(context.TODO(), secret.Name, metav1.GetOptions{}) - assert.NilError(t, err) - assert.DeepEqual(t, string(s.Data["namespaces"]), "testNamespace2") + assert.NoError(t, err) + assert.Equal(t, string(s.Data["namespaces"]), "testNamespace2") } @@ -517,7 +529,7 @@ func TestRemoveManagedByLabelFromNamespaces(t *testing.T) { Name: a.Namespace, }} err := r.Client.Create(context.TODO(), nsArgocd) - assert.NilError(t, err) + assert.NoError(t, err) ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{ Name: "testNamespace", @@ -527,7 +539,7 @@ func TestRemoveManagedByLabelFromNamespaces(t *testing.T) { } err = r.Client.Create(context.TODO(), ns) - assert.NilError(t, err) + assert.NoError(t, err) ns2 := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{ Name: "testNamespace2", @@ -537,7 +549,7 @@ func TestRemoveManagedByLabelFromNamespaces(t *testing.T) { } err = r.Client.Create(context.TODO(), ns2) - assert.NilError(t, err) + assert.NoError(t, err) ns3 := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{ Name: "testNamespace3", @@ -547,14 +559,14 @@ func TestRemoveManagedByLabelFromNamespaces(t *testing.T) { } err = r.Client.Create(context.TODO(), ns3) - assert.NilError(t, err) + assert.NoError(t, err) err = r.removeManagedByLabelFromNamespaces(a.Namespace) - assert.NilError(t, err) + assert.NoError(t, err) nsList := &v1.NamespaceList{} err = r.Client.List(context.TODO(), nsList) - assert.NilError(t, err) + assert.NoError(t, err) for _, n := range nsList.Items { if n.Name == ns3.Name { _, ok := n.Labels[common.ArgoCDManagedByLabel] @@ -604,7 +616,7 @@ func TestSetManagedNamespaces(t *testing.T) { r := makeTestReconciler(t, nsList) err := r.setManagedNamespaces(a) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, len(r.ManagedNamespaces.Items), 3) for _, n := range r.ManagedNamespaces.Items { diff --git a/controllers/openshift/openshift_test.go b/controllers/openshift/openshift_test.go index 5387e5855..9bc893b9d 100644 --- a/controllers/openshift/openshift_test.go +++ b/controllers/openshift/openshift_test.go @@ -7,7 +7,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "gotest.tools/assert" + "github.com/stretchr/testify/assert" ) func TestReconcileArgoCD_reconcileApplicableClusterRole(t *testing.T) { @@ -22,10 +22,10 @@ func TestReconcileArgoCD_reconcileApplicableClusterRole(t *testing.T) { }, Rules: makeTestPolicyRules(), } - assert.NilError(t, reconcilerHook(a, testClusterRole, "")) + assert.NoError(t, reconcilerHook(a, testClusterRole, "")) want := policyRulesForClusterConfig() - assert.DeepEqual(t, want, testClusterRole.Rules) + assert.Equal(t, want, testClusterRole.Rules) } func TestReconcileArgoCD_reconcileNotApplicableClusterRole(t *testing.T) { @@ -36,8 +36,8 @@ func TestReconcileArgoCD_reconcileNotApplicableClusterRole(t *testing.T) { a := makeTestArgoCDForClusterConfig() testClusterRole := makeTestClusterRole() - assert.NilError(t, reconcilerHook(a, testClusterRole, "")) - assert.DeepEqual(t, makeTestPolicyRules(), testClusterRole.Rules) + assert.NoError(t, reconcilerHook(a, testClusterRole, "")) + assert.Equal(t, makeTestPolicyRules(), testClusterRole.Rules) } func TestReconcileArgoCD_reconcileMultipleClusterRoles(t *testing.T) { @@ -56,12 +56,12 @@ func TestReconcileArgoCD_reconcileMultipleClusterRoles(t *testing.T) { testNotApplicableClusterRole := makeTestClusterRole() - assert.NilError(t, reconcilerHook(a, testApplicableClusterRole, "")) + assert.NoError(t, reconcilerHook(a, testApplicableClusterRole, "")) want := policyRulesForClusterConfig() - assert.DeepEqual(t, want, testApplicableClusterRole.Rules) + assert.Equal(t, want, testApplicableClusterRole.Rules) - assert.NilError(t, reconcilerHook(a, testNotApplicableClusterRole, "")) - assert.DeepEqual(t, makeTestPolicyRules(), testNotApplicableClusterRole.Rules) + assert.NoError(t, reconcilerHook(a, testNotApplicableClusterRole, "")) + assert.Equal(t, makeTestPolicyRules(), testNotApplicableClusterRole.Rules) } func TestReconcileArgoCD_testDeployment(t *testing.T) { @@ -72,7 +72,7 @@ func TestReconcileArgoCD_testDeployment(t *testing.T) { a := makeTestArgoCDForClusterConfig() testDeployment := makeTestDeployment() // reconcilerHook should not error on a Deployment resource - assert.NilError(t, reconcilerHook(a, testDeployment, "")) + assert.NoError(t, reconcilerHook(a, testDeployment, "")) } func TestReconcileArgoCD_notInClusterConfigNamespaces(t *testing.T) { @@ -87,26 +87,26 @@ func TestReconcileArgoCD_notInClusterConfigNamespaces(t *testing.T) { }, Rules: makeTestPolicyRules(), } - assert.NilError(t, reconcilerHook(a, testClusterRole, "")) + assert.NoError(t, reconcilerHook(a, testClusterRole, "")) want := makeTestPolicyRules() - assert.DeepEqual(t, want, testClusterRole.Rules) + assert.Equal(t, want, testClusterRole.Rules) } func TestAllowedNamespaces(t *testing.T) { argocdNamespace := testNamespace clusterConfigNamespaces := "foo,bar,argocd" - assert.DeepEqual(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) + assert.Equal(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) clusterConfigNamespaces = "foo, bar, argocd" - assert.DeepEqual(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) + assert.Equal(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) clusterConfigNamespaces = "*" - assert.DeepEqual(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) + assert.Equal(t, true, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) clusterConfigNamespaces = "foo,bar" - assert.DeepEqual(t, false, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) + assert.Equal(t, false, allowedNamespace(argocdNamespace, clusterConfigNamespaces)) } func TestReconcileArgoCD_reconcileRedisDeployment(t *testing.T) { @@ -116,14 +116,14 @@ func TestReconcileArgoCD_reconcileRedisDeployment(t *testing.T) { testDeployment.ObjectMeta.Name = a.Name + "-" + "redis" want := append(getArgsForRedhatRedis(), testDeployment.Spec.Template.Spec.Containers[0].Args...) - assert.NilError(t, reconcilerHook(a, testDeployment, "")) - assert.DeepEqual(t, testDeployment.Spec.Template.Spec.Containers[0].Args, want) + assert.NoError(t, reconcilerHook(a, testDeployment, "")) + assert.Equal(t, testDeployment.Spec.Template.Spec.Containers[0].Args, want) testDeployment.ObjectMeta.Name = a.Name + "-" + "not-redis" want = testDeployment.Spec.Template.Spec.Containers[0].Args - assert.NilError(t, reconcilerHook(a, testDeployment, "")) - assert.DeepEqual(t, testDeployment.Spec.Template.Spec.Containers[0].Args, want) + assert.NoError(t, reconcilerHook(a, testDeployment, "")) + assert.Equal(t, testDeployment.Spec.Template.Spec.Containers[0].Args, want) } func TestReconcileArgoCD_reconcileRedisHaProxyDeployment(t *testing.T) { @@ -133,35 +133,35 @@ func TestReconcileArgoCD_reconcileRedisHaProxyDeployment(t *testing.T) { testDeployment.ObjectMeta.Name = a.Name + "-redis-ha-haproxy" want := append(getCommandForRedhatRedisHaProxy(), testDeployment.Spec.Template.Spec.Containers[0].Command...) - assert.NilError(t, reconcilerHook(a, testDeployment, "")) - assert.DeepEqual(t, testDeployment.Spec.Template.Spec.Containers[0].Command, want) + assert.NoError(t, reconcilerHook(a, testDeployment, "")) + assert.Equal(t, testDeployment.Spec.Template.Spec.Containers[0].Command, want) assert.Equal(t, 0, len(testDeployment.Spec.Template.Spec.Containers[0].Args)) testDeployment = makeTestDeployment() testDeployment.ObjectMeta.Name = a.Name + "-" + "not-redis-ha-haproxy" want = testDeployment.Spec.Template.Spec.Containers[0].Command - assert.NilError(t, reconcilerHook(a, testDeployment, "")) - assert.DeepEqual(t, testDeployment.Spec.Template.Spec.Containers[0].Command, want) + assert.NoError(t, reconcilerHook(a, testDeployment, "")) + assert.Equal(t, testDeployment.Spec.Template.Spec.Containers[0].Command, want) } func TestReconcileArgoCD_reconcileRedisHaServerStatefulSet(t *testing.T) { a := makeTestArgoCD() s := newStatefulSetWithSuffix("redis-ha-server", "redis", a) - assert.NilError(t, reconcilerHook(a, s, "")) + assert.NoError(t, reconcilerHook(a, s, "")) // Check the name to ensure we're looking at the right container definition assert.Equal(t, s.Spec.Template.Spec.Containers[0].Name, "redis") - assert.DeepEqual(t, s.Spec.Template.Spec.Containers[0].Args, getArgsForRedhatHaRedisServer()) + assert.Equal(t, s.Spec.Template.Spec.Containers[0].Args, getArgsForRedhatHaRedisServer()) assert.Equal(t, 0, len(s.Spec.Template.Spec.Containers[0].Command)) // Check the name to ensure we're looking at the right container definition assert.Equal(t, s.Spec.Template.Spec.Containers[1].Name, "sentinel") - assert.DeepEqual(t, s.Spec.Template.Spec.Containers[1].Args, getArgsForRedhatHaRedisSentinel()) + assert.Equal(t, s.Spec.Template.Spec.Containers[1].Args, getArgsForRedhatHaRedisSentinel()) assert.Equal(t, 0, len(s.Spec.Template.Spec.Containers[1].Command)) - assert.DeepEqual(t, s.Spec.Template.Spec.InitContainers[0].Args, getArgsForRedhatHaRedisInitContainer()) + assert.Equal(t, s.Spec.Template.Spec.InitContainers[0].Args, getArgsForRedhatHaRedisInitContainer()) assert.Equal(t, 0, len(s.Spec.Template.Spec.InitContainers[0].Command)) s = newStatefulSetWithSuffix("not-redis-ha-server", "redis", a) @@ -169,9 +169,9 @@ func TestReconcileArgoCD_reconcileRedisHaServerStatefulSet(t *testing.T) { want0 := s.Spec.Template.Spec.Containers[0].Args want1 := s.Spec.Template.Spec.Containers[1].Args - assert.NilError(t, reconcilerHook(a, s, "")) - assert.DeepEqual(t, s.Spec.Template.Spec.Containers[0].Args, want0) - assert.DeepEqual(t, s.Spec.Template.Spec.Containers[1].Args, want1) + assert.NoError(t, reconcilerHook(a, s, "")) + assert.Equal(t, s.Spec.Template.Spec.Containers[0].Args, want0) + assert.Equal(t, s.Spec.Template.Spec.Containers[1].Args, want1) } func TestReconcileArgoCD_reconcilePolicyRuleForRedisHa(t *testing.T) { @@ -191,9 +191,9 @@ func TestReconcileArgoCD_reconcilePolicyRuleForRedisHa(t *testing.T) { }, } - assert.NilError(t, reconcilerHook(a, &rules, "policyRuleForRedisHa")) + assert.NoError(t, reconcilerHook(a, &rules, "policyRuleForRedisHa")) assert.Equal(t, 2, len(rules)) - assert.DeepEqual(t, rules[1], getPolicyRuleForRedisHa()) + assert.Equal(t, rules[1], getPolicyRuleForRedisHa()) } func TestReconcileArgoCD_reconcileSecrets(t *testing.T) { @@ -206,8 +206,8 @@ func TestReconcileArgoCD_reconcileSecrets(t *testing.T) { "namespaces": []byte(testNamespace), }, } - assert.NilError(t, reconcilerHook(a, testSecret, "")) - assert.DeepEqual(t, string(testSecret.Data["namespaces"]), "") + assert.NoError(t, reconcilerHook(a, testSecret, "")) + assert.Equal(t, string(testSecret.Data["namespaces"]), "") a.Namespace = "someRandomNamespace" testSecret = &corev1.Secret{ @@ -215,6 +215,6 @@ func TestReconcileArgoCD_reconcileSecrets(t *testing.T) { "namespaces": []byte("someRandomNamespace"), }, } - assert.NilError(t, reconcilerHook(a, testSecret, "")) - assert.DeepEqual(t, string(testSecret.Data["namespaces"]), "someRandomNamespace") + assert.NoError(t, reconcilerHook(a, testSecret, "")) + assert.Equal(t, string(testSecret.Data["namespaces"]), "someRandomNamespace") }