-
Notifications
You must be signed in to change notification settings - Fork 4
/
htt2curl_test.go
30 lines (24 loc) · 938 Bytes
/
htt2curl_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
package http2curl
import (
"bytes"
"net/http"
"testing"
"github.com/cloudwego/hertz/pkg/common/test/assert"
)
func TestGetCurlCommand(t *testing.T) {
t.Parallel()
t.Run("test1", func(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "https://example.com/index?a=1&b=2", nil)
req.Header.Set("a", "2")
c, err := GetCurlCommand(req)
assert.DeepEqual(t, nil, err)
assert.DeepEqual(t, "curl -k -X 'GET' -H 'A: 2' 'https://example.com/index?a=1&b=2' --compressed", c.String())
})
t.Run("test2", func(t *testing.T) {
req, _ := http.NewRequest(http.MethodPost, "https://example.com/index", bytes.NewBufferString(`{"a":"b"}`))
req.Header.Set("Content-Type", "application/json")
command, err := GetCurlCommand(req)
assert.DeepEqual(t, nil, err)
assert.DeepEqual(t, "curl -k -X 'POST' -d '{\"a\":\"b\"}' -H 'Content-Type: application/json' 'https://example.com/index' --compressed", command.String())
})
}