-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhttp2curl_resty_test.go
38 lines (34 loc) · 1.25 KB
/
http2curl_resty_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
package http2curl
import (
"github.com/cloudwego/hertz/pkg/common/test/assert"
"github.com/go-resty/resty/v2"
"testing"
)
func TestGetCurlCommandResty(t *testing.T) {
t.Parallel()
t.Run("GET", func(t *testing.T) {
var req *resty.Request
client := resty.New()
resp, _ := client.R().
SetQueryParams(map[string]string{
"a": "1",
"b": "2",
}).SetHeader("a", "2").Get("https://example.com/index")
req = resp.Request
c, err := GetCurlCommandResty(req)
assert.DeepEqual(t, nil, err)
assert.DeepEqual(t, "curl -k -X 'GET' -H 'A: 2' -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' 'https://example.com/index?a=1&b=2' --compressed", c.String())
})
t.Run("POST", func(t *testing.T) {
var req *resty.Request
client := resty.New()
resp, _ := client.R().
SetHeader("Content-Type", "application/json").
SetBody([]byte(`{"a":"b"}`)).
Post("https://example.com/index")
req = resp.Request
command, err := GetCurlCommandResty(req)
assert.DeepEqual(t, nil, err)
assert.DeepEqual(t, "curl -k -X 'POST' -d '{\"a\":\"b\"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' 'https://example.com/index' --compressed", command.String())
})
}