2023-01-27 13:37:20 -08:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-02-24 14:26:08 -08:00
|
|
|
|
|
|
|
|
package main // import "tailscale.com/cmd/tailscaled"
|
|
|
|
|
|
2023-07-20 18:26:52 -07:00
|
|
|
import (
|
2025-11-20 15:52:58 -06:00
|
|
|
"os"
|
|
|
|
|
"strings"
|
2023-07-20 18:26:52 -07:00
|
|
|
"testing"
|
|
|
|
|
|
2025-11-20 15:52:58 -06:00
|
|
|
"tailscale.com/envknob"
|
|
|
|
|
"tailscale.com/ipn"
|
|
|
|
|
"tailscale.com/net/netmon"
|
|
|
|
|
"tailscale.com/tsd"
|
2023-07-20 18:26:52 -07:00
|
|
|
"tailscale.com/tstest/deptest"
|
2025-11-20 15:52:58 -06:00
|
|
|
"tailscale.com/types/logid"
|
|
|
|
|
"tailscale.com/util/must"
|
2023-07-20 18:26:52 -07:00
|
|
|
)
|
2022-02-24 14:26:08 -08:00
|
|
|
|
|
|
|
|
func TestNothing(t *testing.T) {
|
|
|
|
|
// This test does nothing on purpose, so we can run
|
|
|
|
|
// GODEBUG=memprofilerate=1 go test -v -run=Nothing -memprofile=prof.mem
|
|
|
|
|
// without any errors about no matching tests.
|
|
|
|
|
}
|
2023-07-20 18:26:52 -07:00
|
|
|
|
|
|
|
|
func TestDeps(t *testing.T) {
|
|
|
|
|
deptest.DepChecker{
|
|
|
|
|
GOOS: "darwin",
|
|
|
|
|
GOARCH: "arm64",
|
|
|
|
|
BadDeps: map[string]string{
|
2024-05-23 23:13:32 -07:00
|
|
|
"testing": "do not use testing package in production code",
|
2023-07-20 20:36:12 -07:00
|
|
|
"gvisor.dev/gvisor/pkg/hostarch": "will crash on non-4K page sizes; see https://github.com/tailscale/tailscale/issues/8658",
|
2025-01-26 17:06:06 +00:00
|
|
|
"net/http/httptest": "do not use httptest in production code",
|
|
|
|
|
"net/http/internal/testcert": "do not use httptest in production code",
|
2023-07-20 18:26:52 -07:00
|
|
|
},
|
|
|
|
|
}.Check(t)
|
|
|
|
|
|
|
|
|
|
deptest.DepChecker{
|
2023-07-20 20:36:12 -07:00
|
|
|
GOOS: "linux",
|
|
|
|
|
GOARCH: "arm64",
|
2023-07-20 18:26:52 -07:00
|
|
|
BadDeps: map[string]string{
|
2025-01-15 13:43:36 -08:00
|
|
|
"testing": "do not use testing package in production code",
|
|
|
|
|
"gvisor.dev/gvisor/pkg/hostarch": "will crash on non-4K page sizes; see https://github.com/tailscale/tailscale/issues/8658",
|
|
|
|
|
"google.golang.org/protobuf/proto": "unexpected",
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus": "use tailscale.com/metrics in tailscaled",
|
2023-07-20 18:26:52 -07:00
|
|
|
},
|
|
|
|
|
}.Check(t)
|
|
|
|
|
}
|
2025-11-20 15:52:58 -06:00
|
|
|
|
|
|
|
|
func TestStateStoreError(t *testing.T) {
|
|
|
|
|
logID, err := logid.NewPrivateID()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
// Don't upload any logs from tests.
|
|
|
|
|
envknob.SetNoLogsNoSupport()
|
|
|
|
|
|
|
|
|
|
args.statedir = t.TempDir()
|
|
|
|
|
args.tunname = "userspace-networking"
|
|
|
|
|
|
|
|
|
|
t.Run("new state", func(t *testing.T) {
|
|
|
|
|
sys := tsd.NewSystem()
|
|
|
|
|
sys.NetMon.Set(must.Get(netmon.New(sys.Bus.Get(), t.Logf)))
|
|
|
|
|
lb, err := getLocalBackend(t.Context(), t.Logf, logID.Public(), sys)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer lb.Shutdown()
|
|
|
|
|
if lb.HealthTracker().IsUnhealthy(ipn.StateStoreHealth) {
|
|
|
|
|
t.Errorf("StateStoreHealth is unhealthy on fresh LocalBackend:\n%s", strings.Join(lb.HealthTracker().Strings(), "\n"))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
t.Run("corrupt state", func(t *testing.T) {
|
|
|
|
|
sys := tsd.NewSystem()
|
|
|
|
|
sys.NetMon.Set(must.Get(netmon.New(sys.Bus.Get(), t.Logf)))
|
|
|
|
|
// Populate the state file with something that will fail to parse to
|
|
|
|
|
// trigger an error from store.New.
|
|
|
|
|
if err := os.WriteFile(statePathOrDefault(), []byte("bad json"), 0644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
lb, err := getLocalBackend(t.Context(), t.Logf, logID.Public(), sys)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer lb.Shutdown()
|
|
|
|
|
if !lb.HealthTracker().IsUnhealthy(ipn.StateStoreHealth) {
|
|
|
|
|
t.Errorf("StateStoreHealth is healthy when state file is corrupt")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|