fixup! cmd/tailscale: get command for printing settings

TestGetDefaultSettings needs to start its own LocalBackend so it isn’t
talking to a running tailscaled.

Signed-off-by: Simon Law <sfllaw@sfllaw.ca>
This commit is contained in:
Simon Law 2025-03-17 12:27:31 -07:00
parent 25995745c9
commit ebdf466f6d
No known key found for this signature in database
GPG Key ID: C535BDB0FBAD9164

View File

@ -10,13 +10,10 @@ import (
"io" "io"
"net" "net"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strconv"
"testing" "testing"
"tailscale.com/client/local" "tailscale.com/client/local"
"tailscale.com/clientupdate"
"tailscale.com/ipn/ipnlocal" "tailscale.com/ipn/ipnlocal"
"tailscale.com/ipn/ipnserver" "tailscale.com/ipn/ipnserver"
"tailscale.com/ipn/store/mem" "tailscale.com/ipn/store/mem"
@ -135,19 +132,27 @@ func TestGetDefaultSettings(t *testing.T) {
var stdout bytes.Buffer var stdout bytes.Buffer
tstest.Replace[io.Writer](t, &Stdout, &stdout) tstest.Replace[io.Writer](t, &Stdout, &stdout)
// Use a fake localClient that processes settings updates
lc := newLocalClient(t)
tstest.Replace(t, &localClient, lc)
if err := runGet(t.Context(), []string{f.Name}); err != nil { if err := runGet(t.Context(), []string{f.Name}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
var want string want := f.DefValue
switch f.Name { switch f.Name {
case "accept-routes":
// ipn.NewPrefs sets this to true
// but tailscale up sets it on start.
want = "true"
case "auto-update": case "auto-update":
want = strconv.FormatBool(clientupdate.CanAutoUpdate()) // Unset by tailscale up.
case "operator": want = "unset"
// applyImplicitPrefs will set the default operator to the current user case "login-server":
want = os.Getenv("USER") // The default settings is empty,
default: // but tailscale up sets it on start.
want = f.DefValue want = ""
} }
want += "\n" want += "\n"