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

Function TestContextFormValue

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

Source from the content-addressed store, hash-verified

781}
782
783func TestContextFormValue(t *testing.T) {
784 f := make(url.Values)
785 f.Set("name", "Jon Snow")
786 f.Set("email", "jon@labstack.com")
787
788 e := New()
789 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode()))
790 req.Header.Add(HeaderContentType, MIMEApplicationForm)
791 c := e.NewContext(req, nil)
792
793 // FormValue
794 assert.Equal(t, "Jon Snow", c.FormValue("name"))
795 assert.Equal(t, "jon@labstack.com", c.FormValue("email"))
796
797 // FormValueOr
798 assert.Equal(t, "Jon Snow", c.FormValueOr("name", "nope"))
799 assert.Equal(t, "default", c.FormValueOr("missing", "default"))
800
801 // FormValues
802 values, err := c.FormValues()
803 if assert.NoError(t, err) {
804 assert.Equal(t, url.Values{
805 "name": []string{"Jon Snow"},
806 "email": []string{"jon@labstack.com"},
807 }, values)
808 }
809
810 // Multipart FormParams error
811 req = httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode()))
812 req.Header.Add(HeaderContentType, MIMEMultipartForm)
813 c = e.NewContext(req, nil)
814 values, err = c.FormValues()
815 assert.Nil(t, values)
816 assert.Error(t, err)
817}
818
819func TestContext_QueryParams(t *testing.T) {
820 var testCases = []struct {

Callers

nothing calls this directly

Calls 8

FormValueMethod · 0.95
FormValueOrMethod · 0.95
FormValuesMethod · 0.95
NewFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
AddMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…