iris/_examples/request-body/read-gzip/main_test.go
Gerasimos (Makis) Maropoulos ed45c77be5 reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
2020-06-07 15:26:06 +03:00

39 lines
797 B
Go

package main
import (
"bytes"
"compress/gzip"
"encoding/json"
"testing"
"github.com/kataras/iris/v12/httptest"
)
func TestGzipReader(t *testing.T) {
app := newApp()
expected := payload{Message: "test"}
b, err := json.Marshal(expected)
if err != nil {
t.Fatal(err)
}
buf := new(bytes.Buffer)
w := gzip.NewWriter(buf)
_, err = w.Write(b)
if err != nil {
t.Fatal(err)
}
err = w.Close()
if err != nil {
t.Fatal(err)
}
e := httptest.New(t, app)
// send gzip compressed.
e.POST("/").WithHeader("Content-Encoding", "gzip").WithHeader("Content-Type", "application/json").
WithBytes(buf.Bytes()).Expect().Status(httptest.StatusOK).Body().Equal(expected.Message)
// raw.
e.POST("/").WithJSON(expected).Expect().Status(httptest.StatusOK).Body().Equal(expected.Message)
}