MCPcopy Create free account
hub / github.com/coder/agentapi / TestServer_redirectToChat

Function TestServer_redirectToChat

lib/httpapi/server_test.go:66–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestServer_redirectToChat(t *testing.T) {
67 cases := []struct {
68 name string
69 chatBasePath string
70 expectedResponseCode int
71 expectedLocation string
72 }{
73 {"default base path", "/chat", http.StatusTemporaryRedirect, "/chat/embed"},
74 {"custom base path", "/custom", http.StatusTemporaryRedirect, "/custom/embed"},
75 }
76 for _, tc := range cases {
77 t.Run(tc.name, func(t *testing.T) {
78 t.Parallel()
79 tCtx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
80 s, err := httpapi.NewServer(tCtx, httpapi.ServerConfig{
81 AgentType: msgfmt.AgentTypeClaude,
82 AgentIO: nil,
83 Port: 0,
84 ChatBasePath: tc.chatBasePath,
85 AllowedHosts: []string{"*"},
86 AllowedOrigins: []string{"*"},
87 })
88 require.NoError(t, err)
89 tsServer := httptest.NewServer(s.Handler())
90 t.Cleanup(tsServer.Close)
91
92 client := &http.Client{
93 CheckRedirect: func(req *http.Request, via []*http.Request) error {
94 return http.ErrUseLastResponse
95 },
96 }
97 resp, err := client.Get(tsServer.URL + "/")
98 require.NoError(t, err, "unexpected error making GET request")
99 t.Cleanup(func() {
100 _ = resp.Body.Close()
101 })
102 require.Equal(t, tc.expectedResponseCode, resp.StatusCode, "expected %d status code", tc.expectedResponseCode)
103 loc := resp.Header.Get("Location")
104 require.Equal(t, tc.expectedLocation, loc, "expected Location %q, got %q", tc.expectedLocation, loc)
105 })
106 }
107}
108
109func TestServer_AllowedHosts(t *testing.T) {
110 cases := []struct {

Callers

nothing calls this directly

Calls 4

HandlerMethod · 0.95
WithLoggerFunction · 0.92
NewServerFunction · 0.92
CloseMethod · 0.80

Tested by

no test coverage detected