envknob: add GOOS func

Centralize the fake GOOS stuff, start to use it more. To be used more
in the future.

Change-Id: Iabacfbeaf5fca0b53bf4d5dbcdc0367f05a205f9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/6481/head
Brad Fitzpatrick 2 years ago committed by Brad Fitzpatrick
parent 6e6f27dd21
commit 4d3713f631

@ -274,12 +274,7 @@ func statePathOrDefault() string {
} }
func ipnServerOpts() (o ipnserver.Options) { func ipnServerOpts() (o ipnserver.Options) {
// Allow changing the OS-specific IPN behavior for tests goos := envknob.GOOS()
// so we can e.g. test Windows-specific behaviors on Linux.
goos := envknob.String("TS_DEBUG_TAILSCALED_IPN_GOOS")
if goos == "" {
goos = runtime.GOOS
}
o.VarRoot = args.statedir o.VarRoot = args.statedir

@ -277,11 +277,9 @@ func SSHPolicyFile() string { return String("TS_DEBUG_SSH_POLICY_FILE") }
// SSHIgnoreTailnetPolicy is whether to ignore the Tailnet SSH policy for development. // SSHIgnoreTailnetPolicy is whether to ignore the Tailnet SSH policy for development.
func SSHIgnoreTailnetPolicy() bool { return Bool("TS_DEBUG_SSH_IGNORE_TAILNET_POLICY") } func SSHIgnoreTailnetPolicy() bool { return Bool("TS_DEBUG_SSH_IGNORE_TAILNET_POLICY") }
// TKASkipSignatureCheck is whether to skip node-key signature checking for development. // TKASkipSignatureCheck is whether to skip node-key signature checking for development.
func TKASkipSignatureCheck() bool { return Bool("TS_UNSAFE_SKIP_NKS_VERIFICATION") } func TKASkipSignatureCheck() bool { return Bool("TS_UNSAFE_SKIP_NKS_VERIFICATION") }
// NoLogsNoSupport reports whether the client's opted out of log uploads and // NoLogsNoSupport reports whether the client's opted out of log uploads and
// technical support. // technical support.
func NoLogsNoSupport() bool { func NoLogsNoSupport() bool {

@ -0,0 +1,17 @@
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ts_not_in_tests
package envknob
import "runtime"
func GOOS() string {
// When the "ts_not_in_tests" build tag is used, we define this func to just
// return a simple constant so callers optimize just as if the knob were not
// present. We can then build production/optimized builds with the
// "ts_not_in_tests" build tag.
return runtime.GOOS
}

@ -0,0 +1,24 @@
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !ts_not_in_tests
package envknob
import "runtime"
// GOOS reports the effective runtime.GOOS to run as.
//
// In practice this returns just runtime.GOOS, unless overridden by
// test TS_DEBUG_FAKE_GOOS.
//
// This allows changing OS-specific stuff like the IPN server behavior
// for tests so we can e.g. test Windows-specific behaviors on Linux.
// This isn't universally used.
func GOOS() string {
if v := String("TS_DEBUG_FAKE_GOOS"); v != "" {
return v
}
return runtime.GOOS
}

@ -13,6 +13,7 @@ import (
"time" "time"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"tailscale.com/envknob"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/logger" "tailscale.com/types/logger"
@ -423,7 +424,7 @@ func ReadStartupPrefsForTest(logf logger.Logf, store ipn.StateStore) (ipn.PrefsV
// It also loads the list of known profiles from the StateStore. // It also loads the list of known profiles from the StateStore.
// If a state key is provided, it will be used to load the current profile. // If a state key is provided, it will be used to load the current profile.
func newProfileManager(store ipn.StateStore, logf logger.Logf, stateKey ipn.StateKey) (*profileManager, error) { func newProfileManager(store ipn.StateStore, logf logger.Logf, stateKey ipn.StateKey) (*profileManager, error) {
return newProfileManagerWithGOOS(store, logf, stateKey, runtime.GOOS) return newProfileManagerWithGOOS(store, logf, stateKey, envknob.GOOS())
} }
func readAutoStartKey(store ipn.StateStore, goos string) (ipn.StateKey, error) { func readAutoStartKey(store ipn.StateStore, goos string) (ipn.StateKey, error) {

@ -809,7 +809,7 @@ func (n *testNode) StartDaemonAsIPNGOOS(ipnGOOS string) *Daemon {
"TS_LOG_TARGET="+n.env.LogCatcherServer.URL, "TS_LOG_TARGET="+n.env.LogCatcherServer.URL,
"HTTP_PROXY="+n.env.TrafficTrapServer.URL, "HTTP_PROXY="+n.env.TrafficTrapServer.URL,
"HTTPS_PROXY="+n.env.TrafficTrapServer.URL, "HTTPS_PROXY="+n.env.TrafficTrapServer.URL,
"TS_DEBUG_TAILSCALED_IPN_GOOS="+ipnGOOS, "TS_DEBUG_FAKE_GOOS="+ipnGOOS,
"TS_LOGS_DIR="+t.TempDir(), "TS_LOGS_DIR="+t.TempDir(),
"TS_NETCHECK_GENERATE_204_URL="+n.env.ControlServer.URL+"/generate_204", "TS_NETCHECK_GENERATE_204_URL="+n.env.ControlServer.URL+"/generate_204",
) )

Loading…
Cancel
Save