Thanks to visit codestin.com
Credit goes to pkg.go.dev

integration

package
v2.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2025 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const EchoPort = 2381

Variables

View Source
var Client1 = Client{
	Number:         ClientNumber1,
	ID:             uuid.MustParse("00000000-0000-0000-0000-000000000001"),
	ListenPort:     client1Port,
	ShouldRunTests: true,
	TunnelSrc:      true,
}
View Source
var Client2 = Client{
	Number:         ClientNumber2,
	ID:             uuid.MustParse("00000000-0000-0000-0000-000000000002"),
	ListenPort:     client2Port,
	ShouldRunTests: false,
	TunnelSrc:      false,
}

Functions

func ExecBackground added in v2.12.0

func ExecBackground(t *testing.T, processName string, netNS *os.File, name string, args []string) (<-chan error, func() error)

ExecBackground starts a subprocess with the given flags and returns a channel that will receive the error when the subprocess exits. The returned function can be used to close the subprocess.

processName is used to identify the subprocess in logs.

Optionally, a network namespace can be passed to run the subprocess in.

Do not call close then wait on the channel. Use the returned value from the function instead in this case.

Cleanup is handled automatically if you don't care about monitoring the process manually.

func TestBigUDP added in v2.24.0

func TestBigUDP(t *testing.T, logger slog.Logger, _ *url.URL, conn *tailnet.Conn, _, peer Client)

func TestSuite added in v2.12.0

func TestSuite(t *testing.T, _ slog.Logger, serverURL *url.URL, conn *tailnet.Conn, _, peer Client)

TODO: instead of reusing one conn for each suite, maybe we should make a new one for each subtest?

Types

type BasicClientStarter added in v2.24.0

type BasicClientStarter struct {
	BlockEndpoints      bool
	DERPForceWebsockets bool
	// WaitForConnection means wait for (any) peer connection before returning from StartClient
	WaitForConnection bool
	// WaitForConnection means wait for a direct peer connection before returning from StartClient
	WaitForDirect bool
	// Service is a network service (e.g. an echo server) to start on the client. If Wait* is set, the service is
	// started prior to waiting.
	Service    NetworkService
	LogPackets bool
}

func (BasicClientStarter) StartClient added in v2.24.0

func (b BasicClientStarter) StartClient(t *testing.T, logger slog.Logger, serverURL *url.URL, derpMap *tailcfg.DERPMap, me, peer Client) *tailnet.Conn

type Client added in v2.12.0

type Client struct {
	Number         ClientNumber
	ID             uuid.UUID
	ListenPort     uint16
	ShouldRunTests bool
	TunnelSrc      bool
}

type ClientNumber added in v2.12.0

type ClientNumber int
const (
	ClientNumber1 ClientNumber = 1
	ClientNumber2 ClientNumber = 2
)

type ClientStarter added in v2.12.0

type ClientStarter interface {
	StartClient(t *testing.T, logger slog.Logger, serverURL *url.URL, derpMap *tailcfg.DERPMap, me Client, peer Client) *tailnet.Conn
}

type NGINXServerOptions added in v2.12.0

type NGINXServerOptions struct {
	SimpleServerOptions
}

func (NGINXServerOptions) StartServer added in v2.12.0

func (o NGINXServerOptions) StartServer(t *testing.T, logger slog.Logger, listenAddr string)

type NetworkService added in v2.24.0

type NetworkService interface {
	StartService(t *testing.T, logger slog.Logger, conn *tailnet.Conn)
}

type NetworkingLoopback added in v2.24.0

type NetworkingLoopback struct{}

NetworkingLoopback creates a network namespace with a loopback interface for all tests to share. This is the simplest networking setup. The network namespace only exists for isolation on the host and doesn't serve any routing purpose.

func (NetworkingLoopback) SetupNetworking added in v2.24.0

func (NetworkingLoopback) SetupNetworking(t *testing.T, _ slog.Logger) TestNetworking

type NetworkingNAT added in v2.24.0

type NetworkingNAT struct {
	StunCount   int
	Client1Hard bool
	Client2Hard bool
}

NetworkingNAT creates a fake internet and sets up "NAT" forwarding rules, either easy or hard. See createFakeInternet. NAT is achieved through a single iptables masquerade rule.

func (NetworkingNAT) SetupNetworking added in v2.24.0

func (n NetworkingNAT) SetupNetworking(t *testing.T, l slog.Logger) TestNetworking

SetupNetworking creates a fake internet with multiple STUN servers and sets up NAT forwarding rules. Client NATs are controlled by the switches ClientXHard, which if true, sets up hard nat.

type NetworkingProvider added in v2.24.0

type NetworkingProvider interface {
	// SetupNetworking creates interfaces and network namespaces for the test.
	// The most simple implementation is NetworkSetupDefault, which only creates
	// a network namespace shared for all tests.
	SetupNetworking(t *testing.T, logger slog.Logger) TestNetworking
}

