hunk.code_window: 	if err != nil {
   		log.Debug().Err(err).Msg("unable to fetch metrics: leaving metrics collection disabled.")
   		return
   	}
   	endpoint.Kubernetes.Configuration.UseServerMetrics = true
   	endpoint.Kubernetes.Flags.IsServerMetricsDetected = true
   	err = endpointService.UpdateEndpoint(
   		portainer.EndpointID(endpoint.ID),
   		endpoint,
   	)
   	if err != nil {
   		log.Debug().Err(err).Msg("unable to enable UseServerMetrics inside the database")
   		return
   	}
   }
  
hunk.labels: keep keep keep keep keep replace replace replace replace replace keep keep keep keep keep
hunk.file_path: api/internal/endpointutils/endpointutils.go
hunk.type: replace
file: package helm
  
  import (
  	"fmt"
  	"io"
  	"net/http"
  	"net/http/httptest"
  	"net/url"
  	"testing"
  
  	helper "github.com/portainer/portainer/api/internal/testhelpers"
  	"github.com/portainer/portainer/pkg/libhelm/binary/test"
  	"github.com/stretchr/testify/assert"
  )
  
  func Test_helmRepoSearch(t *testing.T) {
  	is := assert.New(t)
  
  	helmPackageManager := test.NewMockHelmBinaryPackageManager("")
  	h := NewTemplateHandler(helper.NewTestRequestBouncer(), helmPackageManager)
  
  	assert.NotNil(t, h, "Handler should not fail")
  
  	repos := []string{"https://charts.bitnami.com/bitnami", "https://portainer.github.io/k8s"}
  
  	for _, repo := range repos {
  		t.Run(repo, func(t *testing.T) {
  			repoUrlEncoded := url.QueryEscape(repo)
  			req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/templates/helm?repo=%s", repoUrlEncoded), nil)
  			rr := httptest.NewRecorder()
  			h.ServeHTTP(rr, req)
  
  			is.Equal(http.StatusOK, rr.Code, "Status should be 200 OK")
  
  			body, err := io.ReadAll(rr.Body)
  			is.NoError(err, "ReadAll should not return error")
  			is.NotEmpty(body, "Body should not be empty")
  		})
  	}
  
  	t.Run("fails on invalid URL", func(t *testing.T) {
  		repo := "abc.com"
  		repoUrlEncoded := url.QueryEscape(repo)
  		req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/templates/helm?repo=%s", repoUrlEncoded), nil)
  		rr := httptest.NewRecorder()
  		h.ServeHTTP(rr, req)
  
  		is.Equal(http.StatusBadRequest, rr.Code, "Status should be 400 Bad request")
  	})
  }
  