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

Function TestServerTailnet_ReverseProxy

coderd/tailnet_test.go:102–368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestServerTailnet_ReverseProxy(t *testing.T) {
103 t.Parallel()
104
105 t.Run("OK", func(t *testing.T) {
106 t.Parallel()
107
108 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
109 defer cancel()
110
111 agents, serverTailnet := setupServerTailnetAgent(t, 1)
112 a := agents[0]
113
114 u, err := url.Parse(fmt.Sprintf("http://127.0.0.1:%d", workspacesdk.AgentHTTPAPIServerPort))
115 require.NoError(t, err)
116
117 rp := serverTailnet.ReverseProxy(u, u, a.id, appurl.ApplicationURL{}, "")
118
119 rw := httptest.NewRecorder()
120 req := httptest.NewRequest(
121 http.MethodGet,
122 u.String(),
123 nil,
124 ).WithContext(ctx)
125
126 rp.ServeHTTP(rw, req)
127 res := rw.Result()
128 defer res.Body.Close()
129
130 assert.Equal(t, http.StatusOK, res.StatusCode)
131 })
132
133 t.Run("Metrics", func(t *testing.T) {
134 t.Parallel()
135
136 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
137 defer cancel()
138
139 agents, serverTailnet := setupServerTailnetAgent(t, 1)
140 a := agents[0]
141
142 registry := prometheus.NewRegistry()
143 require.NoError(t, registry.Register(serverTailnet))
144
145 u, err := url.Parse(fmt.Sprintf("http://127.0.0.1:%d", workspacesdk.AgentHTTPAPIServerPort))
146 require.NoError(t, err)
147
148 rp := serverTailnet.ReverseProxy(u, u, a.id, appurl.ApplicationURL{}, "")
149
150 rw := httptest.NewRecorder()
151 req := httptest.NewRequest(
152 http.MethodGet,
153 u.String(),
154 nil,
155 ).WithContext(ctx)
156
157 rp.ServeHTTP(rw, req)
158 res := rw.Result()
159 defer res.Body.Close()

Callers

nothing calls this directly

Calls 15

getDialsMethod · 0.95
PromCounterHasValueFunction · 0.92
PromGaugeHasValueFunction · 0.92
setupServerTailnetAgentFunction · 0.85
WithContextMethod · 0.80
AddrFromUUIDMethod · 0.80
GetBlockEndpointsMethod · 0.80
ConnMethod · 0.80
RunMethod · 0.65
ParseMethod · 0.65
ReverseProxyMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected