Skip to content

Commit

Permalink
补充方法的测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared-lu committed Nov 10, 2024
1 parent d869c7f commit 4b7c145
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions net/httpx/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func TestRequest_JSONBody(t *testing.T) {
req = req.JSONBody(User{})
assert.NotNil(t, req.req.Body)
assert.Equal(t, "application/json", req.req.Header.Get("Content-Type"))

req2 := NewRequest(context.Background(), http.MethodGet, "://localhost:80/a")
assert.NotNil(t, req2.err)
assert.Nil(t, req2.req)
}

func TestRequest_Do(t *testing.T) {
Expand Down Expand Up @@ -103,6 +107,10 @@ func TestRequest_AddParam(t *testing.T) {
AddParam("key1", "value1").
AddParam("key2", "value2")
assert.Equal(t, "http://localhost?key1=value1&key2=value2", req.req.URL.String())

req2 := NewRequest(context.Background(), http.MethodGet, "://localhost:80/a")
assert.NotNil(t, req2.err)
assert.Nil(t, req2.req)
}

func TestRequestAddHeader(t *testing.T) {
Expand All @@ -111,14 +119,12 @@ func TestRequestAddHeader(t *testing.T) {
AddHeader("head1", "val1").AddHeader("head1", "val2")
vals := req.req.Header.Values("head1")
assert.Equal(t, []string{"val1", "val2"}, vals)

req2 := NewRequest(context.Background(), http.MethodGet, "://localhost:80/a")
assert.NotNil(t, req2.err)
assert.Nil(t, req2.req)
}

type User struct {
Name string
}

func TestNewRequest_ReturnError(t *testing.T) {
req := NewRequest(context.Background(), http.MethodGet, "://localhost:80/a")
assert.NotNil(t, req.err)
assert.Nil(t, req.req)
}

0 comments on commit 4b7c145

Please sign in to comment.