From 67efc174a86dd1f8988d5d53ae735b1b9bd845a4 Mon Sep 17 00:00:00 2001 From: hagen1778 Date: Fri, 8 Mar 2024 21:10:11 +0100 Subject: [PATCH] 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 (cherry picked from commit cb1e618a165fddf33b51370f629e6c41ddfd6fa1) --- app/vmauth/auth_config_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/vmauth/auth_config_test.go b/app/vmauth/auth_config_test.go index 00965ddab..2c717ad4f 100644 --- a/app/vmauth/auth_config_test.go +++ b/app/vmauth/auth_config_test.go @@ -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 }