Add some testing

This commit is contained in:
Rodrigo Villablanca 2020-04-12 18:37:22 -04:00
parent 0972c9ba4d
commit ae603b8ef1
2 changed files with 16 additions and 1 deletions

View File

@ -1579,6 +1579,20 @@ func TestDebuggingDisabledHandlers(t *testing.T) {
}
func TestFailedParseParamsSummaryHandler(t *testing.T) {
fw := newServerTest()
defer fw.testHTTPServer.Close()
resp, err := http.Post(fw.testHTTPServer.URL+"/stats/summary", "invalid/content/type", nil)
assert.NoError(t, err)
defer resp.Body.Close()
v, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
assert.Contains(t, string(v), "parse form failed")
}
func TestTrimURLPath(t *testing.T) {
tests := []struct {
path, expected string

View File

@ -26,6 +26,7 @@ import (
restful "github.com/emicklei/go-restful"
cadvisorapi "github.com/google/cadvisor/info/v1"
"github.com/pkg/errors"
"k8s.io/klog"
"k8s.io/api/core/v1"
@ -217,7 +218,7 @@ func (h *handler) handleSummary(request *restful.Request, response *restful.Resp
onlyCPUAndMemory := false
err := request.Request.ParseForm()
if err != nil {
handleError(response, "/stats/summary", err)
handleError(response, "/stats/summary", errors.Wrapf(err, "parse form failed"))
return
}
if onlyCluAndMemoryParam, found := request.Request.Form["only_cpu_and_memory"]; found &&