envknob: make Setenv update RegisterInt knobs

Setenv refreshes the cached values behind RegisterString, RegisterBool,
RegisterOptBool and RegisterDuration, but had no case for RegisterInt.
An int knob kept its old value after Setenv, even though RegisterInt's
doc says mutations happen via Setenv.

Add the missing case and a test.

Fixes #21530

Change-Id: I3213c68a22619c0dd334b00f6eaa1e260ee20827
Signed-off-by: Jeremy Schoemaker <[email protected]>
This commit is contained in:
Jeremy Schoemaker authored and Brad Fitzpatrick committed 2026-11-27 21:30:54 -08:00
1 parent 091ebe8543
commit d486755fb9
2 files changed
+21

No files matched your search

+3
View File
@@ -109,6 +109,9 @@ func Setenv(envVar, val string) {
if p := regDuration[envVar]; p != nil {
setDurationLocked(p, envVar, val)
}
if p := regInt[envVar]; p != nil {
setIntLocked(p, envVar, val)
}
}
// SetenvForTest safely changes an environment variable in a test.
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package envknob
import "testing"
func TestSetenvRegisterInt(t *testing.T) {
const envVar = "TS_ENVKNOB_TEST_REGISTER_INT"
get := RegisterInt(envVar)
if got := get(); got != 0 {
t.Fatalf("initial value = %d; want 0", got)
}
SetenvForTest(t, envVar, "42")
if got := get(); got != 42 {
t.Errorf("value after Setenv = %d; want 42", got)
}
}