refactor: no error pages must return nil.

This commit is contained in:
Fernandez Ludovic 2017-12-21 17:10:22 +01:00 committed by Traefiker
parent 2cb4acd6cc
commit 987e8a93bd
2 changed files with 10 additions and 1 deletions

View file

@ -267,7 +267,7 @@ func ExtractServicePropertiesP(labels *map[string]string) ServiceProperties {
// ParseErrorPages parse error pages to create ErrorPage struct
func ParseErrorPages(labels map[string]string, labelPrefix string, labelRegex *regexp.Regexp) map[string]*types.ErrorPage {
errorPages := make(map[string]*types.ErrorPage)
var errorPages map[string]*types.ErrorPage
for lblName, value := range labels {
if strings.HasPrefix(lblName, labelPrefix) {
@ -277,6 +277,10 @@ func ParseErrorPages(labels map[string]string, labelPrefix string, labelRegex *r
continue
}
if errorPages == nil {
errorPages = make(map[string]*types.ErrorPage)
}
pageName := submatch[1]
ep, ok := errorPages[pageName]

View file

@ -1070,6 +1070,11 @@ func TestParseErrorPages(t *testing.T) {
},
expected: map[string]*types.ErrorPage{"foo": {}},
},
{
desc: "no error pages labels",
labels: map[string]string{},
expected: nil,
},
}
for _, test := range testCases {