refactor: no error pages must return nil.
This commit is contained in:
parent
2cb4acd6cc
commit
987e8a93bd
2 changed files with 10 additions and 1 deletions
|
@ -267,7 +267,7 @@ func ExtractServicePropertiesP(labels *map[string]string) ServiceProperties {
|
||||||
|
|
||||||
// ParseErrorPages parse error pages to create ErrorPage struct
|
// ParseErrorPages parse error pages to create ErrorPage struct
|
||||||
func ParseErrorPages(labels map[string]string, labelPrefix string, labelRegex *regexp.Regexp) map[string]*types.ErrorPage {
|
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 {
|
for lblName, value := range labels {
|
||||||
if strings.HasPrefix(lblName, labelPrefix) {
|
if strings.HasPrefix(lblName, labelPrefix) {
|
||||||
|
@ -277,6 +277,10 @@ func ParseErrorPages(labels map[string]string, labelPrefix string, labelRegex *r
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errorPages == nil {
|
||||||
|
errorPages = make(map[string]*types.ErrorPage)
|
||||||
|
}
|
||||||
|
|
||||||
pageName := submatch[1]
|
pageName := submatch[1]
|
||||||
|
|
||||||
ep, ok := errorPages[pageName]
|
ep, ok := errorPages[pageName]
|
||||||
|
|
|
@ -1070,6 +1070,11 @@ func TestParseErrorPages(t *testing.T) {
|
||||||
},
|
},
|
||||||
expected: map[string]*types.ErrorPage{"foo": {}},
|
expected: map[string]*types.ErrorPage{"foo": {}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "no error pages labels",
|
||||||
|
labels: map[string]string{},
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue