-
Notifications
You must be signed in to change notification settings - Fork 12
/
pcurl_compressed_test.go
55 lines (42 loc) · 1.17 KB
/
pcurl_compressed_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package pcurl
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/guonaihong/gout"
"github.com/stretchr/testify/assert"
)
func createCompressed() *httptest.Server {
r := gin.New()
r.Use(gzip.Gzip(gzip.DefaultCompression))
cb := func(c *gin.Context) {
//c.Writer.Header().Add("Content-Encoding", "gzip")
io.Copy(c.Writer, c.Request.Body)
}
r.POST("/", cb)
return httptest.NewServer(http.HandlerFunc(r.ServeHTTP))
}
func Test_Compressed(t *testing.T) {
router := createCompressed()
type rspHeader struct {
ContentEncoding string `header:"Content-Encoding"`
}
for _, v := range []string{
`curl --compressed -d "test compressed test compressed"`,
} {
curlString := v + " " + router.URL + "/" + " " + "-d " + strings.Repeat("test", 100)
req, err := ParseAndRequest(curlString)
assert.NoError(t, err)
code := 0
rHeader := rspHeader{}
err = gout.New().SetRequest(req).Code(&code).BindHeader(&rHeader).Do()
assert.NoError(t, err)
assert.Equal(t, code, 200, fmt.Sprintf("server address:%s", router.URL))
assert.Equal(t, rHeader.ContentEncoding, "gzip")
}
}