From 33ac61c6008ed096e1ca6bc453b0e6dabaa7c5f6 Mon Sep 17 00:00:00 2001 From: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:08:26 +1200 Subject: [PATCH] fix: golang lint error [BE-11235] (#12215) --- api/http/handler/docker/images/images_list.go | 2 +- .../endpointedge/endpointedge_status_inspect_test.go | 12 ++++++------ api/http/handler/stacks/stack_associate.go | 3 ++- api/http/handler/stacks/stack_delete.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/api/http/handler/docker/images/images_list.go b/api/http/handler/docker/images/images_list.go index 623bd39e1..b9995e5c2 100644 --- a/api/http/handler/docker/images/images_list.go +++ b/api/http/handler/docker/images/images_list.go @@ -78,7 +78,7 @@ func (handler *Handler) imagesList(w http.ResponseWriter, r *http.Request) *http imagesList := make([]ImageResponse, len(images)) for i, image := range images { - if (image.RepoTags == nil || len(image.RepoTags) == 0) && (image.RepoDigests != nil && len(image.RepoDigests) > 0) { + if len(image.RepoTags) == 0 && len(image.RepoDigests) > 0 { for _, repoDigest := range image.RepoDigests { image.RepoTags = append(image.RepoTags, repoDigest[0:strings.Index(repoDigest, "@")]+":") } diff --git a/api/http/handler/endpointedge/endpointedge_status_inspect_test.go b/api/http/handler/endpointedge/endpointedge_status_inspect_test.go index 41b8eb2de..683d0652e 100644 --- a/api/http/handler/endpointedge/endpointedge_status_inspect_test.go +++ b/api/http/handler/endpointedge/endpointedge_status_inspect_test.go @@ -154,7 +154,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) } } @@ -179,7 +179,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) } } } @@ -219,7 +219,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) @@ -262,7 +262,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 @@ -391,7 +391,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..309e07635 100644 --- a/api/http/handler/stacks/stack_associate.go +++ b/api/http/handler/stacks/stack_associate.go @@ -1,6 +1,7 @@ package stacks import ( + "errors" "fmt" "net/http" "time" @@ -95,7 +96,7 @@ func (handler *Handler) stackAssociate(w http.ResponseWriter, r *http.Request) * } if !canManage { errMsg := "Stack management is disabled for non-admin users" - return httperror.Forbidden(errMsg, fmt.Errorf(errMsg)) + 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 ee63f4de7..4c6e94365 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -111,7 +111,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 @@ -338,7 +338,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)