-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
557 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,152 @@ | ||
package ftwhttp | ||
|
||
import ( | ||
"testing" | ||
"testing" | ||
) | ||
|
||
func TestNewClient(t *testing.T) { | ||
c := NewClient() | ||
c := NewClient(NewClientConfig()) | ||
|
||
if c.Jar == nil { | ||
t.Logf("Error creating Client") | ||
} | ||
if c.Jar == nil { | ||
t.Logf("Error creating Client") | ||
} | ||
} | ||
|
||
func TestConnectDestinationHTTPS(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "example.com", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if c.Transport.protocol != "https" { | ||
t.Logf("Error connecting to example.com using https") | ||
} | ||
d := &Destination{ | ||
DestAddr: "example.com", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient(NewClientConfig()) | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if c.Transport.protocol != "https" { | ||
t.Logf("Error connecting to example.com using https") | ||
} | ||
} | ||
|
||
func TestDoRequest(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
c := NewClient(NewClientConfig()) | ||
|
||
req := generateBaseRequestForTesting() | ||
req := generateBaseRequestForTesting() | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
_, err = c.Do(*req) | ||
_, err = c.Do(*req) | ||
|
||
if err == nil { | ||
t.Logf("This should return error") | ||
} | ||
if err == nil { | ||
t.Logf("This should return error") | ||
} | ||
} | ||
|
||
func TestGetTrackedTime(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
c := NewClient(NewClientConfig()) | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"} | ||
h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"} | ||
|
||
data := []byte(`test=me&one=two&one=twice`) | ||
req := NewRequest(rl, h, data, true) | ||
data := []byte(`test=me&one=two&one=twice`) | ||
req := NewRequest(rl, h, data, true) | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
c.StartTrackingTime() | ||
c.StartTrackingTime() | ||
|
||
resp, err := c.Do(*req) | ||
resp, err := c.Do(*req) | ||
|
||
c.StopTrackingTime() | ||
c.StopTrackingTime() | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
} | ||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
} | ||
|
||
rtt := c.GetRoundTripTime() | ||
rtt := c.GetRoundTripTime() | ||
|
||
if rtt.RoundTripDuration() < 0 { | ||
t.Logf("Error getting RTT") | ||
} | ||
if rtt.RoundTripDuration() < 0 { | ||
t.Logf("Error getting RTT") | ||
} | ||
} | ||
|
||
func TestClientMultipartFormDataRequest(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{ | ||
"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost", | ||
"Content-Type": "multipart/form-data; boundary=--------397236876", | ||
} | ||
|
||
data := []byte(`----------397236876 | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient(NewClientConfig()) | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{ | ||
"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost", | ||
"Content-Type": "multipart/form-data; boundary=--------397236876", | ||
} | ||
|
||
data := []byte(`----------397236876 | ||
Content-Disposition: form-data; name="fileRap"; filename="test.txt" | ||
Content-Type: text/plain | ||
Some-file-test-here | ||
----------397236876--`) | ||
|
||
req := NewRequest(rl, h, data, true) | ||
req := NewRequest(rl, h, data, true) | ||
|
||
err := c.NewConnection(*d) | ||
err := c.NewConnection(*d) | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
c.StartTrackingTime() | ||
c.StartTrackingTime() | ||
|
||
resp, err := c.Do(*req) | ||
resp, err := c.Do(*req) | ||
|
||
c.StopTrackingTime() | ||
c.StopTrackingTime() | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.