From 866c338fab2335d908ca92b7ae79052b79cf49d7 Mon Sep 17 00:00:00 2001 From: Atanas Alexandrov Date: Thu, 3 Oct 2024 14:56:50 +0200 Subject: [PATCH] Fix bad smells This PR contains two small changes: 1. Error comparison with equality operator can fails on wrapped errors. It is better to use errors.Is instead. 2. %V is unknown verb, it should be lowercase '%v' Signed-off-by: Atanas Alexandrov --- pkg/virtual/framework/forwardingregistry/rest_test.go | 6 +++--- test/e2e/fixtures/webhook/webhook.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/virtual/framework/forwardingregistry/rest_test.go b/pkg/virtual/framework/forwardingregistry/rest_test.go index f76629b1d14..078ca406b1d 100644 --- a/pkg/virtual/framework/forwardingregistry/rest_test.go +++ b/pkg/virtual/framework/forwardingregistry/rest_test.go @@ -160,7 +160,7 @@ func TestGet(t *testing.T) { result, err := getter.Get(ctx, "foo", &metav1.GetOptions{}) require.NoError(t, err) - require.Truef(t, apiequality.Semantic.DeepEqual(resource, result), "expected:\n%V\nactual:\n%V", resource, result) + require.Truef(t, apiequality.Semantic.DeepEqual(resource, result), "expected:\n%v\nactual:\n%v", resource, result) } func TestList(t *testing.T) { @@ -178,7 +178,7 @@ func TestList(t *testing.T) { require.Len(t, resultResources, len(resources)) for i, resource := range resources { resource := *resource.(*unstructured.Unstructured) - require.Truef(t, apiequality.Semantic.DeepEqual(resource, resultResources[i]), "expected:\n%V\nactual:\n%V", resource, resultResources[0]) + require.Truef(t, apiequality.Semantic.DeepEqual(resource, resultResources[i]), "expected:\n%v\nactual:\n%v", resource, resultResources[0]) } require.Len(t, fakeClient.Actions(), 1) require.Equal(t, "noxus", fakeClient.Actions()[0].GetResource().Resource) @@ -209,7 +209,7 @@ func TestWildcardListWithAPIExportIdentity(t *testing.T) { require.Len(t, resultResources, len(resources)) for i, resource := range resources { resource := *resource.(*unstructured.Unstructured) - require.Truef(t, apiequality.Semantic.DeepEqual(resource, resultResources[i]), "expected:\n%V\nactual:\n%V", resource, resultResources[0]) + require.Truef(t, apiequality.Semantic.DeepEqual(resource, resultResources[i]), "expected:\n%v\nactual:\n%v", resource, resultResources[0]) } require.Len(t, fakeClient.Actions(), 1) require.Equal(t, "noxus:apiExportIdentityHash", fakeClient.Actions()[0].GetResource().Resource) diff --git a/test/e2e/fixtures/webhook/webhook.go b/test/e2e/fixtures/webhook/webhook.go index 0e44bbe530a..915dd83f8ac 100644 --- a/test/e2e/fixtures/webhook/webhook.go +++ b/test/e2e/fixtures/webhook/webhook.go @@ -19,6 +19,7 @@ package webhook import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -59,7 +60,7 @@ func (s *AdmissionWebhookServer) StartTLS(t *testing.T, certFile, keyFile string go func() { err := serv.ListenAndServeTLS(certFile, keyFile) - if err != nil && err != http.ErrServerClosed { + if err != nil && !errors.Is(err, http.ErrServerClosed) { t.Logf("unable to shutdown server gracefully err: %v", err) } }()