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

Function TestServer_SSEMiddleware_Events

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

Source from the content-addressed store, hash-verified

612}
613
614func TestServer_SSEMiddleware_Events(t *testing.T) {
615 t.Parallel()
616 ctx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
617 srv, err := httpapi.NewServer(ctx, httpapi.ServerConfig{
618 AgentType: msgfmt.AgentTypeClaude,
619 AgentIO: nil,
620 Port: 0,
621 ChatBasePath: "/chat",
622 AllowedHosts: []string{"*"},
623 AllowedOrigins: []string{"*"},
624 })
625 require.NoError(t, err)
626 tsServer := httptest.NewServer(srv.Handler())
627 t.Cleanup(tsServer.Close)
628
629 t.Run("events", func(t *testing.T) {
630 t.Parallel()
631 resp, err := tsServer.Client().Get(tsServer.URL + "/events")
632 require.NoError(t, err)
633 t.Cleanup(func() {
634 _ = resp.Body.Close()
635 })
636 assertSSEHeaders(t, resp)
637 })
638
639 t.Run("internal/screen", func(t *testing.T) {
640 t.Parallel()
641
642 resp, err := tsServer.Client().Get(tsServer.URL + "/internal/screen")
643 require.NoError(t, err)
644 t.Cleanup(func() {
645 _ = resp.Body.Close()
646 })
647 assertSSEHeaders(t, resp)
648 })
649}
650
651func assertSSEHeaders(t testing.TB, resp *http.Response) {
652 t.Helper()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected