func TestGinDelete(t *testing.T) { r := New() r.DELETE("/delete"). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) hello, _ := jsonparser.GetString(data, "hello") assert.Equal(t, "world", hello) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinCookie(t *testing.T) { r := New() r.GET("/text"). SetCookie(H{ "foo": "bar", }). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, "foo=bar", rq.Header.Get("cookie")) }) }
func TestGinHelloWorld(t *testing.T) { r := New() r.GET("/hello"). SetDebug(true). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) value, _ := jsonparser.GetString(data, "hello") assert.Equal(t, "world", value) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinQuery(t *testing.T) { r := New() r.GET("/query?text=world&foo=bar"). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) hello, _ := jsonparser.GetString(data, "hello") foo, _ := jsonparser.GetString(data, "foo") assert.Equal(t, "world", hello) assert.Equal(t, "bar", foo) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinPut(t *testing.T) { r := New() r.PUT("/update"). SetBody("c=1&d=2"). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) c, _ := jsonparser.GetString(data, "c") d, _ := jsonparser.GetString(data, "d") assert.Equal(t, "1", c) assert.Equal(t, "2", d) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinHeader(t *testing.T) { r := New() r.GET("/text"). SetHeader(H{ "Content-Type": "text/plain", "Go-Version": goVersion, }). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { assert.Equal(t, goVersion, rq.Header.Get("Go-Version")) assert.Equal(t, "Gofight-client/"+Version, rq.Header.Get(UserAgent)) assert.Equal(t, "text/plain", rq.Header.Get(ContentType)) assert.Equal(t, "Hello World", r.Body.String()) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinOptions(t *testing.T) { r := New() r.OPTIONS("/options"). SetJSON(D{ "a": 1, "b": 2, }). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) a, _ := jsonparser.GetInt(data, "a") b, _ := jsonparser.GetInt(data, "b") assert.Equal(t, 1, int(a)) assert.Equal(t, 2, int(b)) assert.Equal(t, http.StatusOK, r.Code) }) }
func TestGinPostFormData(t *testing.T) { r := New() r.POST("/form"). SetForm(H{ "a": "1", "b": "2", }). Run(framework.GinEngine(), func(r HTTPResponse, rq HTTPRequest) { data := []byte(r.Body.String()) a, _ := jsonparser.GetString(data, "a") b, _ := jsonparser.GetString(data, "b") assert.Equal(t, "1", a) assert.Equal(t, "2", b) assert.Equal(t, http.StatusOK, r.Code) }) }