diff --git a/net/wsconn/wsconn_test.go b/net/wsconn/wsconn_test.go new file mode 100644 index 000000000..fbfcb8e23 --- /dev/null +++ b/net/wsconn/wsconn_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package wsconn + +import "testing" + +func TestNetConn(t *testing.T) { + // Basic package test + _ = "wsconn" +} diff --git a/omit/omit_test.go b/omit/omit_test.go new file mode 100644 index 000000000..efaf7462b --- /dev/null +++ b/omit/omit_test.go @@ -0,0 +1,12 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package omit + +import "testing" + +func TestErr(t *testing.T) { + if Err == nil { + t.Error("omit.Err is nil") + } +} diff --git a/paths/paths_test.go b/paths/paths_test.go new file mode 100644 index 000000000..e45e75973 --- /dev/null +++ b/paths/paths_test.go @@ -0,0 +1,23 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package paths + +import ( + "runtime" + "testing" +) + +func TestDefaultTailscaledSocket(t *testing.T) { + path := DefaultTailscaledSocket() + if path == "" { + t.Error("DefaultTailscaledSocket() returned empty") + } +} + +func TestStateFile(t *testing.T) { + path := StateFile() + if path == "" && runtime.GOOS != "js" { + t.Error("StateFile() returned empty") + } +} diff --git a/proxymap/proxymap_test.go b/proxymap/proxymap_test.go new file mode 100644 index 000000000..339cb7de6 --- /dev/null +++ b/proxymap/proxymap_test.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package proxymap + +import "testing" + +func TestProxyMap(t *testing.T) { + pm := &ProxyMap{} + if pm == nil { + t.Fatal("ProxyMap is nil") + } +} diff --git a/sessionrecording/sessionrecording_test.go b/sessionrecording/sessionrecording_test.go new file mode 100644 index 000000000..c516cb004 --- /dev/null +++ b/sessionrecording/sessionrecording_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package sessionrecording + +import "testing" + +func TestRecorder(t *testing.T) { + // Basic test that package loads + _ = "sessionrecording" +} diff --git a/tsconst/tsconst_test.go b/tsconst/tsconst_test.go new file mode 100644 index 000000000..84fcb23bc --- /dev/null +++ b/tsconst/tsconst_test.go @@ -0,0 +1,12 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package tsconst + +import "testing" + +func TestDerpHostname(t *testing.T) { + if DerpHostname == "" { + t.Error("DerpHostname is empty") + } +} diff --git a/tsd/tsd_test.go b/tsd/tsd_test.go new file mode 100644 index 000000000..642f9c58f --- /dev/null +++ b/tsd/tsd_test.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package tsd + +import "testing" + +func TestSystem(t *testing.T) { + s := &System{} + if s == nil { + t.Fatal("System is nil") + } +} diff --git a/types/empty/empty_test.go b/types/empty/empty_test.go new file mode 100644 index 000000000..b90da2f91 --- /dev/null +++ b/types/empty/empty_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package empty + +import "testing" + +func TestMessage(t *testing.T) { + var m Message + _ = m +} diff --git a/types/flagtype/flagtype_test.go b/types/flagtype/flagtype_test.go new file mode 100644 index 000000000..10e516e96 --- /dev/null +++ b/types/flagtype/flagtype_test.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package flagtype + +import "testing" + +func TestHTTPFlag(t *testing.T) { + var f HTTPFlag + if err := f.Set("http://example.com"); err != nil { + t.Fatalf("Set() failed: %v", err) + } +} diff --git a/types/nettype/nettype_test.go b/types/nettype/nettype_test.go new file mode 100644 index 000000000..b8a9d5f29 --- /dev/null +++ b/types/nettype/nettype_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package nettype + +import "testing" + +func TestPacketConn(t *testing.T) { + var pc PacketConn + _ = pc +} diff --git a/types/preftype/preftype_test.go b/types/preftype/preftype_test.go new file mode 100644 index 000000000..bcaca57d4 --- /dev/null +++ b/types/preftype/preftype_test.go @@ -0,0 +1,20 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package preftype + +import "testing" + +func TestNetfilterMode(t *testing.T) { + modes := []NetfilterMode{ + NetfilterOff, + NetfilterOn, + NetfilterNoDivert, + } + for _, m := range modes { + s := m.String() + if s == "" { + t.Errorf("NetfilterMode(%d).String() is empty", m) + } + } +} diff --git a/types/ptr/ptr_test.go b/types/ptr/ptr_test.go new file mode 100644 index 000000000..b9129f2df --- /dev/null +++ b/types/ptr/ptr_test.go @@ -0,0 +1,17 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package ptr + +import "testing" + +func TestTo(t *testing.T) { + i := 42 + p := To(i) + if p == nil { + t.Fatal("To() returned nil") + } + if *p != 42 { + t.Errorf("*To(42) = %d, want 42", *p) + } +} diff --git a/types/structs/structs_test.go b/types/structs/structs_test.go new file mode 100644 index 000000000..797755826 --- /dev/null +++ b/types/structs/structs_test.go @@ -0,0 +1,22 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package structs + +import "testing" + +func TestContainsPointers(t *testing.T) { + type hasPtr struct { + p *int + } + if !ContainsPointers[hasPtr]() { + t.Error("ContainsPointers for struct with pointer returned false") + } + + type noPtr struct { + i int + } + if ContainsPointers[noPtr]() { + t.Error("ContainsPointers for struct without pointer returned true") + } +} diff --git a/util/cibuild/cibuild_test.go b/util/cibuild/cibuild_test.go new file mode 100644 index 000000000..899d29402 --- /dev/null +++ b/util/cibuild/cibuild_test.go @@ -0,0 +1,10 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package cibuild + +import "testing" + +func TestRunningInCI(t *testing.T) { + _ = RunningInCI() +} diff --git a/util/groupmember/groupmember_test.go b/util/groupmember/groupmember_test.go new file mode 100644 index 000000000..1220ad97b --- /dev/null +++ b/util/groupmember/groupmember_test.go @@ -0,0 +1,12 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package groupmember + +import "testing" + +func TestIsMemberOfGroup(t *testing.T) { + // This will likely fail/return false on most systems but shouldn't panic + _, err := IsMemberOfGroup("root", "root") + _ = err // May error, that's ok +} diff --git a/util/lineread/lineread_test.go b/util/lineread/lineread_test.go new file mode 100644 index 000000000..5e04d7c5f --- /dev/null +++ b/util/lineread/lineread_test.go @@ -0,0 +1,24 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package lineread + +import ( + "strings" + "testing" +) + +func TestReader(t *testing.T) { + r := strings.NewReader("line1\nline2\nline3\n") + var lines []string + if err := Reader(r, func(line []byte) error { + lines = append(lines, string(line)) + return nil + }); err != nil { + t.Fatalf("Reader() failed: %v", err) + } + + if len(lines) != 3 { + t.Errorf("got %d lines, want 3", len(lines)) + } +} diff --git a/util/must/must_test.go b/util/must/must_test.go new file mode 100644 index 000000000..1c69ce582 --- /dev/null +++ b/util/must/must_test.go @@ -0,0 +1,25 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package must + +import "testing" + +func TestGet(t *testing.T) { + val := Get(42, nil) + if val != 42 { + t.Errorf("Get(42, nil) = %d, want 42", val) + } +} + +func TestGetPanic(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Error("Get with error did not panic") + } + }() + Get(0, error(nil)) + Get(0, (*error)(nil)) + type testError struct{} + Get(0, testError{}) +} diff --git a/util/osshare/osshare_test.go b/util/osshare/osshare_test.go new file mode 100644 index 000000000..3c7782ffe --- /dev/null +++ b/util/osshare/osshare_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package osshare + +import "testing" + +func TestSetFileSharingEnabled(t *testing.T) { + // Basic test - may not be supported on all platforms + _ = SetFileSharingEnabled(false) +} diff --git a/util/precompress/precompress_test.go b/util/precompress/precompress_test.go new file mode 100644 index 000000000..a974208dc --- /dev/null +++ b/util/precompress/precompress_test.go @@ -0,0 +1,14 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package precompress + +import "testing" + +func TestPrecompress(t *testing.T) { + data := []byte("test data") + result := Precompress(data) + if len(result) == 0 { + t.Error("Precompress returned empty") + } +} diff --git a/util/progresstracking/progresstracking_test.go b/util/progresstracking/progresstracking_test.go new file mode 100644 index 000000000..cac1d57f3 --- /dev/null +++ b/util/progresstracking/progresstracking_test.go @@ -0,0 +1,13 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package progresstracking + +import "testing" + +func TestTracker(t *testing.T) { + tracker := &Tracker{} + if tracker == nil { + t.Fatal("Tracker is nil") + } +} diff --git a/util/quarantine/quarantine_test.go b/util/quarantine/quarantine_test.go new file mode 100644 index 000000000..65c39cb40 --- /dev/null +++ b/util/quarantine/quarantine_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package quarantine + +import "testing" + +func TestSetOnFile(t *testing.T) { + // Basic test + _ = "quarantine" +} diff --git a/util/racebuild/racebuild_test.go b/util/racebuild/racebuild_test.go new file mode 100644 index 000000000..94e72a7b5 --- /dev/null +++ b/util/racebuild/racebuild_test.go @@ -0,0 +1,10 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package racebuild + +import "testing" + +func TestOn(t *testing.T) { + _ = On +} diff --git a/util/systemd/systemd_test.go b/util/systemd/systemd_test.go new file mode 100644 index 000000000..80aaafb31 --- /dev/null +++ b/util/systemd/systemd_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package systemd + +import "testing" + +func TestIsReady(t *testing.T) { + // Just verify it doesn't panic + _ = Ready() +} diff --git a/wf/wf_test.go b/wf/wf_test.go new file mode 100644 index 000000000..f94b14cb9 --- /dev/null +++ b/wf/wf_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package wf + +import "testing" + +func TestWireGuardFirewall(t *testing.T) { + // Basic test + _ = "wf" +} diff --git a/wgengine/wgcfg/nmcfg/nmcfg_test.go b/wgengine/wgcfg/nmcfg/nmcfg_test.go new file mode 100644 index 000000000..5c900bcce --- /dev/null +++ b/wgengine/wgcfg/nmcfg/nmcfg_test.go @@ -0,0 +1,11 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +package nmcfg + +import "testing" + +func TestWGCfg(t *testing.T) { + // Basic test + _ = "nmcfg" +}