diff --git a/.golangci.yaml b/.golangci.yaml index a472d5183e8f6..4684842e6d7a2 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,7 +3,7 @@ issues: - SA1019 - SA5011 exclude-rules: - - path: "(applicationset|cmpserver|controller|reposerver)/" + - path: "(cmpserver|controller|reposerver)/" text: "require-error:" linters: - testifylint diff --git a/applicationset/controllers/applicationset_controller_test.go b/applicationset/controllers/applicationset_controller_test.go index 58dafe832e798..444179ef892c4 100644 --- a/applicationset/controllers/applicationset_controller_test.go +++ b/applicationset/controllers/applicationset_controller_test.go @@ -12,6 +12,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -123,7 +124,7 @@ func (r *rendererMock) Replace(tmpl string, replaceMap map[string]interface{}, u func TestExtractApplications(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { name string @@ -238,9 +239,9 @@ func TestExtractApplications(t *testing.T) { }) if cc.expectErr { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Equal(t, expectedApps, got) assert.Equal(t, cc.expectedReason, reason) @@ -356,10 +357,10 @@ func TestMergeTemplateApplications(t *testing.T) { func TestCreateOrUpdateInCluster(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { // name is human-readable test name @@ -1350,7 +1351,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) { for _, a := range c.existingApps { err = controllerutil.SetControllerReference(&c.appSet, &a, scheme) - assert.NoError(t, err) + require.NoError(t, err) initObjs = append(initObjs, &a) } @@ -1364,7 +1365,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) { } err = r.createOrUpdateInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps) - assert.NoError(t, err) + require.NoError(t, err) for _, obj := range c.expected { got := &v1alpha1.Application{} @@ -1383,10 +1384,10 @@ func TestCreateOrUpdateInCluster(t *testing.T) { func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { // name is human-readable test name @@ -1477,18 +1478,18 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) { // argoDB := db.NewDB("namespace", settingsMgr, r.KubeClientset) // clusterList, err := argoDB.ListClusters(context.Background()) clusterList, err := utils.ListClusters(context.Background(), kubeclientset, "namespace") - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") appLog := log.WithFields(log.Fields{"app": app.Name, "appSet": ""}) appInputParam := app.DeepCopy() err = r.removeFinalizerOnInvalidDestination(context.Background(), appSet, appInputParam, clusterList, appLog) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") // App on the cluster should have the expected finalizers assert.ElementsMatch(t, c.expectedFinalizers, retrievedApp.Finalizers) @@ -1505,10 +1506,10 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) { func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { // name is human-readable test name @@ -1635,18 +1636,18 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) { // argoDB := db.NewDB("argocd", settingsMgr, r.KubeClientset) // clusterList, err := argoDB.ListClusters(context.Background()) clusterList, err := utils.ListClusters(context.Background(), kubeclientset, "namespace") - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") appLog := log.WithFields(log.Fields{"app": app.Name, "appSet": ""}) appInputParam := app.DeepCopy() err = r.removeFinalizerOnInvalidDestination(context.Background(), appSet, appInputParam, clusterList, appLog) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") finalizerRemoved := len(retrievedApp.Finalizers) == 0 @@ -1661,10 +1662,10 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) { func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { // name is human-readable test name @@ -1706,7 +1707,7 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { } err := controllerutil.SetControllerReference(&appSet, &app, scheme) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") initObjs := []crtclient.Object{&app, &appSet} @@ -1721,11 +1722,11 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { } err = r.removeOwnerReferencesOnDeleteAppSet(context.Background(), appSet) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - assert.NoError(t, err, "Unexpected error") + require.NoError(t, err, "Unexpected error") ownerReferencesRemoved := len(retrievedApp.OwnerReferences) == 0 assert.True(t, ownerReferencesRemoved) @@ -1736,10 +1737,10 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { func TestCreateApplications(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) testCases := []struct { name string @@ -1904,7 +1905,7 @@ func TestCreateApplications(t *testing.T) { initObjs := []crtclient.Object{&c.appSet} for _, a := range c.existsApps { err = controllerutil.SetControllerReference(&c.appSet, &a, scheme) - assert.NoError(t, err) + require.NoError(t, err) initObjs = append(initObjs, &a) } @@ -1918,7 +1919,7 @@ func TestCreateApplications(t *testing.T) { } err = r.createInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.apps) - assert.NoError(t, err) + require.NoError(t, err) for _, obj := range c.expected { got := &v1alpha1.Application{} @@ -1928,7 +1929,7 @@ func TestCreateApplications(t *testing.T) { }, got) err = controllerutil.SetControllerReference(&c.appSet, &obj, r.Scheme) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, obj, *got) } @@ -1939,9 +1940,9 @@ func TestCreateApplications(t *testing.T) { func TestDeleteInCluster(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { // appSet is the application set on which the delete function is called @@ -2047,7 +2048,7 @@ func TestDeleteInCluster(t *testing.T) { for _, a := range c.existingApps { temp := a err = controllerutil.SetControllerReference(&c.appSet, &temp, scheme) - assert.NoError(t, err) + require.NoError(t, err) initObjs = append(initObjs, &temp) } @@ -2061,7 +2062,7 @@ func TestDeleteInCluster(t *testing.T) { } err = r.deleteInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps) - assert.NoError(t, err) + require.NoError(t, err) // For each of the expected objects, verify they exist on the cluster for _, obj := range c.expected { @@ -2072,7 +2073,7 @@ func TestDeleteInCluster(t *testing.T) { }, got) err = controllerutil.SetControllerReference(&c.appSet, &obj, r.Scheme) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, obj, *got) } @@ -2093,9 +2094,9 @@ func TestDeleteInCluster(t *testing.T) { func TestGetMinRequeueAfter(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) client := fake.NewClientBuilder().WithScheme(scheme).Build() @@ -2141,10 +2142,10 @@ func TestGetMinRequeueAfter(t *testing.T) { func TestValidateGeneratedApplications(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) client := fake.NewClientBuilder().WithScheme(scheme).Build() @@ -2378,9 +2379,9 @@ func TestValidateGeneratedApplications(t *testing.T) { func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) project := v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: "good-project", Namespace: "argocd"}, @@ -2455,27 +2456,27 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) { // Verify that on validation error, no error is returned, but the object is requeued res, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ReconcileRequeueOnValidationError, res.RequeueAfter) var app v1alpha1.Application // make sure good app got created err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-project"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "good-project", app.Name) // make sure bad app was not created err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "bad-project"}, &app) - assert.Error(t, err) + require.Error(t, err) } func TestReconcilerCreateAppsRecoveringRenderError(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) project := v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"}, @@ -2543,23 +2544,23 @@ func TestReconcilerCreateAppsRecoveringRenderError(t *testing.T) { // Verify that on generatorsError, no error is returned, but the object is requeued res, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ReconcileRequeueOnValidationError, res.RequeueAfter) var app v1alpha1.Application // make sure good app got created err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "app"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "app", app.Name) } func TestSetApplicationSetStatusCondition(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appSet := v1alpha1.ApplicationSet{ ObjectMeta: metav1.ObjectMeta{ @@ -2606,7 +2607,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) { } err = r.setApplicationSetStatusCondition(context.TODO(), &appSet, appCondition, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, appSet.Status.Conditions, 3) } @@ -2614,9 +2615,9 @@ func TestSetApplicationSetStatusCondition(t *testing.T) { func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.Application { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) defaultProject := v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"}, @@ -2691,20 +2692,20 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp // Verify that on validation error, no error is returned, but the object is requeued resCreate, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), resCreate.RequeueAfter) var app v1alpha1.Application // make sure good app got created err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "good-cluster", app.Name) // Update resource var retrievedApplicationSet v1alpha1.ApplicationSet err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet) - assert.NoError(t, err) + require.NoError(t, err) retrievedApplicationSet.Spec.Template.Annotations = map[string]string{"annotation-key": "annotation-value"} retrievedApplicationSet.Spec.Template.Labels = map[string]string{"label-key": "label-value"} @@ -2714,13 +2715,13 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp } err = r.Client.Update(context.TODO(), &retrievedApplicationSet) - assert.NoError(t, err) + require.NoError(t, err) resUpdate, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), resUpdate.RequeueAfter) assert.Equal(t, "good-cluster", app.Name) @@ -2778,9 +2779,9 @@ func TestUpdatePerformedWithSyncPolicyCreateOnlyAndAllowPolicyOverrideFalse(t *t func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.ApplicationList { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) defaultProject := v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"}, @@ -2855,20 +2856,20 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp // Verify that on validation error, no error is returned, but the object is requeued resCreate, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), resCreate.RequeueAfter) var app v1alpha1.Application // make sure good app got created err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "good-cluster", app.Name) // Update resource var retrievedApplicationSet v1alpha1.ApplicationSet err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet) - assert.NoError(t, err) + require.NoError(t, err) retrievedApplicationSet.Spec.Generators = []v1alpha1.ApplicationSetGenerator{ { List: &v1alpha1.ListGenerator{ @@ -2878,15 +2879,15 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp } err = r.Client.Update(context.TODO(), &retrievedApplicationSet) - assert.NoError(t, err) + require.NoError(t, err) resUpdate, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) var apps v1alpha1.ApplicationList err = r.Client.List(context.TODO(), &apps) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), resUpdate.RequeueAfter) return apps @@ -3050,10 +3051,10 @@ func TestGenerateAppsUsingPullRequestGenerator(t *testing.T) { func TestPolicies(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) defaultProject := v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"}, @@ -3166,25 +3167,25 @@ func TestPolicies(t *testing.T) { // Check if Application is created res, err := r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), res.RequeueAfter) var app v1alpha1.Application err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "value", app.Annotations["key"]) // Check if Application is updated app.Annotations["key"] = "edited" err = r.Client.Update(context.TODO(), &app) - assert.NoError(t, err) + require.NoError(t, err) res, err = r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), res.RequeueAfter) err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app) - assert.NoError(t, err) + require.NoError(t, err) if c.allowedUpdate { assert.Equal(t, "value", app.Annotations["key"]) @@ -3194,21 +3195,21 @@ func TestPolicies(t *testing.T) { // Check if Application is deleted err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &appSet) - assert.NoError(t, err) + require.NoError(t, err) appSet.Spec.Generators[0] = v1alpha1.ApplicationSetGenerator{ List: &v1alpha1.ListGenerator{ Elements: []apiextensionsv1.JSON{}, }, } err = r.Client.Update(context.TODO(), &appSet) - assert.NoError(t, err) + require.NoError(t, err) res, err = r.Reconcile(context.Background(), req) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, time.Duration(0), res.RequeueAfter) err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app) - assert.NoError(t, err) + require.NoError(t, err) if c.allowedDelete { assert.NotNil(t, app.DeletionTimestamp) } else { @@ -3221,9 +3222,9 @@ func TestPolicies(t *testing.T) { func TestSetApplicationSetApplicationStatus(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...) argoDBMock := dbmocks.ArgoDB{} @@ -3317,7 +3318,7 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) { } err = r.setAppSetApplicationStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appStatuses) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, cc.expectedAppStatuses, cc.appSet.Status.ApplicationStatus) }) @@ -3327,10 +3328,10 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) { func TestBuildAppDependencyList(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) client := fake.NewClientBuilder().WithScheme(scheme).Build() @@ -4077,7 +4078,7 @@ func TestBuildAppDependencyList(t *testing.T) { } appDependencyList, appStepMap, err := r.buildAppDependencyList(log.NewEntry(log.StandardLogger()), cc.appSet, cc.apps) - assert.NoError(t, err, "expected no errors, but errors occurred") + require.NoError(t, err, "expected no errors, but errors occurred") assert.Equal(t, cc.expectedList, appDependencyList, "expected appDependencyList did not match actual") assert.Equal(t, cc.expectedStepMap, appStepMap, "expected appStepMap did not match actual") }) @@ -4087,10 +4088,10 @@ func TestBuildAppDependencyList(t *testing.T) { func TestBuildAppSyncMap(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) client := fake.NewClientBuilder().WithScheme(scheme).Build() @@ -4668,7 +4669,7 @@ func TestBuildAppSyncMap(t *testing.T) { } appSyncMap, err := r.buildAppSyncMap(context.TODO(), cc.appSet, cc.appDependencyList, cc.appMap) - assert.NoError(t, err, "expected no errors, but errors occurred") + require.NoError(t, err, "expected no errors, but errors occurred") assert.Equal(t, cc.expectedMap, appSyncMap, "expected appSyncMap did not match actual") }) } @@ -4677,10 +4678,10 @@ func TestBuildAppSyncMap(t *testing.T) { func TestUpdateApplicationSetApplicationStatus(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, cc := range []struct { name string @@ -5401,7 +5402,7 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { appStatuses[i].LastTransitionTime = nil } - assert.NoError(t, err, "expected no errors, but errors occurred") + require.NoError(t, err, "expected no errors, but errors occurred") assert.Equal(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") }) } @@ -5410,10 +5411,10 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, cc := range []struct { name string @@ -6152,7 +6153,7 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) { appStatuses[i].LastTransitionTime = nil } - assert.NoError(t, err, "expected no errors, but errors occurred") + require.NoError(t, err, "expected no errors, but errors occurred") assert.Equal(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") }) } @@ -6161,10 +6162,10 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) { func TestUpdateResourceStatus(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, cc := range []struct { name string @@ -6362,7 +6363,7 @@ func TestUpdateResourceStatus(t *testing.T) { err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps) - assert.NoError(t, err, "expected no errors, but errors occurred") + require.NoError(t, err, "expected no errors, but errors occurred") assert.Equal(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual") }) } diff --git a/applicationset/controllers/clustereventhandler_test.go b/applicationset/controllers/clustereventhandler_test.go index cfec651434f35..15ce757954db2 100644 --- a/applicationset/controllers/clustereventhandler_test.go +++ b/applicationset/controllers/clustereventhandler_test.go @@ -6,6 +6,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -22,10 +23,10 @@ import ( func TestClusterEventHandler(t *testing.T) { scheme := runtime.NewScheme() err := argov1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = argov1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) tests := []struct { name string @@ -577,7 +578,7 @@ func TestNestedGeneratorHasClusterGenerator_NestedClusterGenerator(t *testing.T) hasClusterGenerator, err := nestedGeneratorHasClusterGenerator(nested) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, hasClusterGenerator) } @@ -604,7 +605,7 @@ func TestNestedGeneratorHasClusterGenerator_NestedMergeGenerator(t *testing.T) { hasClusterGenerator, err := nestedGeneratorHasClusterGenerator(nested) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, hasClusterGenerator) } @@ -631,6 +632,6 @@ func TestNestedGeneratorHasClusterGenerator_NestedMergeGeneratorWithInvalidJSON( hasClusterGenerator, err := nestedGeneratorHasClusterGenerator(nested) - assert.Error(t, err) + require.Error(t, err) assert.False(t, hasClusterGenerator) } diff --git a/applicationset/controllers/requeue_after_test.go b/applicationset/controllers/requeue_after_test.go index 73075bd246cca..10067c119b78d 100644 --- a/applicationset/controllers/requeue_after_test.go +++ b/applicationset/controllers/requeue_after_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -25,7 +26,7 @@ func TestRequeueAfter(t *testing.T) { ctx := context.Background() scheme := runtime.NewScheme() err := argov1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) gvrToListKind := map[schema.GroupVersionResource]string{{ Group: "mallard.io", Version: "v1", diff --git a/applicationset/generators/cluster_test.go b/applicationset/generators/cluster_test.go index 50908e7f7b705..a943dc98cdf2b 100644 --- a/applicationset/generators/cluster_test.go +++ b/applicationset/generators/cluster_test.go @@ -17,6 +17,7 @@ import ( argoprojiov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type possiblyErroringFakeCtrlRuntimeClient struct { @@ -262,9 +263,9 @@ func TestGenerateParams(t *testing.T) { }, &applicationSetInfo, nil) if testCase.expectedError != nil { - assert.EqualError(t, err, testCase.expectedError.Error()) + require.EqualError(t, err, testCase.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } }) @@ -635,9 +636,9 @@ func TestGenerateParamsGoTemplate(t *testing.T) { }, &applicationSetInfo, nil) if testCase.expectedError != nil { - assert.EqualError(t, err, testCase.expectedError.Error()) + require.EqualError(t, err, testCase.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } }) diff --git a/applicationset/generators/duck_type_test.go b/applicationset/generators/duck_type_test.go index ed82a5c9fe075..d2cfdbc59d6bc 100644 --- a/applicationset/generators/duck_type_test.go +++ b/applicationset/generators/duck_type_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -311,9 +312,9 @@ func TestGenerateParamsForDuckType(t *testing.T) { }, &applicationSetInfo, nil) if testCase.expectedError != nil { - assert.EqualError(t, err, testCase.expectedError.Error()) + require.EqualError(t, err, testCase.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } }) @@ -609,9 +610,9 @@ func TestGenerateParamsForDuckTypeGoTemplate(t *testing.T) { }, &applicationSetInfo, nil) if testCase.expectedError != nil { - assert.EqualError(t, err, testCase.expectedError.Error()) + require.EqualError(t, err, testCase.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } }) diff --git a/applicationset/generators/generator_spec_processor_test.go b/applicationset/generators/generator_spec_processor_test.go index 8f29aba4d698b..dfa89782f9a1f 100644 --- a/applicationset/generators/generator_spec_processor_test.go +++ b/applicationset/generators/generator_spec_processor_test.go @@ -90,7 +90,7 @@ func TestMatchValues(t *testing.T) { emptyTemplate(), &applicationSetInfo, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, results[0].Params) }) } @@ -174,7 +174,7 @@ func TestMatchValuesGoTemplate(t *testing.T) { emptyTemplate(), &applicationSetInfo, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, results[0].Params) }) } @@ -244,7 +244,7 @@ func TestTransForm(t *testing.T) { emptyTemplate(), &applicationSetInfo, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, results[0].Params) }) } @@ -555,7 +555,7 @@ func TestInterpolateGeneratorError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := InterpolateGenerator(tt.args.requestedGenerator, tt.args.params, tt.args.useGoTemplate, tt.args.goTemplateOptions) if tt.expectedErrStr != "" { - assert.EqualError(t, err, tt.expectedErrStr) + require.EqualError(t, err, tt.expectedErrStr) } else { require.NoError(t, err) } diff --git a/applicationset/generators/git_test.go b/applicationset/generators/git_test.go index 275406cd6fc1a..4f55b1c4391b2 100644 --- a/applicationset/generators/git_test.go +++ b/applicationset/generators/git_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -342,7 +343,7 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appProject := argoprojiov1alpha1.AppProject{} client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appProject).Build() @@ -350,9 +351,9 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { got, err := gitGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, client) if testCaseCopy.expectedError != nil { - assert.EqualError(t, err, testCaseCopy.expectedError.Error()) + require.EqualError(t, err, testCaseCopy.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } @@ -643,7 +644,7 @@ func TestGitGenerateParamsFromDirectoriesGoTemplate(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appProject := argoprojiov1alpha1.AppProject{} client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appProject).Build() @@ -651,9 +652,9 @@ func TestGitGenerateParamsFromDirectoriesGoTemplate(t *testing.T) { got, err := gitGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, client) if testCaseCopy.expectedError != nil { - assert.EqualError(t, err, testCaseCopy.expectedError.Error()) + require.EqualError(t, err, testCaseCopy.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } @@ -1007,7 +1008,7 @@ cluster: scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appProject := argoprojiov1alpha1.AppProject{} client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appProject).Build() @@ -1016,9 +1017,9 @@ cluster: fmt.Println(got, err) if testCaseCopy.expectedError != nil { - assert.EqualError(t, err, testCaseCopy.expectedError.Error()) + require.EqualError(t, err, testCaseCopy.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCaseCopy.expected, got) } @@ -1363,7 +1364,7 @@ cluster: scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appProject := argoprojiov1alpha1.AppProject{} client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appProject).Build() @@ -1372,9 +1373,9 @@ cluster: fmt.Println(got, err) if testCaseCopy.expectedError != nil { - assert.EqualError(t, err, testCaseCopy.expectedError.Error()) + require.EqualError(t, err, testCaseCopy.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCaseCopy.expected, got) } diff --git a/applicationset/generators/list_test.go b/applicationset/generators/list_test.go index cf8f0bca54938..5a3b1d88dd4f4 100644 --- a/applicationset/generators/list_test.go +++ b/applicationset/generators/list_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -40,7 +41,7 @@ func TestGenerateListParams(t *testing.T) { }, }, &applicationSetInfo, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } } @@ -77,7 +78,7 @@ func TestGenerateListParamsGoTemplate(t *testing.T) { }, }, &applicationSetInfo, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, testCase.expected, got) } } diff --git a/applicationset/generators/matrix_test.go b/applicationset/generators/matrix_test.go index 86e7f236364ff..440fafd3f3ad2 100644 --- a/applicationset/generators/matrix_test.go +++ b/applicationset/generators/matrix_test.go @@ -183,9 +183,9 @@ func TestMatrixGenerate(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.ErrorIs(t, err, testCaseCopy.expectedErr) + require.ErrorIs(t, err, testCaseCopy.expectedErr) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -396,9 +396,9 @@ func TestMatrixGenerateGoTemplate(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.ErrorIs(t, err, testCaseCopy.expectedErr) + require.ErrorIs(t, err, testCaseCopy.expectedErr) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -682,9 +682,9 @@ func TestInterpolatedMatrixGenerate(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.ErrorIs(t, err, testCaseCopy.expectedErr) + require.ErrorIs(t, err, testCaseCopy.expectedErr) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -867,9 +867,9 @@ func TestInterpolatedMatrixGenerateGoTemplate(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.ErrorIs(t, err, testCaseCopy.expectedErr) + require.ErrorIs(t, err, testCaseCopy.expectedErr) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -1028,9 +1028,9 @@ func TestMatrixGenerateListElementsYaml(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.ErrorIs(t, err, testCaseCopy.expectedErr) + require.ErrorIs(t, err, testCaseCopy.expectedErr) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -1115,7 +1115,7 @@ func TestGitGenerator_GenerateParams_list_x_git_matrix_generator(t *testing.T) { scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) appProject := argoprojiov1alpha1.AppProject{} client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appProject).Build() diff --git a/applicationset/generators/merge_test.go b/applicationset/generators/merge_test.go index eba356c081f72..005e5c2c32905 100644 --- a/applicationset/generators/merge_test.go +++ b/applicationset/generators/merge_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" argoprojiov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" @@ -180,15 +181,15 @@ func TestMergeGenerate(t *testing.T) { }, appSet, nil) if testCaseCopy.expectedErr != nil { - assert.EqualError(t, err, testCaseCopy.expectedErr.Error()) + require.EqualError(t, err, testCaseCopy.expectedErr.Error()) } else { expectedSet, err := listOfMapsToSet(testCaseCopy.expected) - assert.NoError(t, err) + require.NoError(t, err) actualSet, err := listOfMapsToSet(got) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expectedSet, actualSet) } }) @@ -337,9 +338,9 @@ func TestParamSetsAreUniqueByMergeKeys(t *testing.T) { got, err := getParamSetsByMergeKey(testCaseCopy.mergeKeys, testCaseCopy.paramSets) if testCaseCopy.expectedErr != nil { - assert.EqualError(t, err, testCaseCopy.expectedErr.Error()) + require.EqualError(t, err, testCaseCopy.expectedErr.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) diff --git a/applicationset/generators/plugin_test.go b/applicationset/generators/plugin_test.go index 0b3deb9e0ab04..55ebcfd5c7820 100644 --- a/applicationset/generators/plugin_test.go +++ b/applicationset/generators/plugin_test.go @@ -654,7 +654,7 @@ func TestPluginGenerateParams(t *testing.T) { w.Header().Set("Content-Type", "application/json") _, err := w.Write(testCase.content) if err != nil { - assert.NoError(t, fmt.Errorf("Error Write %w", err)) + require.NoError(t, fmt.Errorf("Error Write %w", err)) } }) @@ -687,9 +687,9 @@ func TestPluginGenerateParams(t *testing.T) { } if testCase.expectedError != nil { - assert.EqualError(t, err, testCase.expectedError.Error()) + require.EqualError(t, err, testCase.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) expectedJson, err := json.Marshal(testCase.expected) require.NoError(t, err) gotJson, err := json.Marshal(got) diff --git a/applicationset/generators/pull_request_test.go b/applicationset/generators/pull_request_test.go index 95730822469ab..c35d231a60d5a 100644 --- a/applicationset/generators/pull_request_test.go +++ b/applicationset/generators/pull_request_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -217,7 +218,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) { if c.expectedErr != nil { assert.Equal(t, c.expectedErr.Error(), gotErr.Error()) } else { - assert.NoError(t, gotErr) + require.NoError(t, gotErr) } assert.ElementsMatch(t, c.expected, got) } @@ -279,9 +280,9 @@ func TestPullRequestGetSecretRef(t *testing.T) { t.Run(c.name, func(t *testing.T) { token, err := gen.getSecretRef(ctx, c.ref, c.namespace) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Equal(t, c.token, token) }) @@ -359,7 +360,7 @@ func TestAllowedSCMProviderPullRequest(t *testing.T) { _, err := pullRequestGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, nil) - assert.Error(t, err, "Must return an error") + require.Error(t, err, "Must return an error") assert.ErrorAs(t, err, testCaseCopy.expectedError) }) } diff --git a/applicationset/generators/scm_provider_test.go b/applicationset/generators/scm_provider_test.go index d2ce25f38b26a..04291b6303e83 100644 --- a/applicationset/generators/scm_provider_test.go +++ b/applicationset/generators/scm_provider_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -69,9 +70,9 @@ func TestSCMProviderGetSecretRef(t *testing.T) { t.Run(c.name, func(t *testing.T) { token, err := gen.getSecretRef(ctx, c.ref, c.namespace) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Equal(t, c.token, token) }) @@ -192,7 +193,7 @@ func TestSCMProviderGenerateParams(t *testing.T) { if testCaseCopy.expectedError != nil { assert.EqualError(t, err, testCaseCopy.expectedError.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) @@ -282,7 +283,7 @@ func TestAllowedSCMProvider(t *testing.T) { _, err := scmGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, nil) - assert.Error(t, err, "Must return an error") + require.Error(t, err, "Must return an error") assert.ErrorAs(t, err, testCaseCopy.expectedError) }) } diff --git a/applicationset/generators/value_interpolation_test.go b/applicationset/generators/value_interpolation_test.go index adf39ccb7642b..5b490233d5d7e 100644 --- a/applicationset/generators/value_interpolation_test.go +++ b/applicationset/generators/value_interpolation_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestValueInterpolation(t *testing.T) { @@ -55,7 +56,7 @@ func TestValueInterpolation(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { err := appendTemplatedValues(testCase.values, testCase.params, false, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.EqualValues(t, testCase.expected, testCase.params) }) } @@ -116,7 +117,7 @@ func TestValueInterpolationWithGoTemplating(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { err := appendTemplatedValues(testCase.values, testCase.params, true, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.EqualValues(t, testCase.expected, testCase.params) }) } diff --git a/applicationset/services/pull_request/azure_devops_test.go b/applicationset/services/pull_request/azure_devops_test.go index e4962036d55b4..1b335f72f92c8 100644 --- a/applicationset/services/pull_request/azure_devops_test.go +++ b/applicationset/services/pull_request/azure_devops_test.go @@ -8,6 +8,7 @@ import ( git "github.com/microsoft/azure-devops-go-api/azuredevops/git" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" azureMock "github.com/argoproj/argo-cd/v2/applicationset/services/scm_provider/azure_devops/git/mocks" ) @@ -92,7 +93,7 @@ func TestListPullRequest(t *testing.T) { } list, err := provider.List(ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, list, 1) assert.Equal(t, "feature-branch", list[0].Branch) assert.Equal(t, pr_head_sha, list[0].HeadSHA) diff --git a/applicationset/services/pull_request/bitbucket_cloud_test.go b/applicationset/services/pull_request/bitbucket_cloud_test.go index 5e5d966163c10..73b0836207673 100644 --- a/applicationset/services/pull_request/bitbucket_cloud_test.go +++ b/applicationset/services/pull_request/bitbucket_cloud_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -52,26 +53,26 @@ func TestParseUrlEmptyUrl(t *testing.T) { url, err := parseUrl("") bitbucketUrl, _ := url.Parse("https://api.bitbucket.org/2.0") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, bitbucketUrl, url) } func TestInvalidBaseUrlBasicAuthCloud(t *testing.T) { _, err := NewBitbucketCloudServiceBasicAuth("http:// example.org", "user", "password", "OWNER", "REPO") - assert.Error(t, err) + require.Error(t, err) } func TestInvalidBaseUrlBearerTokenCloud(t *testing.T) { _, err := NewBitbucketCloudServiceBearerToken("http:// example.org", "TOKEN", "OWNER", "REPO") - assert.Error(t, err) + require.Error(t, err) } func TestInvalidBaseUrlNoAuthCloud(t *testing.T) { _, err := NewBitbucketCloudServiceNoAuth("http:// example.org", "OWNER", "REPO") - assert.Error(t, err) + require.Error(t, err) } func TestListPullRequestBearerTokenCloud(t *testing.T) { @@ -81,9 +82,9 @@ func TestListPullRequestBearerTokenCloud(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketCloudServiceBearerToken(ts.URL, "TOKEN", "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, 101, pullRequests[0].Number) assert.Equal(t, "feat(foo-bar)", pullRequests[0].Title) @@ -98,9 +99,9 @@ func TestListPullRequestNoAuthCloud(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, 101, pullRequests[0].Number) assert.Equal(t, "feat(foo-bar)", pullRequests[0].Title) @@ -115,9 +116,9 @@ func TestListPullRequestBasicAuthCloud(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketCloudServiceBasicAuth(ts.URL, "user", "password", "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, 101, pullRequests[0].Number) assert.Equal(t, "feat(foo-bar)", pullRequests[0].Title) @@ -196,9 +197,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 3) assert.Equal(t, PullRequest{ Number: 101, @@ -227,7 +228,7 @@ func TestListResponseErrorCloud(t *testing.T) { defer ts.Close() svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") _, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.Error(t, err) + require.Error(t, err) } func TestListResponseMalformedCloud(t *testing.T) { @@ -251,7 +252,7 @@ func TestListResponseMalformedCloud(t *testing.T) { defer ts.Close() svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") _, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.Error(t, err) + require.Error(t, err) } func TestListResponseMalformedValuesCloud(t *testing.T) { @@ -275,7 +276,7 @@ func TestListResponseMalformedValuesCloud(t *testing.T) { defer ts.Close() svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") _, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.Error(t, err) + require.Error(t, err) } func TestListResponseEmptyCloud(t *testing.T) { @@ -298,9 +299,9 @@ func TestListResponseEmptyCloud(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, pullRequests) } @@ -376,13 +377,13 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { defer ts.Close() regexp := `feature-1[\d]{2}` svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 2) assert.Equal(t, PullRequest{ Number: 101, @@ -399,13 +400,13 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { regexp = `.*2$` svc, err = NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, PullRequest{ Number: 102, @@ -416,11 +417,11 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { regexp = `[\d{2}` svc, err = NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO") - assert.NoError(t, err) + require.NoError(t, err) _, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.Error(t, err) + require.Error(t, err) } diff --git a/applicationset/services/pull_request/bitbucket_server_test.go b/applicationset/services/pull_request/bitbucket_server_test.go index c42f7553af821..4969d82b67a1b 100644 --- a/applicationset/services/pull_request/bitbucket_server_test.go +++ b/applicationset/services/pull_request/bitbucket_server_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -56,9 +57,9 @@ func TestListPullRequestNoAuth(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, 101, pullRequests[0].Number) assert.Equal(t, "feat(ABC) : 123", pullRequests[0].Title) @@ -141,9 +142,9 @@ func TestListPullRequestPagination(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 3) assert.Equal(t, PullRequest{ Number: 101, @@ -180,9 +181,9 @@ func TestListPullRequestBasicAuth(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketServiceBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, 101, pullRequests[0].Number) assert.Equal(t, "feat(ABC) : 123", pullRequests[0].Title) @@ -197,7 +198,7 @@ func TestListResponseError(t *testing.T) { defer ts.Close() svc, _ := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") _, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.Error(t, err) + require.Error(t, err) } func TestListResponseMalformed(t *testing.T) { @@ -222,7 +223,7 @@ func TestListResponseMalformed(t *testing.T) { defer ts.Close() svc, _ := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") _, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.Error(t, err) + require.Error(t, err) } func TestListResponseEmpty(t *testing.T) { @@ -246,9 +247,9 @@ func TestListResponseEmpty(t *testing.T) { })) defer ts.Close() svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, pullRequests) } @@ -327,13 +328,13 @@ func TestListPullRequestBranchMatch(t *testing.T) { defer ts.Close() regexp := `feature-1[\d]{2}` svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 2) assert.Equal(t, PullRequest{ Number: 101, @@ -354,13 +355,13 @@ func TestListPullRequestBranchMatch(t *testing.T) { regexp = `.*2$` svc, err = NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) pullRequests, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, PullRequest{ Number: 102, @@ -373,11 +374,11 @@ func TestListPullRequestBranchMatch(t *testing.T) { regexp = `[\d{2}` svc, err = NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO") - assert.NoError(t, err) + require.NoError(t, err) _, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{ { BranchMatch: ®exp, }, }) - assert.Error(t, err) + require.Error(t, err) } diff --git a/applicationset/services/pull_request/gitea_test.go b/applicationset/services/pull_request/gitea_test.go index 94e2a95a08229..231f7d102a424 100644 --- a/applicationset/services/pull_request/gitea_test.go +++ b/applicationset/services/pull_request/gitea_test.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/sdk/gitea" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) { @@ -250,9 +251,9 @@ func TestGiteaList(t *testing.T) { giteaMockHandler(t)(w, r) })) host, err := NewGiteaService(context.Background(), "", ts.URL, "test-argocd", "pr-test", false) - assert.NoError(t, err) + require.NoError(t, err) prs, err := host.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, prs, 1) assert.Equal(t, 1, prs[0].Number) assert.Equal(t, "add an empty file", prs[0].Title) diff --git a/applicationset/services/pull_request/gitlab_test.go b/applicationset/services/pull_request/gitlab_test.go index b7423fbbd1e82..14cee3309b40a 100644 --- a/applicationset/services/pull_request/gitlab_test.go +++ b/applicationset/services/pull_request/gitlab_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func writeMRListResponse(t *testing.T, w io.Writer) { @@ -35,10 +36,10 @@ func TestGitLabServiceCustomBaseURL(t *testing.T) { }) svc, err := NewGitLabService(context.Background(), "", server.URL, "278964", nil, "", "", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = svc.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) } func TestGitLabServiceToken(t *testing.T) { @@ -54,10 +55,10 @@ func TestGitLabServiceToken(t *testing.T) { }) svc, err := NewGitLabService(context.Background(), "token-123", server.URL, "278964", nil, "", "", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = svc.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) } func TestList(t *testing.T) { @@ -73,10 +74,10 @@ func TestList(t *testing.T) { }) svc, err := NewGitLabService(context.Background(), "", server.URL, "278964", []string{}, "", "", false) - assert.NoError(t, err) + require.NoError(t, err) prs, err := svc.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, prs, 1) assert.Equal(t, 15442, prs[0].Number) assert.Equal(t, "Draft: Use structured logging for DB load balancer", prs[0].Title) @@ -98,10 +99,10 @@ func TestListWithLabels(t *testing.T) { }) svc, err := NewGitLabService(context.Background(), "", server.URL, "278964", []string{"feature", "ready"}, "", "", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = svc.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) } func TestListWithState(t *testing.T) { @@ -117,8 +118,8 @@ func TestListWithState(t *testing.T) { }) svc, err := NewGitLabService(context.Background(), "", server.URL, "278964", []string{}, "opened", "", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = svc.List(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) } diff --git a/applicationset/services/pull_request/utils_test.go b/applicationset/services/pull_request/utils_test.go index 75655d6c39e34..c688086395533 100644 --- a/applicationset/services/pull_request/utils_test.go +++ b/applicationset/services/pull_request/utils_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" argoprojiov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -33,7 +34,7 @@ func TestFilterBranchMatchBadRegexp(t *testing.T) { }, } _, err := ListPullRequests(context.Background(), provider, filters) - assert.Error(t, err) + require.Error(t, err) } func TestFilterBranchMatch(t *testing.T) { @@ -77,7 +78,7 @@ func TestFilterBranchMatch(t *testing.T) { }, } pullRequests, err := ListPullRequests(context.Background(), provider, filters) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, "two", pullRequests[0].Branch) } @@ -123,7 +124,7 @@ func TestFilterTargetBranchMatch(t *testing.T) { }, } pullRequests, err := ListPullRequests(context.Background(), provider, filters) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 1) assert.Equal(t, "two", pullRequests[0].Branch) } @@ -172,7 +173,7 @@ func TestMultiFilterOr(t *testing.T) { }, } pullRequests, err := ListPullRequests(context.Background(), provider, filters) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 3) assert.Equal(t, "two", pullRequests[0].Branch) assert.Equal(t, "three", pullRequests[1].Branch) @@ -225,7 +226,7 @@ func TestMultiFilterOrWithTargetBranchFilter(t *testing.T) { }, } pullRequests, err := ListPullRequests(context.Background(), provider, filters) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, pullRequests, 2) assert.Equal(t, "two", pullRequests[0].Branch) assert.Equal(t, "four", pullRequests[1].Branch) @@ -254,7 +255,7 @@ func TestNoFilters(t *testing.T) { ) filters := []argoprojiov1alpha1.PullRequestGeneratorFilter{} repos, err := ListPullRequests(context.Background(), provider, filters) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, "one", repos[0].Branch) assert.Equal(t, "two", repos[1].Branch) diff --git a/applicationset/services/repo_service_test.go b/applicationset/services/repo_service_test.go index 7660502130ce5..dbce9843a1b23 100644 --- a/applicationset/services/repo_service_test.go +++ b/applicationset/services/repo_service_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/reposerver/apiclient" repo_mocks "github.com/argoproj/argo-cd/v2/reposerver/apiclient/mocks" @@ -190,6 +191,6 @@ func TestNewArgoCDService(t *testing.T) { service, err := NewArgoCDService(func(ctx context.Context, url, project string) (*v1alpha1.Repository, error) { return &v1alpha1.Repository{}, nil }, false, &repo_mocks.Clientset{}, false) - assert.NoError(t, err, err) + require.NoError(t, err, err) assert.NotNil(t, service) } diff --git a/applicationset/services/scm_provider/azure_devops_test.go b/applicationset/services/scm_provider/azure_devops_test.go index aa9e48582c5a2..3379653401888 100644 --- a/applicationset/services/scm_provider/azure_devops_test.go +++ b/applicationset/services/scm_provider/azure_devops_test.go @@ -8,6 +8,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "k8s.io/utils/ptr" "github.com/microsoft/azure-devops-go-api/azuredevops" @@ -92,14 +93,14 @@ func TestAzureDevopsRepoHasPath(t *testing.T) { hasPath, err := provider.RepoHasPath(ctx, repo, path) if testCase.clientError != nil { - assert.ErrorContains(t, err, testCase.clientError.Error()) + require.ErrorContains(t, err, testCase.clientError.Error()) gitClientMock.AssertNotCalled(t, "GetItem", ctx, azureGit.GetItemArgs{Project: &teamProject, Path: &path, VersionDescriptor: &azureGit.GitVersionDescriptor{Version: &branchName}, RepositoryId: repoId}) return } if testCase.returnError { - assert.ErrorContains(t, err, testCase.errorMessage) + require.ErrorContains(t, err, testCase.errorMessage) } assert.Equal(t, testCase.pathFound, hasPath) @@ -156,9 +157,9 @@ func TestGetDefaultBranchOnDisabledRepo(t *testing.T) { branches, err := provider.GetBranches(ctx, repo) if testCase.shouldReturnError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Empty(t, branches) @@ -215,9 +216,9 @@ func TestGetAllBranchesOnDisabledRepo(t *testing.T) { branches, err := provider.GetBranches(ctx, repo) if testCase.shouldReturnError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Empty(t, branches) @@ -251,7 +252,7 @@ func TestAzureDevOpsGetDefaultBranchStripsRefsName(t *testing.T) { provider := AzureDevOpsProvider{organization: organization, teamProject: teamProject, clientFactory: clientFactoryMock, allBranches: false} branches, err := provider.GetBranches(ctx, repo) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, branches, 1) assert.Equal(t, strippedBranchName, branches[0].Branch) @@ -308,7 +309,7 @@ func TestAzureDevOpsGetBranchesDefultBranchOnly(t *testing.T) { branches, err := provider.GetBranches(ctx, repo) if testCase.clientError != nil { - assert.ErrorContains(t, err, testCase.clientError.Error()) + require.ErrorContains(t, err, testCase.clientError.Error()) gitClientMock.AssertNotCalled(t, "GetBranch", ctx, azureGit.GetBranchArgs{RepositoryId: &repoName, Project: &teamProject, Name: &defaultBranch}) return @@ -316,7 +317,7 @@ func TestAzureDevOpsGetBranchesDefultBranchOnly(t *testing.T) { if testCase.getBranchesApiError != nil { assert.Empty(t, branches) - assert.ErrorContains(t, err, testCase.getBranchesApiError.Error()) + require.ErrorContains(t, err, testCase.getBranchesApiError.Error()) } else { if testCase.expectedBranch != nil { assert.NotEmpty(t, branches) @@ -392,20 +393,20 @@ func TestAzureDevopsGetBranches(t *testing.T) { branches, err := provider.GetBranches(ctx, repo) if testCase.expectedProcessingErrorMsg != "" { - assert.ErrorContains(t, err, testCase.expectedProcessingErrorMsg) + require.ErrorContains(t, err, testCase.expectedProcessingErrorMsg) assert.Nil(t, branches) return } if testCase.clientError != nil { - assert.ErrorContains(t, err, testCase.clientError.Error()) + require.ErrorContains(t, err, testCase.clientError.Error()) gitClientMock.AssertNotCalled(t, "GetBranches", ctx, azureGit.GetBranchesArgs{RepositoryId: &repoName, Project: &teamProject}) return } if testCase.getBranchesApiError != nil { assert.Empty(t, branches) - assert.ErrorContains(t, err, testCase.getBranchesApiError.Error()) + require.ErrorContains(t, err, testCase.getBranchesApiError.Error()) } else { if len(*testCase.expectedBranches) > 0 { assert.NotEmpty(t, branches) @@ -488,7 +489,7 @@ func TestGetAzureDevopsRepositories(t *testing.T) { repositories, err := provider.ListRepos(ctx, "https") if testCase.getRepositoriesError != nil { - assert.Error(t, err, "Expected an error from test case %v", testCase.name) + require.Error(t, err, "Expected an error from test case %v", testCase.name) } if testCase.expectedNumberOfRepos == 0 { diff --git a/applicationset/services/scm_provider/bitbucket_cloud_test.go b/applicationset/services/scm_provider/bitbucket_cloud_test.go index dc7732e9f6850..d4127dbbf4002 100644 --- a/applicationset/services/scm_provider/bitbucket_cloud_test.go +++ b/applicationset/services/scm_provider/bitbucket_cloud_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -18,7 +19,7 @@ func TestBitbucketHasRepo(t *testing.T) { res.WriteHeader(http.StatusNotFound) _, err := res.Write([]byte("")) if err != nil { - assert.NoError(t, fmt.Errorf("Error in mock response %w", err)) + require.NoError(t, fmt.Errorf("Error in mock response %w", err)) } } if req.URL.Path == "/repositories/test-owner/testmike/src/dc1edb6c7d650d8ba67719ddf7b662ad8f8fb798/.gitignore" { @@ -55,7 +56,7 @@ func TestBitbucketHasRepo(t *testing.T) { "size": 624 }`)) if err != nil { - assert.NoError(t, fmt.Errorf("Error in mock response %w", err)) + require.NoError(t, fmt.Errorf("Error in mock response %w", err)) } } })) @@ -95,7 +96,7 @@ func TestBitbucketHasRepo(t *testing.T) { } hasPath, err := provider.RepoHasPath(context.Background(), repo, c.path) if err != nil { - assert.Error(t, fmt.Errorf("Error in test %w", err)) + require.Error(t, fmt.Errorf("Error in test %w", err)) } if c.status != http.StatusOK { assert.False(t, hasPath) @@ -208,7 +209,7 @@ func TestBitbucketListRepos(t *testing.T) { "size": 1 }`)) if err != nil { - assert.NoError(t, fmt.Errorf("Error in mock response %w", err)) + require.NoError(t, fmt.Errorf("Error in mock response %w", err)) } } if req.URL.Path == "/repositories/test-owner/testmike/refs/branches/main" { @@ -303,7 +304,7 @@ func TestBitbucketListRepos(t *testing.T) { } }`)) if err != nil { - assert.NoError(t, fmt.Errorf("Error in mock response %w", err)) + require.NoError(t, fmt.Errorf("Error in mock response %w", err)) } } if req.URL.Path == "/repositories/test-owner" { @@ -442,7 +443,7 @@ func TestBitbucketListRepos(t *testing.T) { "size": 1 }`)) if err != nil { - assert.NoError(t, fmt.Errorf("Error in mock response %w", err)) + require.NoError(t, fmt.Errorf("Error in mock response %w", err)) } } })) @@ -489,9 +490,9 @@ func TestBitbucketListRepos(t *testing.T) { provider, _ := NewBitBucketCloudProvider(context.Background(), c.owner, "user", "password", c.allBranches) rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) repos := []*Repository{} branches := []string{} for _, r := range rawRepos { diff --git a/applicationset/services/scm_provider/bitbucket_server_test.go b/applicationset/services/scm_provider/bitbucket_server_test.go index e1990b8d116a2..a8fc7afac5580 100644 --- a/applicationset/services/scm_provider/bitbucket_server_test.go +++ b/applicationset/services/scm_provider/bitbucket_server_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) { @@ -79,7 +80,7 @@ func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) { } func verifyDefaultRepo(t *testing.T, err error, repos []*Repository) { - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -99,7 +100,7 @@ func TestListReposNoAuth(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "ssh") verifyDefaultRepo(t, err, repos) } @@ -191,9 +192,9 @@ func TestListReposPagination(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "ssh") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -268,7 +269,7 @@ func TestGetBranchesBranchPagination(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.GetBranches(context.Background(), &Repository{ Organization: "PROJECT", Repository: "REPO", @@ -276,7 +277,7 @@ func TestGetBranchesBranchPagination(t *testing.T) { Labels: []string{}, RepositoryId: 1, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -321,7 +322,7 @@ func TestGetBranchesDefaultOnly(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.GetBranches(context.Background(), &Repository{ Organization: "PROJECT", Repository: "REPO", @@ -329,7 +330,7 @@ func TestGetBranchesDefaultOnly(t *testing.T) { Labels: []string{}, RepositoryId: 1, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -353,7 +354,7 @@ func TestGetBranchesMissingDefault(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.GetBranches(context.Background(), &Repository{ Organization: "PROJECT", Repository: "REPO", @@ -361,7 +362,7 @@ func TestGetBranchesMissingDefault(t *testing.T) { Labels: []string{}, RepositoryId: 1, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, repos) } @@ -375,7 +376,7 @@ func TestGetBranchesEmptyRepo(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.GetBranches(context.Background(), &Repository{ Organization: "PROJECT", Repository: "REPO", @@ -384,7 +385,7 @@ func TestGetBranchesEmptyRepo(t *testing.T) { RepositoryId: 1, }) assert.Empty(t, repos) - assert.NoError(t, err) + require.NoError(t, err) } func TestGetBranchesErrorDefaultBranch(t *testing.T) { @@ -398,7 +399,7 @@ func TestGetBranchesErrorDefaultBranch(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = provider.GetBranches(context.Background(), &Repository{ Organization: "PROJECT", Repository: "REPO", @@ -406,7 +407,7 @@ func TestGetBranchesErrorDefaultBranch(t *testing.T) { Labels: []string{}, RepositoryId: 1, }) - assert.Error(t, err) + require.Error(t, err) } func TestListReposBasicAuth(t *testing.T) { @@ -417,7 +418,7 @@ func TestListReposBasicAuth(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "ssh") verifyDefaultRepo(t, err, repos) } @@ -444,9 +445,9 @@ func TestListReposDefaultBranch(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "ssh") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -470,9 +471,9 @@ func TestListReposMissingDefaultBranch(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "ssh") - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, repos) } @@ -487,9 +488,9 @@ func TestListReposErrorDefaultBranch(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false) - assert.NoError(t, err) + require.NoError(t, err) _, err = provider.ListRepos(context.Background(), "ssh") - assert.Error(t, err) + require.Error(t, err) } func TestListReposCloneProtocol(t *testing.T) { @@ -499,9 +500,9 @@ func TestListReposCloneProtocol(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repos, err := provider.ListRepos(context.Background(), "https") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, Repository{ Organization: "PROJECT", @@ -521,9 +522,9 @@ func TestListReposUnknownProtocol(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) _, errProtocol := provider.ListRepos(context.Background(), "http") - assert.Error(t, errProtocol) + require.Error(t, errProtocol) } func TestBitbucketServerHasPath(t *testing.T) { @@ -559,36 +560,36 @@ func TestBitbucketServerHasPath(t *testing.T) { })) defer ts.Close() provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true) - assert.NoError(t, err) + require.NoError(t, err) repo := &Repository{ Organization: "PROJECT", Repository: "REPO", Branch: "main", } ok, err := provider.RepoHasPath(context.Background(), repo, "pkg") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) ok, err = provider.RepoHasPath(context.Background(), repo, "pkg/") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) ok, err = provider.RepoHasPath(context.Background(), repo, "anotherpkg/file.txt") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) ok, err = provider.RepoHasPath(context.Background(), repo, "anotherpkg/missing.txt") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, ok) ok, err = provider.RepoHasPath(context.Background(), repo, "notathing") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, ok) ok, err = provider.RepoHasPath(context.Background(), repo, "return-redirect") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) _, err = provider.RepoHasPath(context.Background(), repo, "unauthorized-response") - assert.Error(t, err) + require.Error(t, err) } diff --git a/applicationset/services/scm_provider/gitea_test.go b/applicationset/services/scm_provider/gitea_test.go index fedbe22d986c4..231913761014b 100644 --- a/applicationset/services/scm_provider/gitea_test.go +++ b/applicationset/services/scm_provider/gitea_test.go @@ -306,9 +306,9 @@ func TestGiteaListRepos(t *testing.T) { provider, _ := NewGiteaProvider(context.Background(), "test-argocd", "", ts.URL, c.allBranches, false) rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) // Just check that this one project shows up. Not a great test but better thing nothing? repos := []*Repository{} branches := []string{} @@ -342,19 +342,19 @@ func TestGiteaHasPath(t *testing.T) { t.Run("file exists", func(t *testing.T) { ok, err := host.RepoHasPath(context.Background(), repo, "README.md") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) }) t.Run("directory exists", func(t *testing.T) { ok, err := host.RepoHasPath(context.Background(), repo, "gitea") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) }) t.Run("does not exists", func(t *testing.T) { ok, err := host.RepoHasPath(context.Background(), repo, "notathing") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, ok) }) } diff --git a/applicationset/services/scm_provider/github_test.go b/applicationset/services/scm_provider/github_test.go index b9f576617135c..03b59c801721a 100644 --- a/applicationset/services/scm_provider/github_test.go +++ b/applicationset/services/scm_provider/github_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -244,9 +245,9 @@ func TestGithubListRepos(t *testing.T) { provider, _ := NewGithubProvider(context.Background(), "argoproj", "", ts.URL, c.allBranches) rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) // Just check that this one project shows up. Not a great test but better thing nothing? repos := []*Repository{} branches := []string{} @@ -278,11 +279,11 @@ func TestGithubHasPath(t *testing.T) { Branch: "master", } ok, err := host.RepoHasPath(context.Background(), repo, "pkg/") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, ok) ok, err = host.RepoHasPath(context.Background(), repo, "notathing/") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, ok) } @@ -299,7 +300,7 @@ func TestGithubGetBranches(t *testing.T) { } repos, err := host.GetBranches(context.Background(), repo) if err != nil { - assert.NoError(t, err) + require.NoError(t, err) } else { assert.Equal(t, "master", repos[0].Branch) } @@ -310,13 +311,13 @@ func TestGithubGetBranches(t *testing.T) { Branch: "main", } _, err = host.GetBranches(context.Background(), repo2) - assert.NoError(t, err) + require.NoError(t, err) // Get all branches host.allBranches = true repos, err = host.GetBranches(context.Background(), repo) if err != nil { - assert.NoError(t, err) + require.NoError(t, err) } else { // considering master branch to exist. assert.Len(t, repos, 1) diff --git a/applicationset/services/scm_provider/gitlab_test.go b/applicationset/services/scm_provider/gitlab_test.go index 0e8403b1663a6..c897e9b3183de 100644 --- a/applicationset/services/scm_provider/gitlab_test.go +++ b/applicationset/services/scm_provider/gitlab_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -1123,9 +1124,9 @@ func TestGitlabListRepos(t *testing.T) { provider, _ := NewGitlabProvider(context.Background(), "test-argocd-proton", "", ts.URL, c.allBranches, c.includeSubgroups, c.includeSharedProjects, c.insecure, "", c.topic) rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto) if c.hasError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) // Just check that this one project shows up. Not a great test but better than nothing? repos := []*Repository{} uniqueRepos := map[string]int{} @@ -1195,7 +1196,7 @@ func TestGitlabHasPath(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { ok, err := host.RepoHasPath(context.Background(), repo, c.path) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, c.exists, ok) }) } @@ -1213,7 +1214,7 @@ func TestGitlabGetBranches(t *testing.T) { } t.Run("branch exists", func(t *testing.T) { repos, err := host.GetBranches(context.Background(), repo) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "master", repos[0].Branch) }) @@ -1223,6 +1224,6 @@ func TestGitlabGetBranches(t *testing.T) { } t.Run("unknown branch", func(t *testing.T) { _, err := host.GetBranches(context.Background(), repo2) - assert.NoError(t, err) + require.NoError(t, err) }) } diff --git a/applicationset/services/scm_provider/utils_test.go b/applicationset/services/scm_provider/utils_test.go index 452148a34b633..83c6c4fc23d9e 100644 --- a/applicationset/services/scm_provider/utils_test.go +++ b/applicationset/services/scm_provider/utils_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" argoprojiov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" ) @@ -37,7 +38,7 @@ func TestFilterRepoMatch(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, "one", repos[0].Repository) assert.Equal(t, "three", repos[1].Repository) @@ -66,7 +67,7 @@ func TestFilterLabelMatch(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, "one", repos[0].Repository) assert.Equal(t, "two", repos[1].Repository) @@ -92,7 +93,7 @@ func TestFilterPathExists(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, "two", repos[0].Repository) } @@ -117,7 +118,7 @@ func TestFilterPathDoesntExists(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) } @@ -135,7 +136,7 @@ func TestFilterRepoMatchBadRegexp(t *testing.T) { }, } _, err := ListRepos(context.Background(), provider, filters, "") - assert.Error(t, err) + require.Error(t, err) } func TestFilterLabelMatchBadRegexp(t *testing.T) { @@ -152,7 +153,7 @@ func TestFilterLabelMatchBadRegexp(t *testing.T) { }, } _, err := ListRepos(context.Background(), provider, filters, "") - assert.Error(t, err) + require.Error(t, err) } func TestFilterBranchMatch(t *testing.T) { @@ -186,7 +187,7 @@ func TestFilterBranchMatch(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 2) assert.Equal(t, "one", repos[0].Repository) assert.Equal(t, "two", repos[0].Branch) @@ -218,7 +219,7 @@ func TestMultiFilterAnd(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 1) assert.Equal(t, "two", repos[0].Repository) } @@ -249,7 +250,7 @@ func TestMultiFilterOr(t *testing.T) { }, } repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 3) assert.Equal(t, "one", repos[0].Repository) assert.Equal(t, "two", repos[1].Repository) @@ -275,7 +276,7 @@ func TestNoFilters(t *testing.T) { } filters := []argoprojiov1alpha1.SCMProviderGeneratorFilter{} repos, err := ListRepos(context.Background(), provider, filters, "") - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, repos, 3) assert.Equal(t, "one", repos[0].Repository) assert.Equal(t, "two", repos[1].Repository) diff --git a/applicationset/utils/clusterUtils_test.go b/applicationset/utils/clusterUtils_test.go index 63d9b3887175d..9e8694359b6bd 100644 --- a/applicationset/utils/clusterUtils_test.go +++ b/applicationset/utils/clusterUtils_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -33,7 +34,7 @@ func Test_secretToCluster(t *testing.T) { }, } cluster, err := secretToCluster(secret) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, argoappv1.Cluster{ Name: "test", Server: "http://mycluster", @@ -56,7 +57,7 @@ func Test_secretToCluster_NoConfig(t *testing.T) { }, } cluster, err := secretToCluster(secret) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, argoappv1.Cluster{ Name: "test", Server: "http://mycluster", @@ -92,7 +93,7 @@ func TestValidateDestination(t *testing.T) { } appCond := ValidateDestination(context.Background(), &dest, nil, fakeNamespace) - assert.NoError(t, appCond) + require.NoError(t, appCond) assert.False(t, dest.IsServerInferred()) }) @@ -107,7 +108,7 @@ func TestValidateDestination(t *testing.T) { kubeclientset := fake.NewSimpleClientset(objects...) appCond := ValidateDestination(context.Background(), &dest, kubeclientset, fakeNamespace) - assert.NoError(t, appCond) + require.NoError(t, appCond) assert.Equal(t, "https://127.0.0.1:6443", dest.Server) assert.True(t, dest.IsServerInferred()) }) diff --git a/applicationset/utils/map_test.go b/applicationset/utils/map_test.go index 6fd4ae906baa1..c12216e0e1ac6 100644 --- a/applicationset/utils/map_test.go +++ b/applicationset/utils/map_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCombineStringMaps(t *testing.T) { @@ -49,7 +50,7 @@ func TestCombineStringMaps(t *testing.T) { if testCaseCopy.expectedErr != nil { assert.EqualError(t, err, testCaseCopy.expectedErr.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCaseCopy.expected, got) } }) diff --git a/applicationset/utils/utils_test.go b/applicationset/utils/utils_test.go index e029a4e909c4f..5b9ed9295780b 100644 --- a/applicationset/utils/utils_test.go +++ b/applicationset/utils/utils_test.go @@ -188,7 +188,7 @@ func TestRenderTemplateParams(t *testing.T) { assert.Equal(t, "default", newApplication.ObjectMeta.Namespace) assert.Equal(t, newApplication.ObjectMeta.UID, types.UID("d546da12-06b7-4f9a-8ea2-3adb16a20e2b")) assert.Equal(t, newApplication.ObjectMeta.CreationTimestamp, application.ObjectMeta.CreationTimestamp) - assert.NoError(t, err) + require.NoError(t, err) } }) } @@ -237,13 +237,13 @@ func TestRenderHelmValuesObjectJson(t *testing.T) { render := Render{} newApplication, err := render.RenderTemplateParams(application, nil, params, true, []string{}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, newApplication) var unmarshaled interface{} err = json.Unmarshal(newApplication.Spec.Source.Helm.ValuesObject.Raw, &unmarshaled) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Hello world", unmarshaled.(map[string]interface{})["some"].(map[string]interface{})["string"]) } @@ -287,13 +287,13 @@ func TestRenderHelmValuesObjectYaml(t *testing.T) { render := Render{} newApplication, err := render.RenderTemplateParams(application, nil, params, true, []string{}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, newApplication) var unmarshaled interface{} err = json.Unmarshal(newApplication.Spec.Source.Helm.ValuesObject.Raw, &unmarshaled) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Hello world", unmarshaled.(map[string]interface{})["some"].(map[string]interface{})["string"]) } @@ -621,10 +621,10 @@ func TestRenderTemplateParamsGoTemplate(t *testing.T) { // Retrieve the value of the target field from the newApplication, then verify that // the target field has been templated into the expected value if test.errorMessage != "" { - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, test.errorMessage, err.Error()) } else { - assert.NoError(t, err) + require.NoError(t, err) actualValue := *getPtrFunc(newApplication) assert.Equal(t, test.expectedVal, actualValue, "Field '%s' had an unexpected value. expected: '%s' value: '%s'", fieldName, test.expectedVal, actualValue) assert.Equal(t, "annotation-value", newApplication.ObjectMeta.Annotations["annotation-key"]) @@ -666,7 +666,7 @@ func TestRenderGeneratorParams_does_not_panic(t *testing.T) { }, } _, err := render.RenderGeneratorParams(generator, params, true, []string{}) - assert.NoError(t, err) + require.NoError(t, err) } func TestRenderTemplateKeys(t *testing.T) { @@ -716,7 +716,7 @@ func Test_Render_Replace_no_panic_on_missing_closing_brace(t *testing.T) { r := &Render{} assert.NotPanics(t, func() { _, err := r.Replace("{{properly.closed}} {{improperly.closed}", nil, false, []string{}) - assert.Error(t, err) + require.Error(t, err) }) } @@ -812,7 +812,7 @@ func TestRenderTemplateParamsFinalizers(t *testing.T) { render := Render{} res, err := render.RenderTemplateParams(application, c.syncPolicy, params, true, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, res.Finalizers, c.expectedFinalizers) }) @@ -822,9 +822,9 @@ func TestRenderTemplateParamsFinalizers(t *testing.T) { func TestCheckInvalidGenerators(t *testing.T) { scheme := runtime.NewScheme() err := argoappsv1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = argoappsv1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { testName string @@ -925,9 +925,9 @@ func TestCheckInvalidGenerators(t *testing.T) { func TestInvalidGenerators(t *testing.T) { scheme := runtime.NewScheme() err := argoappsv1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = argoappsv1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, c := range []struct { testName string diff --git a/applicationset/webhook/webhook_test.go b/applicationset/webhook/webhook_test.go index 6c1f6be29cfc4..14fc5ce68503b 100644 --- a/applicationset/webhook/webhook_test.go +++ b/applicationset/webhook/webhook_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -180,9 +181,9 @@ func TestWebhookHandler(t *testing.T) { fakeClient := newFakeClient(namespace) scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) err = v1alpha1.AddToScheme(scheme) - assert.NoError(t, err) + require.NoError(t, err) for _, test := range tt { t.Run(test.desc, func(t *testing.T) { @@ -206,12 +207,12 @@ func TestWebhookHandler(t *testing.T) { ).Build() set := argosettings.NewSettingsManager(context.TODO(), fakeClient, namespace) h, err := NewWebhookHandler(namespace, set, fc, mockGenerators()) - assert.NoError(t, err) + require.NoError(t, err) req := httptest.NewRequest(http.MethodPost, "/api/webhook", nil) req.Header.Set(test.headerKey, test.headerValue) eventJSON, err := os.ReadFile(filepath.Join("testdata", test.payloadFile)) - assert.NoError(t, err) + require.NoError(t, err) req.Body = io.NopCloser(bytes.NewReader(eventJSON)) w := httptest.NewRecorder() @@ -220,7 +221,7 @@ func TestWebhookHandler(t *testing.T) { list := &v1alpha1.ApplicationSetList{} err = fc.List(context.TODO(), list) - assert.NoError(t, err) + require.NoError(t, err) effectedAppSetsAsExpected := make(map[string]bool) for _, appSetName := range test.effectedAppSets { effectedAppSetsAsExpected[appSetName] = false diff --git a/server/applicationset/applicationset_test.go b/server/applicationset/applicationset_test.go index 031a58cfde62e..da8c980fdd4e5 100644 --- a/server/applicationset/applicationset_test.go +++ b/server/applicationset/applicationset_test.go @@ -7,6 +7,7 @@ import ( "github.com/argoproj/gitops-engine/pkg/health" "github.com/argoproj/pkg/sync" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -221,7 +222,7 @@ func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.Applicat t.Run(validTest.testName, func(t *testing.T) { appsetQuery.Selector = validTest.label res, err := appServer.List(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) apps := []string{} for i := range res.Items { apps = append(apps, res.Items[i].Name) @@ -315,7 +316,7 @@ func TestListAppSetsWithoutNamespace(t *testing.T) { appsetQuery := applicationset.ApplicationSetListQuery{} res, err := appSetServer.List(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, res.Items) } @@ -331,7 +332,7 @@ func TestCreateAppSet(t *testing.T) { Applicationset: testAppSet, } _, err := appServer.Create(context.Background(), &createReq) - assert.NoError(t, err) + require.NoError(t, err) } func TestCreateAppSetTemplatedProject(t *testing.T) { @@ -376,7 +377,7 @@ func TestGetAppSet(t *testing.T) { appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1"} res, err := appSetServer.Get(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "AppSet1", res.Name) }) @@ -386,7 +387,7 @@ func TestGetAppSet(t *testing.T) { appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1", AppsetNamespace: testNamespace} res, err := appSetServer.Get(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "AppSet1", res.Name) }) @@ -419,7 +420,7 @@ func TestDeleteAppSet(t *testing.T) { appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1"} res, err := appSetServer.Delete(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &applicationset.ApplicationSetResponse{}, res) }) @@ -429,7 +430,7 @@ func TestDeleteAppSet(t *testing.T) { appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1", AppsetNamespace: testNamespace} res, err := appSetServer.Delete(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &applicationset.ApplicationSetResponse{}, res) }) } @@ -460,7 +461,7 @@ func TestUpdateAppSet(t *testing.T) { updated, err := appServer.updateAppSet(appSet, newAppSet, context.Background(), true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, map[string]string{ "annotation-key1": "annotation-value1-updated", "annotation-key2": "annotation-value2", @@ -476,7 +477,7 @@ func TestUpdateAppSet(t *testing.T) { updated, err := appServer.updateAppSet(appSet, newAppSet, context.Background(), false) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, map[string]string{ "annotation-key1": "annotation-value1-updated", }, updated.Annotations) @@ -546,7 +547,7 @@ func TestResourceTree(t *testing.T) { appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1"} res, err := appSetServer.ResourceTree(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expectedTree, res) }) @@ -556,7 +557,7 @@ func TestResourceTree(t *testing.T) { appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1", AppsetNamespace: testNamespace} res, err := appSetServer.ResourceTree(context.Background(), &appsetQuery) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expectedTree, res) })