Skip to content

Help testing middleware #51

Closed
Closed
@raphael

Description

@raphael

echo currently makes it hard/impossible to initialize a context outside of an actual HTTP request handling (the "response" field is private for example). This makes testing echo middleware tricky as one cannot just mock a context. It would be good if echo exposed a way to create arbitrary contexts. To make things more concrete here is an example of what I'm trying to achieve:

// Create dummy echo.Context with request for tests
// Note: echo makes it impossible to initialize the context response :(
func dummyContext() *echo.Context {
    req, _ := http.NewRequest("POST", "http://example.com", strings.NewReader("foo"))
    ctx := echo.Context{Request: req}
    ctx.String(200, "ok") // BLOWS UP because "response" not initialized
    return &ctx
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions