44 "io"
55 "net/http"
66 "net/http/httptest"
7+ "net/url"
78 "testing"
89
910 "github.com/globocom/httpclient"
@@ -30,6 +31,7 @@ func TestRequest(t *testing.T) {
3031 "SetBody" : testSetBody ,
3132 "SetHeader" : testSetHeader ,
3233 "SetBasicAuth" : testSetBasicAuth ,
34+ "SetHostURL" : testSetHostURL ,
3335 "Get" : testGet ,
3436 "Post" : testPost ,
3537 "Put" : testPut ,
@@ -131,3 +133,30 @@ func testDelete(target *httpclient.Request) func(*testing.T) {
131133 assert .Equal (t , "DELETE" , gReq .Method )
132134 }
133135}
136+
137+ func testSetHostURL (target * httpclient.Request ) func (* testing.T ) {
138+ return func (t * testing.T ) {
139+ // Create a new URL to set
140+ newURL , err := url .Parse ("https://example.com:8080" )
141+ assert .NoError (t , err )
142+
143+ // Test setting the host URL
144+ result := target .SetHostURL (newURL )
145+
146+ // Verify the method returns the request instance (for chaining)
147+ assert .Equal (t , target , result )
148+
149+ // Verify the host URL was set correctly
150+ hostURL := target .HostURL ()
151+ assert .NotNil (t , hostURL )
152+ assert .Equal (t , "https://example.com:8080" , hostURL .String ())
153+ assert .Equal (t , "example.com" , hostURL .Hostname ())
154+ assert .Equal (t , "8080" , hostURL .Port ())
155+ assert .Equal (t , "https" , hostURL .Scheme )
156+
157+ // Test with nil URL
158+ result2 := target .SetHostURL (nil )
159+ assert .Equal (t , target , result2 )
160+ assert .Nil (t , target .HostURL ())
161+ }
162+ }
0 commit comments