mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
ed45c77be5
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
39 lines
797 B
Go
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)
|
|
}
|