From 0b37b677c16143725fb84fb9e6d677a9b244f699 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 28 Aug 2024 15:03:15 +0200 Subject: [PATCH] refactor: fix linting issues across the codebase (#12152) --- .../endpointedge/endpointedge_status_inspect_test.go | 12 ++++++------ api/http/handler/stacks/stack_associate.go | 5 +++-- api/http/handler/stacks/stack_delete.go | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/api/http/handler/endpointedge/endpointedge_status_inspect_test.go b/api/http/handler/endpointedge/endpointedge_status_inspect_test.go index b173446e7..2b9be5722 100644 --- a/api/http/handler/endpointedge/endpointedge_status_inspect_test.go +++ b/api/http/handler/endpointedge/endpointedge_status_inspect_test.go @@ -152,7 +152,7 @@ func TestMissingEdgeIdentifier(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != http.StatusForbidden { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d without Edge identifier", http.StatusForbidden, rec.Code)) + t.Fatalf("expected a %d response, found: %d without Edge identifier", http.StatusForbidden, rec.Code) } } @@ -177,7 +177,7 @@ func TestWithEndpoints(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != test.expectedStatusCode { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d for endpoint ID: %d", test.expectedStatusCode, rec.Code, test.endpoint.ID)) + t.Fatalf("expected a %d response, found: %d for endpoint ID: %d", test.expectedStatusCode, rec.Code, test.endpoint.ID) } } } @@ -217,7 +217,7 @@ func TestLastCheckInDateIncreases(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d", http.StatusOK, rec.Code)) + t.Fatalf("expected a %d response, found: %d", http.StatusOK, rec.Code) } updatedEndpoint, err := handler.DataStore.Endpoint().Endpoint(endpoint.ID) @@ -260,7 +260,7 @@ func TestEmptyEdgeIdWithAgentPlatformHeader(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d with empty edge ID", http.StatusOK, rec.Code)) + t.Fatalf("expected a %d response, found: %d with empty edge ID", http.StatusOK, rec.Code) } updatedEndpoint, err := handler.DataStore.Endpoint().Endpoint(endpoint.ID) @@ -326,7 +326,7 @@ func TestEdgeStackStatus(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d", http.StatusOK, rec.Code)) + t.Fatalf("expected a %d response, found: %d", http.StatusOK, rec.Code) } var data endpointEdgeStatusInspectResponse @@ -390,7 +390,7 @@ func TestEdgeJobsResponse(t *testing.T) { handler.ServeHTTP(rec, req) if rec.Code != http.StatusOK { - t.Fatalf(fmt.Sprintf("expected a %d response, found: %d", http.StatusOK, rec.Code)) + t.Fatalf("expected a %d response, found: %d", http.StatusOK, rec.Code) } var data endpointEdgeStatusInspectResponse diff --git a/api/http/handler/stacks/stack_associate.go b/api/http/handler/stacks/stack_associate.go index 5eaaae726..7f4165bc8 100644 --- a/api/http/handler/stacks/stack_associate.go +++ b/api/http/handler/stacks/stack_associate.go @@ -5,6 +5,7 @@ import ( "net/http" "time" + "github.com/pkg/errors" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/http/security" "github.com/portainer/portainer/api/stacks/stackutils" @@ -94,8 +95,8 @@ func (handler *Handler) stackAssociate(w http.ResponseWriter, r *http.Request) * return httperror.InternalServerError("Unable to verify user authorizations to validate stack deletion", err) } if !canManage { - errMsg := "Stack management is disabled for non-admin users" - return httperror.Forbidden(errMsg, fmt.Errorf(errMsg)) + errMsg := "stack management is disabled for non-admin users" + return httperror.Forbidden(errMsg, errors.New(errMsg)) } stack.EndpointID = portainer.EndpointID(endpointID) diff --git a/api/http/handler/stacks/stack_delete.go b/api/http/handler/stacks/stack_delete.go index 82933f516..09a38f4e7 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -109,7 +109,7 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt } if !canManage { errMsg := "stack deletion is disabled for non-admin users" - return httperror.Forbidden(errMsg, fmt.Errorf(errMsg)) + return httperror.Forbidden(errMsg, errors.New(errMsg)) } // stop scheduler updates of the stack before removal @@ -307,7 +307,7 @@ func (handler *Handler) stackDeleteKubernetesByName(w http.ResponseWriter, r *ht } if !canManage { errMsg := "stack deletion is disabled for non-admin users" - return httperror.Forbidden(errMsg, fmt.Errorf(errMsg)) + return httperror.Forbidden(errMsg, errors.New(errMsg)) } stacksToDelete = append(stacksToDelete, stack)