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

Function TestCORS

middleware/cors_test.go:18–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestCORS(t *testing.T) {
19 e := echo.New()
20 req := httptest.NewRequest(http.MethodOptions, "/", nil) // Preflight request
21 req.Header.Set(echo.HeaderOrigin, "http://example.com")
22 rec := httptest.NewRecorder()
23 c := e.NewContext(req, rec)
24
25 mw := CORS("*")
26 handler := mw(func(c *echo.Context) error {
27 return nil
28 })
29
30 err := handler(c)
31 assert.NoError(t, err)
32 assert.Equal(t, http.StatusNoContent, rec.Code)
33 assert.Equal(t, "*", rec.Header().Get(echo.HeaderAccessControlAllowOrigin))
34}
35
36func TestCORSConfig(t *testing.T) {
37 var testCases = []struct {

Callers

nothing calls this directly

Calls 5

CORSFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…