From d7fc1bf2d7afd88f40add2bdb40ae797e80afc35 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 17 Jun 2024 15:05:27 +0200 Subject: [PATCH] chore: enable require-error rule from errorlint linter on controller folder (#18690) Signed-off-by: Matthieu MOREL Signed-off-by: pasha-codefresh Co-authored-by: pasha-codefresh --- .golangci.yaml | 2 +- controller/appcontroller_test.go | 72 ++++++++--------- controller/clusterinfoupdater_test.go | 9 ++- controller/health_test.go | 17 ++-- controller/metrics/metrics_test.go | 31 +++---- controller/sharding/sharding_test.go | 17 ++-- controller/state_test.go | 81 ++++++++++--------- controller/sync_namespace_test.go | 3 +- controller/sync_test.go | 4 +- .../controller/controller_test.go | 5 +- 10 files changed, 124 insertions(+), 117 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 4684842e6d7a2..0b549fd364ff6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,7 +3,7 @@ issues: - SA1019 - SA5011 exclude-rules: - - path: "(cmpserver|controller|reposerver)/" + - path: "(cmpserver|reposerver)/" text: "require-error:" linters: - testifylint diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index 1833d28c2bd4f..389466908e71d 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -457,7 +457,7 @@ func TestAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, app.Operation) assert.NotNil(t, app.Operation.Sync) assert.False(t, app.Operation.Sync.Prune) @@ -501,7 +501,7 @@ func TestSkipAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) @@ -516,7 +516,7 @@ func TestSkipAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) @@ -532,7 +532,7 @@ func TestSkipAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) @@ -549,7 +549,7 @@ func TestSkipAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) @@ -575,7 +575,7 @@ func TestSkipAutoSync(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}) assert.NotNil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) @@ -591,7 +591,7 @@ func TestSkipAutoSync(t *testing.T) { }) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) }) } @@ -627,7 +627,7 @@ func TestAutoSyncIndicateError(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}) assert.NotNil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Nil(t, app.Operation) } @@ -670,7 +670,7 @@ func TestAutoSyncParameterOverrides(t *testing.T) { cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}) assert.Nil(t, cond) app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, app.Operation) } @@ -715,7 +715,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, patched) }) @@ -766,11 +766,11 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, patched) objsMap, err := ctrl.stateCache.GetManagedLiveObjs(app, []*unstructured.Unstructured{}) if err != nil { - assert.NoError(t, err) + require.NoError(t, err) } // Managed objects must be empty assert.Empty(t, objsMap) @@ -802,7 +802,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, patched) }) @@ -826,7 +826,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) } app1 := appTemplate.DeepCopy() @@ -869,7 +869,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) // finalizer is not deleted assert.False(t, patched) // post-delete hook is created @@ -907,7 +907,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) // finalizer is removed assert.True(t, patched) }) @@ -942,7 +942,7 @@ func TestFinalizeAppDeletion(t *testing.T) { err := ctrl.finalizeApplicationDeletion(app, func(project string) ([]*v1alpha1.Cluster, error) { return []*v1alpha1.Cluster{}, nil }) - assert.NoError(t, err) + require.NoError(t, err) // post-delete hook is deleted require.Len(t, ctrl.kubectl.(*MockKubectl).DeletedResources, 1) require.Equal(t, "post-delete-hook", ctrl.kubectl.(*MockKubectl).DeletedResources[0].Name) @@ -1103,7 +1103,7 @@ func TestGetResourceTree_HasOrphanedResources(t *testing.T) { TargetState: test.DeploymentManifest, }}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []v1alpha1.ResourceNode{managedDeploy}, tree.Nodes) assert.Equal(t, []v1alpha1.ResourceNode{orphanedDeploy1, orphanedDeploy2}, tree.OrphanedNodes) } @@ -1463,7 +1463,7 @@ func TestUpdateReconciledAt(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.AddReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1476,11 +1476,11 @@ func TestUpdateReconciledAt(t *testing.T) { ctrl.processAppRefreshQueueItem() _, updated, err := unstructured.NestedString(receivedPatch, "status", "reconciledAt") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, updated) _, updated, err = unstructured.NestedString(receivedPatch, "status", "observedAt") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, updated) }) @@ -1492,11 +1492,11 @@ func TestUpdateReconciledAt(t *testing.T) { ctrl.processAppRefreshQueueItem() _, updated, err := unstructured.NestedString(receivedPatch, "status", "reconciledAt") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, updated) _, updated, err = unstructured.NestedString(receivedPatch, "status", "observedAt") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, updated) }) } @@ -1522,7 +1522,7 @@ func TestProjectErrorToCondition(t *testing.T) { obj, ok, err := ctrl.appInformer.GetIndexer().GetByKey(key) assert.True(t, ok) - assert.NoError(t, err) + require.NoError(t, err) updatedApp := obj.(*v1alpha1.Application) assert.Equal(t, v1alpha1.ApplicationConditionInvalidSpecError, updatedApp.Status.Conditions[0].Type) assert.Equal(t, "Application referencing project wrong project which does not exist", updatedApp.Status.Conditions[0].Message) @@ -1542,7 +1542,7 @@ func TestFinalizeProjectDeletion_HasApplications(t *testing.T) { }) err := ctrl.finalizeProjectDeletion(proj) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, patched) } @@ -1554,13 +1554,13 @@ func TestFinalizeProjectDeletion_DoesNotHaveApplications(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.AppProject{}, nil }) err := ctrl.finalizeProjectDeletion(proj) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, map[string]interface{}{ "metadata": map[string]interface{}{ "finalizers": nil, @@ -1579,7 +1579,7 @@ func TestProcessRequestedAppOperation_FailedNoRetries(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1607,7 +1607,7 @@ func TestProcessRequestedAppOperation_InvalidDestination(t *testing.T) { defer fakeAppCs.Unlock() fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1633,7 +1633,7 @@ func TestProcessRequestedAppOperation_FailedHasRetries(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1676,7 +1676,7 @@ func TestProcessRequestedAppOperation_RunningPreviouslyFailed(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1709,7 +1709,7 @@ func TestProcessRequestedAppOperation_HasRetriesTerminated(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1736,7 +1736,7 @@ func TestProcessRequestedAppOperation_Successful(t *testing.T) { receivedPatch := map[string]interface{}{} fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { if patchAction, ok := action.(kubetesting.PatchAction); ok { - assert.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) + require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch)) } return true, &v1alpha1.Application{}, nil }) @@ -1799,7 +1799,7 @@ func TestGetAppHosts(t *testing.T) { }}, }}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []v1alpha1.HostInfo{{ Name: "minikube", SystemInfo: corev1.NodeSystemInfo{OSImage: "debian"}, @@ -1926,7 +1926,7 @@ func TestAddControllerNamespace(t *testing.T) { ctrl.processAppRefreshQueueItem() updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(ctrl.namespace).Get(context.Background(), app.Name, metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace) }) t.Run("set controllerNamespace when the app is in another namespace than the controller", func(t *testing.T) { @@ -1945,7 +1945,7 @@ func TestAddControllerNamespace(t *testing.T) { ctrl.processAppRefreshQueueItem() updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(appNamespace).Get(context.Background(), app.Name, metav1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace) }) } diff --git a/controller/clusterinfoupdater_test.go b/controller/clusterinfoupdater_test.go index b0a873f4ef587..989ac630d528a 100644 --- a/controller/clusterinfoupdater_test.go +++ b/controller/clusterinfoupdater_test.go @@ -23,6 +23,7 @@ import ( clustercache "github.com/argoproj/gitops-engine/pkg/cache" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/tools/cache" ) @@ -76,7 +77,7 @@ func TestClusterSecretUpdater(t *testing.T) { appCache := appstate.NewCache(cacheutil.NewCache(cacheutil.NewInMemoryCache(time.Minute)), time.Minute) cluster, err := argoDB.CreateCluster(ctx, &v1alpha1.Cluster{Server: "http://minikube"}) - assert.NoError(t, err, "Test prepare test data create cluster failed") + require.NoError(t, err, "Test prepare test data create cluster failed") for _, test := range tests { info := &clustercache.ClusterInfo{ @@ -90,11 +91,11 @@ func TestClusterSecretUpdater(t *testing.T) { updater := NewClusterInfoUpdater(nil, argoDB, lister, appCache, nil, nil, fakeNamespace) err = updater.updateClusterInfo(context.Background(), *cluster, info) - assert.NoError(t, err, "Invoking updateClusterInfo failed.") + require.NoError(t, err, "Invoking updateClusterInfo failed.") var clusterInfo v1alpha1.ClusterInfo err = appCache.GetClusterInfo(cluster.Server, &clusterInfo) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, updatedK8sVersion, clusterInfo.ServerVersion) assert.Equal(t, test.ExpectedStatus, clusterInfo.ConnectionState.Status) } @@ -103,7 +104,7 @@ func TestClusterSecretUpdater(t *testing.T) { func TestUpdateClusterLabels(t *testing.T) { shouldNotBeInvoked := func(ctx context.Context, cluster *v1alpha1.Cluster) (*v1alpha1.Cluster, error) { shouldNotHappen := errors.New("if an error happens here, something's wrong") - assert.NoError(t, shouldNotHappen) + require.NoError(t, shouldNotHappen) return nil, shouldNotHappen } tests := []struct { diff --git a/controller/health_test.go b/controller/health_test.go index ed2358bcbdfee..efaf4b2a8fc80 100644 --- a/controller/health_test.go +++ b/controller/health_test.go @@ -8,6 +8,7 @@ import ( synccommon "github.com/argoproj/gitops-engine/pkg/sync/common" "github.com/argoproj/gitops-engine/pkg/utils/kube" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" @@ -53,7 +54,7 @@ func TestSetApplicationHealth(t *testing.T) { resourceStatuses := initStatuses(resources) healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status) assert.Equal(t, health.HealthStatusHealthy, resourceStatuses[0].Health.Status) @@ -62,7 +63,7 @@ func TestSetApplicationHealth(t *testing.T) { // now mark the job as a hook and retry. it should ignore the hook and consider the app healthy failedJob.SetAnnotations(map[string]string{synccommon.AnnotationKeyHook: "PreSync"}) healthStatus, err = setApplicationHealth(resources, resourceStatuses, nil, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status) } @@ -75,7 +76,7 @@ func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) { resourceStatuses := initStatuses(resources) healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, false) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status) assert.Nil(t, resourceStatuses[0].Health) @@ -90,7 +91,7 @@ func TestSetApplicationHealth_MissingResource(t *testing.T) { resourceStatuses := initStatuses(resources) healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusMissing, healthStatus.Status) } @@ -104,7 +105,7 @@ func TestSetApplicationHealth_MissingResourceNoBuiltHealthCheck(t *testing.T) { t.Run("NoOverride", func(t *testing.T) { healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status) assert.Equal(t, health.HealthStatusMissing, resourceStatuses[0].Health.Status) }) @@ -115,7 +116,7 @@ func TestSetApplicationHealth_MissingResourceNoBuiltHealthCheck(t *testing.T) { HealthLua: "some health check", }, }, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusMissing, healthStatus.Status) }) } @@ -166,7 +167,7 @@ return hs`, resourceStatuses := initStatuses(resources) healthStatus, err := setApplicationHealth(resources, resourceStatuses, overrides, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status) }) @@ -178,7 +179,7 @@ return hs`, resourceStatuses := initStatuses(resources) healthStatus, err := setApplicationHealth(resources, resourceStatuses, overrides, app, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status) }) } diff --git a/controller/metrics/metrics_test.go b/controller/metrics/metrics_test.go index a1977fe888de9..28422be55f653 100644 --- a/controller/metrics/metrics_test.go +++ b/controller/metrics/metrics_test.go @@ -12,6 +12,7 @@ import ( gitopsCache "github.com/argoproj/gitops-engine/pkg/cache" "github.com/argoproj/gitops-engine/pkg/sync/common" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/cache" @@ -212,7 +213,7 @@ func runTest(t *testing.T, cfg TestMetricServerConfig) { cancel, appLister := newFakeLister(cfg.FakeAppYAMLs...) defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, cfg.AppLabels) - assert.NoError(t, err) + require.NoError(t, err) if len(cfg.ClustersInfo) > 0 { ci := &fakeClusterInfo{clustersInfo: cfg.ClustersInfo} @@ -224,7 +225,7 @@ func runTest(t *testing.T, cfg TestMetricServerConfig) { } req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -335,7 +336,7 @@ func TestMetricsSyncCounter(t *testing.T) { cancel, appLister := newFakeLister() defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}) - assert.NoError(t, err) + require.NoError(t, err) appSyncTotal := ` # HELP argocd_app_sync_total Number of application syncs. @@ -353,7 +354,7 @@ argocd_app_sync_total{dest_server="https://localhost:6443",name="my-app",namespa metricsServ.IncSync(fakeApp, &argoappv1.OperationState{Phase: common.OperationSucceeded}) req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -387,7 +388,7 @@ func TestReconcileMetrics(t *testing.T) { cancel, appLister := newFakeLister() defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}) - assert.NoError(t, err) + require.NoError(t, err) appReconcileMetrics := ` # HELP argocd_app_reconcile Application reconciliation performance in seconds. @@ -407,7 +408,7 @@ argocd_app_reconcile_count{dest_server="https://localhost:6443",namespace="argoc metricsServ.IncReconcile(fakeApp, 5*time.Second) req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -420,7 +421,7 @@ func TestMetricsReset(t *testing.T) { cancel, appLister := newFakeLister() defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}) - assert.NoError(t, err) + require.NoError(t, err) appSyncTotal := ` # HELP argocd_app_sync_total Number of application syncs. @@ -431,7 +432,7 @@ argocd_app_sync_total{dest_server="https://localhost:6443",name="my-app",namespa ` req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -439,10 +440,10 @@ argocd_app_sync_total{dest_server="https://localhost:6443",name="my-app",namespa assertMetricsPrinted(t, appSyncTotal, body) err = metricsServ.SetExpiration(time.Second) - assert.NoError(t, err) + require.NoError(t, err) time.Sleep(2 * time.Second) req, err = http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr = httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -450,14 +451,14 @@ argocd_app_sync_total{dest_server="https://localhost:6443",name="my-app",namespa log.Println(body) assertMetricsNotPrinted(t, appSyncTotal, body) err = metricsServ.SetExpiration(time.Second) - assert.Error(t, err) + require.Error(t, err) } func TestWorkqueueMetrics(t *testing.T) { cancel, appLister := newFakeLister() defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}) - assert.NoError(t, err) + require.NoError(t, err) expectedMetrics := ` # TYPE workqueue_adds_total counter @@ -479,7 +480,7 @@ workqueue_unfinished_work_seconds{name="test"} workqueue.NewNamed("test") req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) @@ -492,7 +493,7 @@ func TestGoMetrics(t *testing.T) { cancel, appLister := newFakeLister() defer cancel() metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}) - assert.NoError(t, err) + require.NoError(t, err) expectedMetrics := ` # TYPE go_gc_duration_seconds summary @@ -511,7 +512,7 @@ go_threads ` req, err := http.NewRequest(http.MethodGet, "/metrics", nil) - assert.NoError(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() metricsServ.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) diff --git a/controller/sharding/sharding_test.go b/controller/sharding/sharding_test.go index ca44b638961cc..ebd212062b199 100644 --- a/controller/sharding/sharding_test.go +++ b/controller/sharding/sharding_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -410,16 +411,16 @@ func TestInferShard(t *testing.T) { osHostnameError := errors.New("cannot resolve hostname") osHostnameFunction = func() (string, error) { return "exampleshard", osHostnameError } _, err := InferShard() - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, err, osHostnameError) osHostnameFunction = func() (string, error) { return "exampleshard", nil } _, err = InferShard() - assert.NoError(t, err) + require.NoError(t, err) osHostnameFunction = func() (string, error) { return "example-shard", nil } _, err = InferShard() - assert.NoError(t, err) + require.NoError(t, err) } func createTestClusters() (clusterAccessor, *dbmocks.ArgoDB, v1alpha1.Cluster, v1alpha1.Cluster, v1alpha1.Cluster, v1alpha1.Cluster, v1alpha1.Cluster) { @@ -494,7 +495,7 @@ func Test_generateDefaultShardMappingCM_NoPredefinedShard(t *testing.T) { } expectedMappingCM, err := json.Marshal(expectedMapping) - assert.NoError(t, err) + require.NoError(t, err) expectedShadingCM := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -508,7 +509,7 @@ func Test_generateDefaultShardMappingCM_NoPredefinedShard(t *testing.T) { heartbeatCurrentTime = func() metav1.Time { return expectedTime } osHostnameFunction = func() (string, error) { return "test-example", nil } shardingCM, err := generateDefaultShardMappingCM("test", "test-example", replicas, -1) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expectedShadingCM, shardingCM) } @@ -529,7 +530,7 @@ func Test_generateDefaultShardMappingCM_PredefinedShard(t *testing.T) { } expectedMappingCM, err := json.Marshal(expectedMapping) - assert.NoError(t, err) + require.NoError(t, err) expectedShadingCM := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -543,7 +544,7 @@ func Test_generateDefaultShardMappingCM_PredefinedShard(t *testing.T) { heartbeatCurrentTime = func() metav1.Time { return expectedTime } osHostnameFunction = func() (string, error) { return "test-example", nil } shardingCM, err := generateDefaultShardMappingCM("test", "test-example", replicas, 1) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expectedShadingCM, shardingCM) } @@ -970,7 +971,7 @@ func TestGetClusterSharding(t *testing.T) { t.Errorf("Expected error %v but got nil", tc.expectedErr) } } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/controller/state_test.go b/controller/state_test.go index 95dba246a72cf..58cfe5c596ebc 100644 --- a/controller/state_test.go +++ b/controller/state_test.go @@ -15,6 +15,7 @@ import ( "github.com/sirupsen/logrus" logrustest "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" v1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" @@ -50,7 +51,7 @@ func TestCompareAppStateEmpty(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -69,18 +70,18 @@ func TestCompareAppStateRepoError(t *testing.T) { revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) assert.Nil(t, compRes) - assert.EqualError(t, err, CompareStateRepoError.Error()) + require.EqualError(t, err, CompareStateRepoError.Error()) // expect to still get compare state error to as inside grace period compRes, err = ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) assert.Nil(t, compRes) - assert.EqualError(t, err, CompareStateRepoError.Error()) + require.EqualError(t, err, CompareStateRepoError.Error()) time.Sleep(10 * time.Second) // expect to not get error as outside of grace period, but status should be unknown compRes, err = ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) assert.NotNil(t, compRes) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, argoappv1.SyncStatusCodeUnknown, compRes.syncStatus.Status) } @@ -114,7 +115,7 @@ func TestCompareAppStateNamespaceMetadataDiffers(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeOutOfSync, compRes.syncStatus.Status) @@ -163,7 +164,7 @@ func TestCompareAppStateNamespaceMetadataDiffersToManifest(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeOutOfSync, compRes.syncStatus.Status) @@ -173,7 +174,7 @@ func TestCompareAppStateNamespaceMetadataDiffersToManifest(t *testing.T) { assert.Len(t, compRes.diffResultList.Diffs, 1) result := NewNamespace() - assert.NoError(t, json.Unmarshal(compRes.diffResultList.Diffs[0].PredictedLive, result)) + require.NoError(t, json.Unmarshal(compRes.diffResultList.Diffs[0].PredictedLive, result)) labels := result.GetLabels() delete(labels, "kubernetes.io/metadata.name") @@ -221,7 +222,7 @@ func TestCompareAppStateNamespaceMetadata(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeOutOfSync, compRes.syncStatus.Status) @@ -231,7 +232,7 @@ func TestCompareAppStateNamespaceMetadata(t *testing.T) { assert.Len(t, compRes.diffResultList.Diffs, 1) result := NewNamespace() - assert.NoError(t, json.Unmarshal(compRes.diffResultList.Diffs[0].PredictedLive, result)) + require.NoError(t, json.Unmarshal(compRes.diffResultList.Diffs[0].PredictedLive, result)) labels := result.GetLabels() delete(labels, "kubernetes.io/metadata.name") @@ -280,7 +281,7 @@ func TestCompareAppStateNamespaceMetadataIsTheSame(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -308,7 +309,7 @@ func TestCompareAppStateMissing(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeOutOfSync, compRes.syncStatus.Status) @@ -340,7 +341,7 @@ func TestCompareAppStateExtra(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeOutOfSync, compRes.syncStatus.Status) assert.Len(t, compRes.resources, 1) @@ -371,7 +372,7 @@ func TestCompareAppStateHook(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) assert.Empty(t, compRes.resources) @@ -403,7 +404,7 @@ func TestCompareAppStateSkipHook(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) assert.Len(t, compRes.resources, 1) @@ -434,7 +435,7 @@ func TestCompareAppStateCompareOptionIgnoreExtraneous(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -467,7 +468,7 @@ func TestCompareAppStateExtraHook(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -496,7 +497,7 @@ func TestAppRevisionsSingleSource(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, app.Spec.GetSources(), false, false, nil, app.Spec.HasMultipleSources(), false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.NotEmpty(t, compRes.syncStatus.Revision) @@ -536,7 +537,7 @@ func TestAppRevisionsMultiSource(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, app.Spec.GetSources(), false, false, nil, app.Spec.HasMultipleSources(), false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Empty(t, compRes.syncStatus.Revision) @@ -548,7 +549,7 @@ func TestAppRevisionsMultiSource(t *testing.T) { func toJSON(t *testing.T, obj *unstructured.Unstructured) string { data, err := json.Marshal(obj) - assert.NoError(t, err) + require.NoError(t, err) return string(data) } @@ -584,7 +585,7 @@ func TestCompareAppStateDuplicatedNamespacedResources(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Len(t, app.Status.Conditions, 1) @@ -621,7 +622,7 @@ func TestCompareAppStateManagedNamespaceMetadataWithLiveNsDoesNotGetPruned(t *te } ctrl := newFakeController(&data, nil) compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, []string{}, app.Spec.Sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Empty(t, app.Status.Conditions) @@ -675,7 +676,7 @@ func TestCompareAppStateWithManifestGeneratePath(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, app.Spec.GetSources(), false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) assert.Equal(t, "abc123", compRes.syncStatus.Revision) @@ -712,7 +713,7 @@ func TestSetHealth(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusHealthy, compRes.healthStatus.Status) } @@ -749,7 +750,7 @@ func TestSetHealthSelfReferencedApp(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusHealthy, compRes.healthStatus.Status) } @@ -773,7 +774,7 @@ func TestSetManagedResourcesWithOrphanedResources(t *testing.T) { tree, err := ctrl.setAppManagedResources(app, &comparisonResult{managedResources: make([]managedResource, 0)}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, tree.OrphanedNodes, 1) assert.Equal(t, "guestbook", tree.OrphanedNodes[0].Name) assert.Equal(t, app.Namespace, tree.OrphanedNodes[0].Namespace) @@ -802,7 +803,7 @@ func TestSetManagedResourcesWithResourcesOfAnotherApp(t *testing.T) { tree, err := ctrl.setAppManagedResources(app1, &comparisonResult{managedResources: make([]managedResource, 0)}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, tree.OrphanedNodes) } @@ -824,7 +825,7 @@ func TestReturnUnknownComparisonStateOnSettingLoadError(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, health.HealthStatusUnknown, compRes.healthStatus.Status) assert.Equal(t, argoappv1.SyncStatusCodeUnknown, compRes.syncStatus.Status) @@ -855,7 +856,7 @@ func TestSetManagedResourcesKnownOrphanedResourceExceptions(t *testing.T) { tree, err := ctrl.setAppManagedResources(app, &comparisonResult{managedResources: make([]managedResource, 0)}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, tree.OrphanedNodes, 1) assert.Equal(t, "guestbook", tree.OrphanedNodes[0].Name) } @@ -872,7 +873,7 @@ func Test_appStateManager_persistRevisionHistory(t *testing.T) { } addHistory := func() { err := manager.persistRevisionHistory(app, "my-revision", argoappv1.ApplicationSource{}, []string{}, []argoappv1.ApplicationSource{}, false, metav1.Time{}, v1alpha1.OperationInitiator{}) - assert.NoError(t, err) + require.NoError(t, err) } addHistory() assert.Len(t, app.Status.History, 1) @@ -908,7 +909,7 @@ func Test_appStateManager_persistRevisionHistory(t *testing.T) { metav1NowTime := metav1.NewTime(time.Now()) err := manager.persistRevisionHistory(app, "my-revision", argoappv1.ApplicationSource{}, []string{}, []argoappv1.ApplicationSource{}, false, metav1NowTime, v1alpha1.OperationInitiator{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, app.Status.History.LastRevisionHistory().DeployStartedAt, &metav1NowTime) } @@ -965,7 +966,7 @@ func TestSignedResponseNoSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -992,7 +993,7 @@ func TestSignedResponseNoSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1024,7 +1025,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1051,7 +1052,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1078,7 +1079,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1105,7 +1106,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1135,7 +1136,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &testProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1165,7 +1166,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, localManifests, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeUnknown, compRes.syncStatus.Status) @@ -1195,7 +1196,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, nil, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) @@ -1225,7 +1226,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) { revisions := make([]string, 0) revisions = append(revisions, "abc123") compRes, err := ctrl.appStateManager.CompareAppState(app, &signedProj, revisions, sources, false, false, localManifests, false, false) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, compRes) assert.NotNil(t, compRes.syncStatus) assert.Equal(t, argoappv1.SyncStatusCodeSynced, compRes.syncStatus.Status) diff --git a/controller/sync_namespace_test.go b/controller/sync_namespace_test.go index 5d3ed4299db5a..7e60b0d287789 100644 --- a/controller/sync_namespace_test.go +++ b/controller/sync_namespace_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -250,7 +251,7 @@ func Test_shouldNamespaceSync(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { actual, err := syncNamespace(argo.NewResourceTracking(), common.LabelKeyAppInstance, argo.TrackingMethodAnnotation, "some-app", tt.syncPolicy)(tt.managedNs, tt.liveNs) - assert.NoError(t, err) + require.NoError(t, err) if tt.managedNs != nil { assert.Equal(t, tt.expectedLabels, tt.managedNs.GetLabels()) diff --git a/controller/sync_test.go b/controller/sync_test.go index 59095d5d40e35..1dbfa2ff9e1a5 100644 --- a/controller/sync_test.go +++ b/controller/sync_test.go @@ -53,7 +53,7 @@ func TestPersistRevisionHistory(t *testing.T) { assert.Equal(t, app.Spec.GetSource(), opState.SyncResult.Source) updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(context.Background(), app.Name, v1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, updatedApp.Status.History, 1) assert.Equal(t, app.Spec.GetSource(), updatedApp.Status.History[0].Source) assert.Equal(t, "abc123", updatedApp.Status.History[0].Revision) @@ -142,7 +142,7 @@ func TestPersistRevisionHistoryRollback(t *testing.T) { assert.Equal(t, source, opState.SyncResult.Source) updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(context.Background(), app.Name, v1.GetOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, updatedApp.Status.History, 1) assert.Equal(t, source, updatedApp.Status.History[0].Source) assert.Equal(t, "abc123", updatedApp.Status.History[0].Revision) diff --git a/notification_controller/controller/controller_test.go b/notification_controller/controller/controller_test.go index 5cef5023473aa..ca901cf2c1890 100644 --- a/notification_controller/controller/controller_test.go +++ b/notification_controller/controller/controller_test.go @@ -7,6 +7,7 @@ import ( "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic/fake" @@ -133,7 +134,7 @@ func TestInit(t *testing.T) { err = nc.Init(ctx) - assert.NoError(t, err) + require.NoError(t, err) } } @@ -169,7 +170,7 @@ func TestInitTimeout(t *testing.T) { err = nc.Init(ctx) // Expect an error & add assertion for the error message - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "Timed out waiting for caches to sync", err.Error()) }