mirror of
https://github.com/kataras/iris.git
synced 2026-01-26 13:25:56 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
53
_examples/request-body/read-body/main_test.go
Normal file
53
_examples/request-body/read-body/main_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestReadBodyAndNegotiate(t *testing.T) {
|
||||
app := newApp()
|
||||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
var (
|
||||
expectedPayload = payload{Message: "a message"}
|
||||
expectedMsgPackPayload = "\x81\xa7message\xa9a message"
|
||||
expectedXMLPayload = `<payload>
|
||||
<message>a message</message>
|
||||
</payload>
|
||||
`
|
||||
expectedYAMLPayload = "Message: a message\n"
|
||||
)
|
||||
|
||||
// Test send JSON and receive JSON.
|
||||
e.POST("/").WithJSON(expectedPayload).Expect().Status(httptest.StatusOK).
|
||||
JSON().Equal(expectedPayload)
|
||||
|
||||
// Test send Form and receive XML.
|
||||
e.POST("/").WithForm(expectedPayload).
|
||||
WithHeader("Accept", "application/xml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(expectedXMLPayload)
|
||||
|
||||
// Test send URL Query and receive MessagePack.
|
||||
e.POST("/").WithQuery("message", expectedPayload.Message).
|
||||
WithHeader("Accept", "application/msgpack").
|
||||
Expect().Status(httptest.StatusOK).ContentType("application/msgpack").
|
||||
Body().Equal(expectedMsgPackPayload)
|
||||
|
||||
// Test send MessagePack and receive MessagePack.
|
||||
e.POST("/").WithBytes([]byte(expectedMsgPackPayload)).
|
||||
WithHeader("Content-Type", "application/msgpack").
|
||||
WithHeader("Accept", "application/msgpack").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/msgpack").Body().Equal(expectedMsgPackPayload)
|
||||
|
||||
// Test send YAML and receive YAML.
|
||||
e.POST("/").WithBytes([]byte(expectedYAMLPayload)).
|
||||
WithHeader("Content-Type", "application/x-yaml").
|
||||
WithHeader("Accept", "application/x-yaml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/x-yaml").Body().Equal(expectedYAMLPayload)
|
||||
}
|
||||
Reference in New Issue
Block a user