Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongdalu-trechina committed Sep 25, 2023
1 parent 7f99be0 commit dabc3ee
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions middleware_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resty

import (
"bytes"
"net/url"
"testing"
)
Expand Down Expand Up @@ -227,3 +228,47 @@ func Test_parseRequestURL(t *testing.T) {
})
}
}

func Test_createHTTPRequest(t *testing.T) {
type args struct {
c *Client
r *Request
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "bodyBuf is not nil, deep copy",
args: args{
c: &Client{},
r: func() *Request {
req := &Request{}
req.bodyBuf = bytes.NewBufferString("test")
return req
}(),
},
wantErr: false,
},
{
name: "bodyBuf is nil, deep copy",
args: args{
c: &Client{},
r: func() *Request {
req := &Request{}
req.bodyBuf = nil
return req
}(),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := createHTTPRequest(tt.args.c, tt.args.r); (err != nil) != tt.wantErr {
t.Errorf("createHTTPRequest() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit dabc3ee

Please sign in to comment.