app/vmauth: properly initialize URLPrefix in tests

It is assumed that URLPrefix.busOriginal will be initialized
durin Unmarshal of the config. But in tests we set fields manually,
so this field never get initialized properly.

Fixes the error `panic: runtime error: integer divide by zero`
at `vmauth.getLeastLoadedBackendURL`.

Signed-off-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit cb1e618a16)
This commit is contained in:
hagen1778 2024-03-08 21:10:11 +01:00
parent 86abbe5b67
commit 67efc174a8
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640

View file

@ -701,6 +701,7 @@ func mustParseURL(u string) *URLPrefix {
func mustParseURLs(us []string) *URLPrefix {
bus := make([]*backendURL, len(us))
urls := make([]*url.URL, len(us))
for i, u := range us {
pu, err := url.Parse(u)
if err != nil {
@ -709,6 +710,7 @@ func mustParseURLs(us []string) *URLPrefix {
bus[i] = &backendURL{
url: pu,
}
urls[i] = pu
}
up := &URLPrefix{}
if len(us) == 1 {
@ -717,6 +719,7 @@ func mustParseURLs(us []string) *URLPrefix {
up.vOriginal = us
}
up.bus.Store(&bus)
up.busOriginal = urls
return up
}