Merge pull request #4031 from codesome/fix-bug-from-4025

Fix bug from 4025
This commit is contained in:
Björn Rabenstein 2018-03-30 16:41:30 +02:00 committed by GitHub
commit 6cf725c56d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View file

@ -666,7 +666,13 @@ func tmplFuncs(consolesPath string, opts *Options) template_text.FuncMap {
return time.Since(t) / time.Millisecond * time.Millisecond
},
"consolesPath": func() string { return consolesPath },
"pathPrefix": func() string { return opts.RoutePrefix },
"pathPrefix": func() string {
if opts.RoutePrefix == "/" {
return ""
} else {
return opts.RoutePrefix
}
},
"buildVersion": func() string { return opts.Version.Revision },
"stripLabels": func(lset map[string]string, labels ...string) map[string]string {
for _, ln := range labels {

View file

@ -274,6 +274,41 @@ func TestRoutePrefix(t *testing.T) {
testutil.Equals(t, http.StatusOK, resp.StatusCode)
}
func TestPathPrefix(t *testing.T) {
tests := []struct {
routePrefix string
pathPrefix string
}{
{
routePrefix: "/",
// If we have pathPrefix as "/", URL in UI gets "//"" as prefix,
// hence doesn't remain relative path anymore.
pathPrefix: "",
},
{
routePrefix: "/prometheus",
pathPrefix: "/prometheus",
},
{
routePrefix: "/p1/p2/p3/p4",
pathPrefix: "/p1/p2/p3/p4",
},
}
for _, test := range tests {
opts := &Options{
RoutePrefix: test.routePrefix,
}
pathPrefix := tmplFuncs("", opts)["pathPrefix"].(func() string)
pp := pathPrefix()
testutil.Equals(t, test.pathPrefix, pp)
}
}
func TestDebugHandler(t *testing.T) {
for _, tc := range []struct {
prefix, url string