MCPcopy Index your code
hub / github.com/coder/coder / TestPortForward

Function TestPortForward

cli/portforward_test.go:63–383  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestPortForward(t *testing.T) {
64 t.Parallel()
65 cases := []struct {
66 name string
67 network string
68 // The flag(s) to pass to `coder port-forward X` to port-forward this type
69 // of connection. Has one format arg (string) for the remote address.
70 flag []string
71 // setupRemote creates a "remote" listener to emulate a service in the
72 // workspace. The prefix is generated per test case and can be used to
73 // filter connections.
74 setupRemote func(t *testing.T, prefix []byte) net.Listener
75 // the local address(es) to "dial"
76 localAddress []string
77 }{
78 {
79 name: "TCP",
80 network: "tcp",
81 flag: []string{"--tcp=5555:%v", "--tcp=6666:%v"},
82 setupRemote: func(t *testing.T, _ []byte) net.Listener {
83 l, err := net.Listen("tcp", "127.0.0.1:0")
84 require.NoError(t, err, "create TCP listener")
85 return l
86 },
87 localAddress: []string{"127.0.0.1:5555", "127.0.0.1:6666"},
88 },
89 {
90 name: "TCP-opportunistic-ipv6",
91 network: "tcp",
92 flag: []string{"--tcp=5566:%v", "--tcp=6655:%v"},
93 setupRemote: func(t *testing.T, _ []byte) net.Listener {
94 l, err := net.Listen("tcp", "127.0.0.1:0")
95 require.NoError(t, err, "create TCP listener")
96 return l
97 },
98 localAddress: []string{"[::1]:5566", "[::1]:6655"},
99 },
100 {
101 name: "UDP",
102 network: "udp",
103 flag: []string{"--udp=7777:%v", "--udp=8888:%v"},
104 setupRemote: listenLocalUDPWithPrefix,
105 localAddress: []string{"127.0.0.1:7777", "127.0.0.1:8888"},
106 },
107 {
108 name: "UDP-opportunistic-ipv6",
109 network: "udp",
110 flag: []string{"--udp=7788:%v", "--udp=8877:%v"},
111 setupRemote: listenLocalUDPWithPrefix,
112 localAddress: []string{"[::1]:7788", "[::1]:8877"},
113 },
114 {
115 name: "TCPWithAddress",
116 network: "tcp", flag: []string{"--tcp=10.10.10.99:9999:%v", "--tcp=10.10.10.10:1010:%v"},
117 setupRemote: func(t *testing.T, _ []byte) net.Listener {
118 l, err := net.Listen("tcp", "127.0.0.1:0")
119 require.NoError(t, err, "create TCP listener")
120 return l

Callers

nothing calls this directly

Calls 15

DialMethod · 0.95
ListenMethod · 0.95
NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
NewInProcNetFunction · 0.92
NewAddrFunction · 0.92
ContextFunction · 0.92
RequireSendFunction · 0.92

Tested by

no test coverage detected