@@ -733,10 +733,12 @@ func TestHostCheckRedirectPolicy(t *testing.T) {
733733 defer ts .Close ()
734734
735735 c := dc ().
736- SetRedirectPolicy (DomainCheckRedirectPolicy ("NotAllowed.com" )).
737- SetTimeout (time .Duration (time .Second * 2 ))
736+ SetRedirectPolicy (DomainCheckRedirectPolicy ("127.0.0.1" ))
738737
739- c .R ().Get (ts .URL + "/redirect-host-check-1" )
738+ _ , err := c .R ().Get (ts .URL + "/redirect-host-check-1" )
739+
740+ assertEqual (t , true , err != nil )
741+ assertEqual (t , true , strings .Contains (err .Error (), "Redirect is not allowed as per DomainCheckRedirectPolicy" ))
740742}
741743
742744func TestClientRedirectPolicy (t * testing.T ) {
@@ -917,54 +919,39 @@ func TestSetRootCertificateNotExists(t *testing.T) {
917919 assertEqual (t , true , DefaultClient .transport .TLSClientConfig == nil )
918920}
919921
920- func TestOutputFileRelativePath (t * testing.T ) {
921- c := dc ().SetRedirectPolicy (FlexibleRedirectPolicy (10 ))
922-
923- _ , err := c .R ().
924- SetOutput ("go-resty/ReplyWithHeader-v5.1-beta.zip" ).
925- Get ("http://bit.ly/1LouEKr" )
926-
927- assertError (t , err )
928- }
922+ func TestOutputFileWithBaseDirAndRelativePath (t * testing.T ) {
923+ ts := createGetServer (t )
924+ defer ts .Close ()
929925
930- func TestOutputFileWithBaseDir (t * testing.T ) {
931926 DefaultClient = dc ()
932-
933927 SetRedirectPolicy (FlexibleRedirectPolicy (10 ))
934- SetOutputDirectory (getTestDataPath () + "/sample1" )
935-
936- _ , err := R ().
937- SetOutput ("go-resty/ReplyWithHeader-v5.1-beta.zip" ).
938- Get ("http://bit.ly/1LouEKr" )
939-
940- assertError (t , err )
941- }
942-
943- func TestOutputFileAbsPath (t * testing.T ) {
944- c := dc ().SetRedirectPolicy (FlexibleRedirectPolicy (10 ))
928+ SetOutputDirectory (getTestDataPath () + "/dir-sample" )
929+ SetDebug (true )
945930
946- _ , err := c . R ().
947- SetOutput (getTestDataPath () + "/ go-resty- test-2/ReplyWithHeader-v5.1-beta.zip " ).
948- Get ("http://bit.ly/1LouEKr " )
931+ resp , err := R ().
932+ SetOutput (" go-resty/ test-img-success.png " ).
933+ Get (ts . URL + "/my-image.png " )
949934
950935 assertError (t , err )
936+ assertEqual (t , true , resp .Size () != 0 )
951937}
952938
953939func TestOutputFileWithBaseDirError (t * testing.T ) {
954940 c := dc ().SetRedirectPolicy (FlexibleRedirectPolicy (10 )).
955- SetOutputDirectory (" /go-resty" )
941+ SetOutputDirectory (getTestDataPath () + ` /go-resty\0` )
956942
957943 _ = c
958944}
959945
960- func TestOutputFileAbsPathError (t * testing.T ) {
961- c := dc ().SetRedirectPolicy (FlexibleRedirectPolicy (10 ))
946+ func TestOutputFileAbsPath (t * testing.T ) {
947+ ts := createGetServer (t )
948+ defer ts .Close ()
962949
963- _ , err := c . R ().
964- SetOutput ("/go-resty- test-2/ReplyWithHeader-v5.1-beta.zip " ).
965- Get ("http://bit.ly/1LouEKr " )
950+ _ , err := dcr ().
951+ SetOutput (getTestDataPath () + "/go-resty/ test-img-success-2.png " ).
952+ Get (ts . URL + "/my-image.png " )
966953
967- assertEqual (t , true , err != nil )
954+ assertError (t , err )
968955}
969956
970957func TestClientOptions (t * testing.T ) {
@@ -1071,6 +1058,11 @@ func createGetServer(t *testing.T) *httptest.Server {
10711058 } else if r .URL .Path == "/set-timeout-test" {
10721059 time .Sleep (time .Second * 5 )
10731060 w .Write ([]byte ("TestClientTimeout page" ))
1061+ } else if r .URL .Path == "/my-image.png" {
1062+ fileBytes , _ := ioutil .ReadFile (getTestDataPath () + "/test-img.png" )
1063+ w .Header ().Set ("Content-Type" , "image/png" )
1064+ w .Header ().Set ("Content-Length" , strconv .Itoa (len (fileBytes )))
1065+ w .Write (fileBytes )
10741066 }
10751067 }
10761068 })
@@ -1301,7 +1293,7 @@ func createRedirectServer(t *testing.T) *httptest.Server {
13011293
13021294 if cnt != 7 { // Testing hard stop via logical
13031295 if cnt >= 5 {
1304- http .Redirect (w , r , "http://notallowed.com/go-redirect " , http .StatusTemporaryRedirect )
1296+ http .Redirect (w , r , "http://httpbin.org/get " , http .StatusTemporaryRedirect )
13051297 } else {
13061298 http .Redirect (w , r , fmt .Sprintf ("/redirect-host-check-%d" , (cnt + 1 )), http .StatusTemporaryRedirect )
13071299 }
0 commit comments