type ServerStarter added in v2.12.0

type ServerStarter interface {
	// StartServer should start the server and return once it's listening. It
	// should not block once it's listening. Cleanup should be handled by
	// t.Cleanup.
	StartServer(t *testing.T, logger slog.Logger, listenAddr string)
}

type SimpleServerOptions added in v2.12.0

type SimpleServerOptions struct {
	// FailUpgradeDERP will make the DERP server fail to handle the initial DERP
	// upgrade in a way that causes the client to fallback to
	// DERP-over-WebSocket fallback automatically.
	// Incompatible with DERPWebsocketOnly.
	FailUpgradeDERP bool
	// DERPWebsocketOnly will make the DERP server only accept WebSocket
	// connections. If a DERP request is received that is not using WebSocket
	// fallback, the test will fail.
	// Incompatible with FailUpgradeDERP.
	DERPWebsocketOnly bool
}

func (SimpleServerOptions) Router added in v2.12.0

func (o SimpleServerOptions) Router(t *testing.T, logger slog.Logger) *chi.Mux

func (SimpleServerOptions) StartServer added in v2.12.0

func (o SimpleServerOptions) StartServer(t *testing.T, logger slog.Logger, listenAddr string)

type TestNetworking

type TestNetworking struct {
	Server  TestNetworkingServer
	STUNs   []TestNetworkingSTUN
	Client1 TestNetworkingClient
	Client2 TestNetworkingClient
}

type TestNetworkingClient added in v2.12.0

type TestNetworkingClient struct {
	Process TestNetworkingProcess
	// ServerAccessURL is the hostname and port that the client uses to access
	// the server over HTTP for coordination.
	ServerAccessURL string
	// DERPMap is the DERP map that the client uses. If nil, a basic DERP map
	// containing only a single DERP with `ServerAccessURL` is used with no
	// STUN servers.
	DERPMap *tailcfg.DERPMap
}

func (TestNetworkingClient) ResolveDERPMap added in v2.12.0

func (c TestNetworkingClient) ResolveDERPMap() (*tailcfg.DERPMap, error)

type TestNetworkingProcess

type TestNetworkingProcess struct {
	// NetNS to enter. If nil, the current network namespace is used.
	NetNS *os.File
}

func (TestNetworkingProcess) CapturePackets added in v2.24.0

func (p TestNetworkingProcess) CapturePackets(t *testing.T, name, dir string)

type TestNetworkingSTUN added in v2.12.0

type TestNetworkingSTUN struct {
	Process    TestNetworkingProcess
	IP         string
	ListenAddr string
}

type TestNetworkingServer added in v2.12.0

type TestNetworkingServer struct {
	Process    TestNetworkingProcess
	ListenAddr string
}

type TestTopology

type TestTopology struct {
	Name string

	NetworkingProvider NetworkingProvider

	// Server is the server starter for the test. It is executed in the server
	// subprocess.
	Server ServerStarter
	// ClientStarter.StartClient gets called in each client subprocess. It's expected to
	// create the tailnet.Conn and ensure connectivity to it's peer.
	ClientStarter ClientStarter

	// RunTests is the main test function. It's called in each of the client
	// subprocesses. If tests can only run once, they should check the client ID
	// and return early if it's not the expected one.
	RunTests func(t *testing.T, logger slog.Logger, serverURL *url.URL, conn *tailnet.Conn, me Client, peer Client)
}

type TriangleNetwork added in v2.24.0

type TriangleNetwork struct {
	Client1MTU int
}

func (TriangleNetwork) SetupNetworking added in v2.24.0

func (n TriangleNetwork) SetupNetworking(t *testing.T, l slog.Logger) TestNetworking

SetupNetworking creates multiple namespaces with a central router in the following topology . . ┌──────────────┐ . │ │ . │ Server ├─────────────────────────────────────┐ . │ │fdac:38fa:ffff:3::2 │ . └──────────────┘ │ fdac:38fa:ffff:3::1 . ┌──────────────┐ ┌─────┴───────┐ . │ │ fdac:38fa:ffff:1::1│ │ . │ Client 1 ├───────────────────────────────┤ Router │ . │ │fdac:38fa:ffff:1::2 │ │ . └──────────────┘ └─────┬───────┘ . ┌──────────────┐ │ fdac:38fa:ffff:2::1 . │ │ │ . │ Client 2 ├─────────────────────────────────────┘ . │ │fdac:38fa:ffff:2::2 . └──────────────┘ The veth link between Client 1 and the router has a configurable MTU via Client1MTU.

type UDPEchoService added in v2.24.0

type UDPEchoService struct{}

func (UDPEchoService) StartService added in v2.24.0

func (UDPEchoService) StartService(t *testing.T, logger slog.Logger, _ *tailnet.Conn)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL