MCPcopy
hub / github.com/labstack/echo / TestContextStream

Function TestContextStream

context_test.go:172–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

170}
171
172func TestContextStream(t *testing.T) {
173 e := New()
174 rec := httptest.NewRecorder()
175 req := httptest.NewRequest(http.MethodGet, "/", nil)
176 c := e.NewContext(req, rec)
177
178 r, w := io.Pipe()
179 go func() {
180 defer w.Close()
181 for i := range 3 {
182 fmt.Fprintf(w, "data: index %v\n\n", i)
183 time.Sleep(5 * time.Millisecond)
184 }
185 }()
186
187 err := c.Stream(http.StatusOK, "text/event-stream", r)
188 if assert.NoError(t, err) {
189 assert.Equal(t, http.StatusOK, rec.Code)
190 assert.Equal(t, "text/event-stream", rec.Header().Get(HeaderContentType))
191 assert.Equal(t, "data: index 0\n\ndata: index 1\n\ndata: index 2\n\n", rec.Body.String())
192 }
193}
194
195func TestContextHTML(t *testing.T) {
196 rec := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 7

StreamMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
CloseMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…