fix: resolve PR2514 lint regressions
This commit is contained in:
parent
93bf871bd2
commit
ae195831bb
5 changed files with 69 additions and 13 deletions
|
|
@ -43,7 +43,13 @@ func TestResolveGatewayHostOverride(t *testing.T) {
|
|||
{name: "implicit empty host is allowed", explicit: false, host: "", wantHost: "", wantErr: false},
|
||||
{name: "explicit empty host rejected", explicit: true, host: " ", wantHost: "", wantErr: true},
|
||||
{name: "explicit localhost kept", explicit: true, host: " localhost ", wantHost: "localhost", wantErr: false},
|
||||
{name: "explicit multi host normalized", explicit: true, host: " [::1] , 127.0.0.1 ", wantHost: "::1,127.0.0.1", wantErr: false},
|
||||
{
|
||||
name: "explicit multi host normalized",
|
||||
explicit: true,
|
||||
host: " [::1] , 127.0.0.1 ",
|
||||
wantHost: "::1,127.0.0.1",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ func setupAndStartServices(
|
|||
runningServices.authToken = authToken
|
||||
runningServices.HealthServer = health.NewServer(listenResult.ProbeHost, cfg.Gateway.Port, authToken)
|
||||
|
||||
listenAddr := ""
|
||||
var listenAddr string
|
||||
if len(listenResult.Listeners) > 0 {
|
||||
listenAddr = listenResult.Listeners[0].Addr().String()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -506,8 +506,14 @@ func openGroup(group bindGroup, port string) ([]net.Listener, []string, string,
|
|||
|
||||
func openAdaptiveLoopbackGroup(allowIPv6, allowIPv4 bool, port string) ([]net.Listener, []string, string, error) {
|
||||
if allowIPv6 && allowIPv4 {
|
||||
if ln6, actualPort, err6 := openExactListener(exactBinding{host: "::1", network: "tcp6", v6Only: true}, port); err6 == nil {
|
||||
if ln4, _, err4 := openExactListener(exactBinding{host: "127.0.0.1", network: "tcp4"}, actualPort); err4 == nil {
|
||||
if ln6, actualPort, err6 := openExactListener(
|
||||
exactBinding{host: "::1", network: "tcp6", v6Only: true},
|
||||
port,
|
||||
); err6 == nil {
|
||||
if ln4, _, err4 := openExactListener(
|
||||
exactBinding{host: "127.0.0.1", network: "tcp4"},
|
||||
actualPort,
|
||||
); err4 == nil {
|
||||
return []net.Listener{ln6, ln4}, []string{"::1", "127.0.0.1"}, actualPort, nil
|
||||
}
|
||||
_ = ln6.Close()
|
||||
|
|
|
|||
|
|
@ -216,7 +216,8 @@ func startGatewayAndCaptureEnv(t *testing.T, h *Handler) gatewayStartEnvSnapshot
|
|||
raw, err := os.ReadFile(envPath)
|
||||
if err == nil {
|
||||
var snapshot gatewayStartEnvSnapshot
|
||||
if err := json.Unmarshal(raw, &snapshot); err != nil {
|
||||
err = json.Unmarshal(raw, &snapshot)
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal(child env) error = %v", err)
|
||||
}
|
||||
return snapshot
|
||||
|
|
|
|||
|
|
@ -51,9 +51,21 @@ func TestDashboardTokenConfigHelpPath(t *testing.T) {
|
|||
source launcherconfig.DashboardTokenSource
|
||||
want string
|
||||
}{
|
||||
{name: "env token does not expose config path", source: launcherconfig.DashboardTokenSourceEnv, want: ""},
|
||||
{name: "config token exposes config path", source: launcherconfig.DashboardTokenSourceConfig, want: launcherPath},
|
||||
{name: "random token does not expose config path", source: launcherconfig.DashboardTokenSourceRandom, want: ""},
|
||||
{
|
||||
name: "env token does not expose config path",
|
||||
source: launcherconfig.DashboardTokenSourceEnv,
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "config token exposes config path",
|
||||
source: launcherconfig.DashboardTokenSourceConfig,
|
||||
want: launcherPath,
|
||||
},
|
||||
{
|
||||
name: "random token does not expose config path",
|
||||
source: launcherconfig.DashboardTokenSourceRandom,
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -98,7 +110,14 @@ func TestResolveLauncherHostInput(t *testing.T) {
|
|||
wantActive bool
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "flag host wins", flagHost: "127.0.0.1", explicitFlag: true, envHost: "::", wantHost: "127.0.0.1", wantActive: true},
|
||||
{
|
||||
name: "flag host wins",
|
||||
flagHost: "127.0.0.1",
|
||||
explicitFlag: true,
|
||||
envHost: "::",
|
||||
wantHost: "127.0.0.1",
|
||||
wantActive: true,
|
||||
},
|
||||
{name: "env host used when flag absent", envHost: "127.0.0.1,::1", wantHost: "127.0.0.1,::1", wantActive: true},
|
||||
{name: "blank env ignored", envHost: " ", wantHost: "", wantActive: false},
|
||||
{name: "invalid flag rejected", flagHost: "127.0.0.1, ", explicitFlag: true, wantErr: true},
|
||||
|
|
@ -230,10 +249,34 @@ func TestWildcardAdvertiseIP(t *testing.T) {
|
|||
ipv6 string
|
||||
want string
|
||||
}{
|
||||
{name: "ipv4 wildcard prefers ipv6 when available", bindHosts: []string{"0.0.0.0"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: "2001:db8::1"},
|
||||
{name: "ipv6 wildcard uses ipv6", bindHosts: []string{"::"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: "2001:db8::1"},
|
||||
{name: "ipv6 wildcard falls back to ipv4", bindHosts: []string{"::"}, ipv4: "192.168.1.2", ipv6: "", want: "192.168.1.2"},
|
||||
{name: "non wildcard does not advertise", bindHosts: []string{"127.0.0.1"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: ""},
|
||||
{
|
||||
name: "ipv4 wildcard prefers ipv6 when available",
|
||||
bindHosts: []string{"0.0.0.0"},
|
||||
ipv4: "192.168.1.2",
|
||||
ipv6: "2001:db8::1",
|
||||
want: "2001:db8::1",
|
||||
},
|
||||
{
|
||||
name: "ipv6 wildcard uses ipv6",
|
||||
bindHosts: []string{"::"},
|
||||
ipv4: "192.168.1.2",
|
||||
ipv6: "2001:db8::1",
|
||||
want: "2001:db8::1",
|
||||
},
|
||||
{
|
||||
name: "ipv6 wildcard falls back to ipv4",
|
||||
bindHosts: []string{"::"},
|
||||
ipv4: "192.168.1.2",
|
||||
ipv6: "",
|
||||
want: "192.168.1.2",
|
||||
},
|
||||
{
|
||||
name: "non wildcard does not advertise",
|
||||
bindHosts: []string{"127.0.0.1"},
|
||||
ipv4: "192.168.1.2",
|
||||
ipv6: "2001:db8::1",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue