diff --git a/applicationset/controllers/applicationset_controller_test.go b/applicationset/controllers/applicationset_controller_test.go index b33465a679caa..781d3ad3a838e 100644 --- a/applicationset/controllers/applicationset_controller_test.go +++ b/applicationset/controllers/applicationset_controller_test.go @@ -1178,18 +1178,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") - require.NoError(t, err, "Unexpected error") + require.NoErrorf(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) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") // App on the cluster should have the expected finalizers assert.ElementsMatch(t, c.expectedFinalizers, retrievedApp.Finalizers) @@ -1334,18 +1334,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") - require.NoError(t, err, "Unexpected error") + require.NoErrorf(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) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") finalizerRemoved := len(retrievedApp.Finalizers) == 0 @@ -1402,7 +1402,7 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { } err := controllerutil.SetControllerReference(&appSet, &app, scheme) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") initObjs := []crtclient.Object{&app, &appSet} @@ -1418,11 +1418,11 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) { } err = r.removeOwnerReferencesOnDeleteAppSet(context.Background(), appSet) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") retrievedApp := v1alpha1.Application{} err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp) - require.NoError(t, err, "Unexpected error") + require.NoErrorf(t, err, "Unexpected error") ownerReferencesRemoved := len(retrievedApp.OwnerReferences) == 0 assert.True(t, ownerReferencesRemoved) @@ -2092,16 +2092,16 @@ func TestValidateGeneratedApplications(t *testing.T) { } if len(errorMessages) == 0 { - assert.Empty(t, cc.expectedErrors, "Expected errors but none were seen") + assert.Emptyf(t, cc.expectedErrors, "Expected errors but none were seen") } else { // An error was returned: it should be expected matched := false for _, expectedErr := range cc.expectedErrors { foundMatch := strings.Contains(strings.Join(errorMessages, ";"), expectedErr) - assert.True(t, foundMatch, "Unble to locate expected error: %s", cc.expectedErrors) + assert.Truef(t, foundMatch, "Unble to locate expected error: %s", cc.expectedErrors) matched = matched || foundMatch } - assert.True(t, matched, "An unexpected error occurrred: %v", err) + assert.Truef(t, matched, "An unexpected error occurrred: %v", err) // validation message was returned: it should be expected matched = false foundMatch := reflect.DeepEqual(validationErrors, cc.validationErrors) @@ -2110,9 +2110,9 @@ func TestValidateGeneratedApplications(t *testing.T) { message = v.Error() break } - assert.True(t, foundMatch, "Unble to locate validation message: %s", message) + assert.Truef(t, foundMatch, "Unble to locate validation message: %s", message) matched = matched || foundMatch - assert.True(t, matched, "An unexpected error occurrred: %v", err) + assert.Truef(t, matched, "An unexpected error occurrred: %v", err) } }) } @@ -2294,7 +2294,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) { } } - assert.False(t, isProgressingCondition, "no RolloutProgressing should be set for applicationsets that don't have rolling strategy") + assert.Falsef(t, isProgressingCondition, "no RolloutProgressing should be set for applicationsets that don't have rolling strategy") }, }, { @@ -2357,7 +2357,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) { } } - assert.True(t, isProgressingCondition, "RolloutProgressing should be set for rollout strategy appset") + assert.Truef(t, isProgressingCondition, "RolloutProgressing should be set for rollout strategy appset") }, }, } @@ -3727,8 +3727,8 @@ func TestBuildAppDependencyList(t *testing.T) { } appDependencyList, appStepMap := r.buildAppDependencyList(log.NewEntry(log.StandardLogger()), cc.appSet, cc.apps) - assert.Equal(t, cc.expectedList, appDependencyList, "expected appDependencyList did not match actual") - assert.Equal(t, cc.expectedStepMap, appStepMap, "expected appStepMap did not match actual") + assert.Equalf(t, cc.expectedList, appDependencyList, "expected appDependencyList did not match actual") + assert.Equalf(t, cc.expectedStepMap, appStepMap, "expected appStepMap did not match actual") }) } } @@ -4394,7 +4394,7 @@ func TestBuildAppSyncMap(t *testing.T) { } appSyncMap := r.buildAppSyncMap(cc.appSet, cc.appDependencyList, cc.appMap) - assert.Equal(t, cc.expectedMap, appSyncMap, "expected appSyncMap did not match actual") + assert.Equalf(t, cc.expectedMap, appSyncMap, "expected appSyncMap did not match actual") }) } } @@ -5348,8 +5348,8 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { appStatuses[i].LastTransitionTime = nil } - require.NoError(t, err, "expected no errors, but errors occurred") - assert.Equal(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") + require.NoErrorf(t, err, "expected no errors, but errors occurred") + assert.Equalf(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") }) } } @@ -6097,8 +6097,8 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) { appStatuses[i].LastTransitionTime = nil } - require.NoError(t, err, "expected no errors, but errors occurred") - assert.Equal(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") + require.NoErrorf(t, err, "expected no errors, but errors occurred") + assert.Equalf(t, cc.expectedAppStatus, appStatuses, "expected appStatuses did not match actual") }) } } @@ -6303,8 +6303,8 @@ func TestUpdateResourceStatus(t *testing.T) { err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps) - 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") + require.NoErrorf(t, err, "expected no errors, but errors occurred") + assert.Equalf(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual") }) } } @@ -6392,15 +6392,15 @@ func TestResourceStatusAreOrdered(t *testing.T) { } err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps) - require.NoError(t, err, "expected no errors, but errors occurred") + require.NoErrorf(t, err, "expected no errors, but errors occurred") err = r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps) - require.NoError(t, err, "expected no errors, but errors occurred") + require.NoErrorf(t, err, "expected no errors, but errors occurred") err = r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps) - require.NoError(t, err, "expected no errors, but errors occurred") + require.NoErrorf(t, err, "expected no errors, but errors occurred") - assert.Equal(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual") + assert.Equalf(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual") }) } } diff --git a/applicationset/generators/pull_request_test.go b/applicationset/generators/pull_request_test.go index d4eae1602bfda..1bbb78ce7753c 100644 --- a/applicationset/generators/pull_request_test.go +++ b/applicationset/generators/pull_request_test.go @@ -298,7 +298,7 @@ func TestAllowedSCMProviderPullRequest(t *testing.T) { _, err := pullRequestGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, nil) - require.Error(t, err, "Must return an error") + require.Errorf(t, err, "Must return an error") var expectedError ErrDisallowedSCMProvider assert.ErrorAs(t, err, &expectedError) }) diff --git a/applicationset/generators/scm_provider_test.go b/applicationset/generators/scm_provider_test.go index a52f7e8159b86..ce4ab5466f674 100644 --- a/applicationset/generators/scm_provider_test.go +++ b/applicationset/generators/scm_provider_test.go @@ -211,7 +211,7 @@ func TestAllowedSCMProvider(t *testing.T) { _, err := scmGenerator.GenerateParams(&applicationSetInfo.Spec.Generators[0], &applicationSetInfo, nil) - require.Error(t, err, "Must return an error") + require.Errorf(t, err, "Must return an error") var expectedError ErrDisallowedSCMProvider assert.ErrorAs(t, err, &expectedError) }) diff --git a/applicationset/services/internal/http/client_test.go b/applicationset/services/internal/http/client_test.go index 83d304835c70a..ab80dcfbc2bfe 100644 --- a/applicationset/services/internal/http/client_test.go +++ b/applicationset/services/internal/http/client_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestClient(t *testing.T) { @@ -24,9 +25,7 @@ func TestClient(t *testing.T) { var clientOptionFns []ClientOptionFunc _, err := NewClient(server.URL, clientOptionFns...) - if err != nil { - t.Fatalf("Failed to create client: %v", err) - } + require.NoErrorf(t, err, "Failed to create client: %v", err) } func TestClientDo(t *testing.T) { @@ -118,14 +117,10 @@ func TestClientDo(t *testing.T) { defer cc.fakeServer.Close() client, err := NewClient(cc.fakeServer.URL, cc.clientOptionFns...) - if err != nil { - t.Fatalf("NewClient returned unexpected error: %v", err) - } + require.NoErrorf(t, err, "NewClient returned unexpected error: %v", err) req, err := client.NewRequest("POST", "", cc.params, nil) - if err != nil { - t.Fatalf("NewRequest returned unexpected error: %v", err) - } + require.NoErrorf(t, err, "NewRequest returned unexpected error: %v", err) var data []map[string]interface{} @@ -149,12 +144,8 @@ func TestCheckResponse(t *testing.T) { } err := CheckResponse(resp) - if err == nil { - t.Error("Expected an error, got nil") - } + require.Errorf(t, err, "Expected an error, got nil") expected := "API error with status code 400: invalid_request" - if err.Error() != expected { - t.Errorf("Expected error '%s', got '%s'", expected, err.Error()) - } + assert.Equalf(t, expected, err.Error(), "Expected error '%s', got '%s'", expected, err.Error()) } diff --git a/applicationset/services/plugin/plugin_service_test.go b/applicationset/services/plugin/plugin_service_test.go index 75e7f2c4a095f..8505662b64a6f 100644 --- a/applicationset/services/plugin/plugin_service_test.go +++ b/applicationset/services/plugin/plugin_service_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestPlugin(t *testing.T) { @@ -31,19 +32,13 @@ func TestPlugin(t *testing.T) { defer ts.Close() client, err := NewPluginService(context.Background(), "plugin-test", ts.URL, token, 0) - if err != nil { - t.Errorf("unexpected error: %v", err) - } + require.NoErrorf(t, err, "unexpected error: %v", err) data, err := client.List(context.Background(), nil) - if err != nil { - t.Errorf("unexpected error: %v", err) - } + require.NoErrorf(t, err, "unexpected error: %v", err) var expectedData ServiceResponse err = json.Unmarshal([]byte(expectedJSON), &expectedData) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) assert.Equal(t, &expectedData, data) } diff --git a/applicationset/services/pull_request/bitbucket_server_test.go b/applicationset/services/pull_request/bitbucket_server_test.go index b9da370830fc0..4f6f839a2e161 100644 --- a/applicationset/services/pull_request/bitbucket_server_test.go +++ b/applicationset/services/pull_request/bitbucket_server_test.go @@ -281,7 +281,7 @@ func TestListPullRequestTLS(t *testing.T) { for _, cert := range ts.TLS.Certificates { for _, c := range cert.Certificate { parsedCert, err := x509.ParseCertificate(c) - require.NoError(t, err, "Failed to parse certificate") + require.NoErrorf(t, err, "Failed to parse certificate") certs = append(certs, pem.EncodeToMemory(&pem.Block{ Type: "CERTIFICATE", Bytes: parsedCert.Raw, diff --git a/applicationset/services/pull_request/github_test.go b/applicationset/services/pull_request/github_test.go index 30b908f9fb1b6..1f977a9789712 100644 --- a/applicationset/services/pull_request/github_test.go +++ b/applicationset/services/pull_request/github_test.go @@ -52,9 +52,8 @@ func TestContainLabels(t *testing.T) { for _, c := range cases { t.Run(c.Name, func(t *testing.T) { - if got := containLabels(c.Labels, c.PullLabels); got != c.Expect { - t.Errorf("expect: %v, got: %v", c.Expect, got) - } + got := containLabels(c.Labels, c.PullLabels) + assert.Equalf(t, got, c.Expect, "expect: %v, got: %v", c.Expect, got) }) } } diff --git a/applicationset/services/pull_request/gitlab_test.go b/applicationset/services/pull_request/gitlab_test.go index 9abb8d73ea491..5082940600218 100644 --- a/applicationset/services/pull_request/gitlab_test.go +++ b/applicationset/services/pull_request/gitlab_test.go @@ -17,13 +17,10 @@ import ( func writeMRListResponse(t *testing.T, w io.Writer) { t.Helper() f, err := os.Open("fixtures/gitlab_mr_list_response.json") - if err != nil { - t.Fatalf("error opening fixture file: %v", err) - } + require.NoErrorf(t, err, "error opening fixture file: %v", err) - if _, err = io.Copy(w, f); err != nil { - t.Fatalf("error writing response: %v", err) - } + _, err = io.Copy(w, f) + require.NoErrorf(t, err, "error writing response: %v", err) } func TestGitLabServiceCustomBaseURL(t *testing.T) { @@ -174,7 +171,7 @@ func TestListWithStateTLS(t *testing.T) { for _, cert := range ts.TLS.Certificates { for _, c := range cert.Certificate { parsedCert, err := x509.ParseCertificate(c) - require.NoError(t, err, "Failed to parse certificate") + require.NoErrorf(t, err, "Failed to parse certificate") certs = append(certs, pem.EncodeToMemory(&pem.Block{ Type: "CERTIFICATE", Bytes: parsedCert.Raw, diff --git a/applicationset/services/scm_provider/aws_codecommit_test.go b/applicationset/services/scm_provider/aws_codecommit_test.go index 00d8240973848..5cf2eb8c00079 100644 --- a/applicationset/services/scm_provider/aws_codecommit_test.go +++ b/applicationset/services/scm_provider/aws_codecommit_test.go @@ -227,7 +227,7 @@ func TestAWSCodeCommitListRepos(t *testing.T) { assert.Equal(t, originRepo.id, repo.RepositoryId) assert.Equal(t, originRepo.defaultBranch, repo.Branch) assert.Equal(t, originRepo.expectedCloneUrl, repo.URL) - assert.Empty(t, repo.SHA, "SHA is always empty") + assert.Emptyf(t, repo.SHA, "SHA is always empty") } } }) diff --git a/applicationset/services/scm_provider/azure_devops_test.go b/applicationset/services/scm_provider/azure_devops_test.go index d718802ad3295..69425300bd789 100644 --- a/applicationset/services/scm_provider/azure_devops_test.go +++ b/applicationset/services/scm_provider/azure_devops_test.go @@ -487,7 +487,7 @@ func TestGetAzureDevopsRepositories(t *testing.T) { repositories, err := provider.ListRepos(ctx, "https") if testCase.getRepositoriesError != nil { - require.Error(t, err, "Expected an error from test case %v", testCase.name) + require.Errorf(t, err, "Expected an error from test case %v", testCase.name) } if testCase.expectedNumberOfRepos == 0 { diff --git a/applicationset/services/scm_provider/bitbucket_server_test.go b/applicationset/services/scm_provider/bitbucket_server_test.go index 5b4a957fea1ab..51d5191c20a5d 100644 --- a/applicationset/services/scm_provider/bitbucket_server_test.go +++ b/applicationset/services/scm_provider/bitbucket_server_test.go @@ -460,7 +460,7 @@ func TestListReposTLS(t *testing.T) { for _, cert := range ts.TLS.Certificates { for _, c := range cert.Certificate { parsedCert, err := x509.ParseCertificate(c) - require.NoError(t, err, "Failed to parse certificate") + require.NoErrorf(t, err, "Failed to parse certificate") certs = append(certs, pem.EncodeToMemory(&pem.Block{ Type: "CERTIFICATE", Bytes: parsedCert.Raw, diff --git a/applicationset/services/scm_provider/gitlab_test.go b/applicationset/services/scm_provider/gitlab_test.go index 4443086333ccb..548b09a74bdeb 100644 --- a/applicationset/services/scm_provider/gitlab_test.go +++ b/applicationset/services/scm_provider/gitlab_test.go @@ -1277,7 +1277,7 @@ func TestGetBranchesTLS(t *testing.T) { for _, cert := range ts.TLS.Certificates { for _, c := range cert.Certificate { parsedCert, err := x509.ParseCertificate(c) - require.NoError(t, err, "Failed to parse certificate") + require.NoErrorf(t, err, "Failed to parse certificate") certs = append(certs, pem.EncodeToMemory(&pem.Block{ Type: "CERTIFICATE", Bytes: parsedCert.Raw, diff --git a/applicationset/utils/clusterUtils_test.go b/applicationset/utils/clusterUtils_test.go index fdc316fbc428c..8e3a6b553e286 100644 --- a/applicationset/utils/clusterUtils_test.go +++ b/applicationset/utils/clusterUtils_test.go @@ -122,7 +122,7 @@ func TestValidateDestination(t *testing.T) { } err := ValidateDestination(context.Background(), &dest, nil, fakeNamespace) - assert.Equal(t, "application destination can't have both name and server defined: minikube https://127.0.0.1:6443", err.Error()) + require.EqualError(t, err, "application destination can't have both name and server defined: minikube https://127.0.0.1:6443") assert.False(t, dest.IsServerInferred()) }) @@ -137,7 +137,7 @@ func TestValidateDestination(t *testing.T) { }) err := ValidateDestination(context.Background(), &dest, kubeclientset, fakeNamespace) - assert.Equal(t, "unable to find destination server: an error occurred", err.Error()) + require.EqualError(t, err, "unable to find destination server: an error occurred") assert.False(t, dest.IsServerInferred()) }) @@ -152,7 +152,7 @@ func TestValidateDestination(t *testing.T) { kubeclientset := fake.NewSimpleClientset(objects...) err := ValidateDestination(context.Background(), &dest, kubeclientset, fakeNamespace) - assert.Equal(t, "unable to find destination server: there are no clusters with this name: minikube", err.Error()) + require.EqualError(t, err, "unable to find destination server: there are no clusters with this name: minikube") assert.False(t, dest.IsServerInferred()) }) @@ -169,7 +169,7 @@ func TestValidateDestination(t *testing.T) { kubeclientset := fake.NewSimpleClientset(objects...) err := ValidateDestination(context.Background(), &dest, kubeclientset, fakeNamespace) - assert.Equal(t, "unable to find destination server: there are 2 clusters with the same name: [https://127.0.0.1:2443 https://127.0.0.1:8443]", err.Error()) + require.EqualError(t, err, "unable to find destination server: there are 2 clusters with the same name: [https://127.0.0.1:2443 https://127.0.0.1:8443]") assert.False(t, dest.IsServerInferred()) }) } diff --git a/applicationset/utils/createOrUpdate_test.go b/applicationset/utils/createOrUpdate_test.go index 2dc5945d2d2cc..efb6e538f2dce 100644 --- a/applicationset/utils/createOrUpdate_test.go +++ b/applicationset/utils/createOrUpdate_test.go @@ -219,10 +219,10 @@ spec: t.Parallel() foundApp := v1alpha1.Application{TypeMeta: appMeta} err := yaml.Unmarshal([]byte(tc.foundApp), &foundApp) - require.NoError(t, err, tc.foundApp) + require.NoErrorf(t, err, tc.foundApp) generatedApp := v1alpha1.Application{TypeMeta: appMeta} err = yaml.Unmarshal([]byte(tc.generatedApp), &generatedApp) - require.NoError(t, err, tc.generatedApp) + require.NoErrorf(t, err, tc.generatedApp) err = applyIgnoreDifferences(tc.ignoreDifferences, &foundApp, &generatedApp, normalizers.IgnoreNormalizerOpts{}) require.NoError(t, err) yamlFound, err := yaml.Marshal(tc.foundApp) diff --git a/applicationset/utils/utils_test.go b/applicationset/utils/utils_test.go index 8d19a2cffa260..4cc9744d80b77 100644 --- a/applicationset/utils/utils_test.go +++ b/applicationset/utils/utils_test.go @@ -179,7 +179,7 @@ func TestRenderTemplateParams(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 actualValue := *getPtrFunc(newApplication) - assert.Equal(t, test.expectedVal, actualValue, "Field '%s' had an unexpected value. expected: '%s' value: '%s'", fieldName, test.expectedVal, actualValue) + assert.Equalf(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"]) assert.Equal(t, "annotation-value2", newApplication.ObjectMeta.Annotations["annotation-key2"]) assert.Equal(t, "label-value", newApplication.ObjectMeta.Labels["label-key"]) @@ -622,11 +622,11 @@ func TestRenderTemplateParamsGoTemplate(t *testing.T) { // the target field has been templated into the expected value if test.errorMessage != "" { require.Error(t, err) - assert.Equal(t, test.errorMessage, err.Error()) + assert.EqualError(t, err, test.errorMessage) } else { 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.Equalf(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"]) assert.Equal(t, "annotation-value2", newApplication.ObjectMeta.Annotations["annotation-key2"]) assert.Equal(t, "label-value", newApplication.ObjectMeta.Labels["label-key"]) @@ -912,11 +912,11 @@ func TestCheckInvalidGenerators(t *testing.T) { hook := logtest.NewGlobal() _ = CheckInvalidGenerators(&c.appSet) - assert.GreaterOrEqual(t, len(hook.Entries), 1, c.testName) - assert.NotNil(t, hook.LastEntry(), c.testName) + assert.GreaterOrEqualf(t, len(hook.Entries), 1, c.testName) + assert.NotNilf(t, hook.LastEntry(), c.testName) if hook.LastEntry() != nil { - assert.Equal(t, logrus.WarnLevel, hook.LastEntry().Level, c.testName) - assert.Equal(t, c.expectedMsg, hook.LastEntry().Message, c.testName) + assert.Equalf(t, logrus.WarnLevel, hook.LastEntry().Level, c.testName) + assert.Equalf(t, c.expectedMsg, hook.LastEntry().Message, c.testName) } hook.Reset() } @@ -1190,8 +1190,8 @@ func TestInvalidGenerators(t *testing.T) { }, } { hasInvalid, names := invalidGenerators(&c.appSet) - assert.Equal(t, c.expectedInvalid, hasInvalid, c.testName) - assert.Equal(t, c.expectedNames, names, c.testName) + assert.Equalf(t, c.expectedInvalid, hasInvalid, c.testName) + assert.Equalf(t, c.expectedNames, names, c.testName) } } @@ -1218,7 +1218,7 @@ func TestNormalizeBitbucketBasePath(t *testing.T) { }, } { result := NormalizeBitbucketBasePath(c.basePath) - assert.Equal(t, c.expectedBasePath, result, c.testName) + assert.Equalf(t, c.expectedBasePath, result, c.testName) } } @@ -1255,7 +1255,7 @@ func TestSlugify(t *testing.T) { }, } { result := SlugifyName(c.length, c.smartTruncate, c.branch) - assert.Equal(t, c.expectedBasePath, result, c.branch) + assert.Equalf(t, c.expectedBasePath, result, c.branch) } } diff --git a/applicationset/webhook/webhook_test.go b/applicationset/webhook/webhook_test.go index 046bbf35f09ab..ed470d132385c 100644 --- a/applicationset/webhook/webhook_test.go +++ b/applicationset/webhook/webhook_test.go @@ -242,16 +242,15 @@ func TestWebhookHandler(t *testing.T) { for i := range list.Items { gotAppSet := &list.Items[i] if _, isEffected := effectedAppSetsAsExpected[gotAppSet.Name]; isEffected { - if expected, got := test.expectedRefresh, gotAppSet.RefreshRequired(); expected != got { - t.Errorf("unexpected RefreshRequired() for appset '%s' expect: %v got: %v", gotAppSet.Name, expected, got) - } + expected, got := test.expectedRefresh, gotAppSet.RefreshRequired() + assert.Equalf(t, expected, got, "unexpected RefreshRequired() for appset '%s' expect: %v got: %v", gotAppSet.Name, expected, got) effectedAppSetsAsExpected[gotAppSet.Name] = true } else { assert.False(t, gotAppSet.RefreshRequired()) } } for appSetName, checked := range effectedAppSetsAsExpected { - assert.True(t, checked, "appset %s not found", appSetName) + assert.Truef(t, checked, "appset %s not found", appSetName) } }) }