added gitlab-ci.yml and Makefile

This commit is contained in:
2018-07-31 15:09:39 +02:00
parent d3af949035
commit 9338255ac7
33 changed files with 28159 additions and 8 deletions

View File

@ -0,0 +1,99 @@
package grequests
import (
"net/url"
"testing"
)
func TestBasicDeleteRequest(t *testing.T) {
resp, err := Delete("http://httpbin.org/delete", nil)
if err != nil {
t.Error("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
}
func TestDeleteSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Delete("http://httpbin.org/delete", nil)
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
t.Error("Invalid number of cookies provided: ", resp.RawResponse.Cookies())
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
func TestDeleteInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Delete("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

1286
vendor/github.com/levigross/grequests/base_get_test.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

115
vendor/github.com/levigross/grequests/base_head_test.go generated vendored Normal file
View File

@ -0,0 +1,115 @@
package grequests
import (
"net/url"
"testing"
)
func TestBasicHeadRequest(t *testing.T) {
resp, err := Head("http://httpbin.org/get", nil)
if err != nil {
t.Error("Unable to make HEAD request: ", resp.Error)
}
if resp.Ok != true {
t.Error("HEAD request did not return success: ", resp.StatusCode)
}
if resp.Header.Get("Content-Type") != "application/json" {
t.Error("Content Type Header is unexpected: ", resp.Header.Get("Content-Type"))
}
}
func TestBasicHeadRequestNoContent(t *testing.T) {
resp, err := Head("http://httpbin.org/bytes/0", nil)
if err != nil {
t.Error("Unable to make HEAD request: ", resp.Error)
}
if resp.Ok != true {
t.Error("HEAD request did not return success: ", resp.StatusCode)
}
if resp.Header.Get("Content-Type") != "application/octet-stream" {
t.Error("Content Type Header is unexpected: ", resp.Header.Get("Content-Type"))
}
if resp.Bytes() != nil {
t.Error("Somehow byte buffer is working now (bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("Somehow byte buffer is working now (bytes)", resp.String())
}
}
func TestHeadSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
func TestHeadInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Head("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

View File

@ -0,0 +1,88 @@
package grequests
import (
"net/url"
"testing"
)
func TestBasicOPTIONSRequest(t *testing.T) {
resp, err := Options("http://httpbin.org/get", nil)
if err != nil {
t.Error("Unable to make OPTIONS request: ", resp.Error)
}
if resp.Ok != true {
t.Error("Options request did not return success: ", resp.StatusCode)
}
if resp.Header.Get("Access-Control-Allow-Methods") != "GET, POST, PUT, DELETE, PATCH, OPTIONS" {
t.Error("Access-Control-Allow-Methods Type Header is unexpected: ", resp.Header)
}
}
func TestOptionsSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
func TestOptionsInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Options("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

View File

@ -0,0 +1,99 @@
package grequests
import (
"net/url"
"testing"
)
func TestBasicPatchRequest(t *testing.T) {
resp, err := Patch("http://httpbin.org/patch", nil)
if err != nil {
t.Error("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
}
func TestPatchSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Patch("http://httpbin.org/patch", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK: ", resp.String())
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
func TestPatchInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Patch("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

948
vendor/github.com/levigross/grequests/base_post_test.go generated vendored Normal file
View File

@ -0,0 +1,948 @@
package grequests
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"math"
"net/url"
"os"
"strings"
"testing"
)
type BasicPostResponse struct {
Args struct{} `json:"args"`
Data string `json:"data"`
Files struct{} `json:"files"`
Form struct {
One string `json:"one"`
} `json:"form"`
Headers struct {
Accept string `json:"Accept"`
ContentLength string `json:"Content-Length"`
ContentType string `json:"Content-Type"`
Host string `json:"Host"`
UserAgent string `json:"User-Agent"`
} `json:"headers"`
JSON interface{} `json:"json"`
Origin string `json:"origin"`
URL string `json:"url"`
}
type BasicPostJSONResponse struct {
Args struct{} `json:"args"`
Data string `json:"data"`
Files struct{} `json:"files"`
Form struct{} `json:"form"`
Headers struct {
AcceptEncoding string `json:"Accept-Encoding"`
ContentLength string `json:"Content-Length"`
ContentType string `json:"Content-Type"`
Host string `json:"Host"`
UserAgent string `json:"User-Agent"`
XRequestedWith string `json:"X-Requested-With"`
} `json:"headers"`
JSON struct {
One string `json:"One"`
} `json:"json"`
Origin string `json:"origin"`
URL string `json:"url"`
}
type BasicMultiFileUploadResponse struct {
Args struct{} `json:"args"`
Data string `json:"data"`
Files struct {
File1 string `json:"file1"`
File2 string `json:"file2"`
} `json:"files"`
Form struct {
One string `json:"One"`
} `json:"form"`
Headers struct {
AcceptEncoding string `json:"Accept-Encoding"`
ContentLength string `json:"Content-Length"`
ContentType string `json:"Content-Type"`
Host string `json:"Host"`
UserAgent string `json:"User-Agent"`
} `json:"headers"`
JSON interface{} `json:"json"`
Origin string `json:"origin"`
URL string `json:"url"`
}
type BasicPostFileUpload struct {
Args struct{} `json:"args"`
Data string `json:"data"`
Files struct {
File string `json:"file"`
} `json:"files"`
Form struct {
One string `json:"one"`
} `json:"form"`
Headers struct {
AcceptEncoding string `json:"Accept-Encoding"`
ContentLength string `json:"Content-Length"`
ContentType string `json:"Content-Type"`
Host string `json:"Host"`
UserAgent string `json:"User-Agent"`
} `json:"headers"`
JSON interface{} `json:"json"`
Origin string `json:"origin"`
URL string `json:"url"`
}
type XMLPostMessage struct {
Name string
Age int
Height int
}
type dataAndErrorBuffer struct {
err error
bytes.Buffer
}
func (dataAndErrorBuffer) Close() error { return nil }
func (r dataAndErrorBuffer) Read(p []byte) (n int, err error) {
return 0, r.err
}
func TestBasicPostRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{Data: map[string]string{"One": "Two"}})
verifyOkPostResponse(resp, t)
}
func TestBasicRegularPostRequest(t *testing.T) {
resp, err := Post("http://httpbin.org/post",
&RequestOptions{Data: map[string]string{"One": "Two"}})
if err != nil {
t.Error("Cannot post: ", err)
}
verifyOkPostResponse(resp, t)
}
func TestBasicPostRequestInvalidURL(t *testing.T) {
resp, _ := Post("%../dir/",
&RequestOptions{Data: map[string]string{"One": "Two"},
Params: map[string]string{"1": "2"}})
if resp.Error == nil {
t.Error("Somehow the request went through")
}
}
func TestBasicPostRequestInvalidURLNoParams(t *testing.T) {
resp, _ := Post("%../dir/", &RequestOptions{Data: map[string]string{"One": "Two"}})
if resp.Error == nil {
t.Error("Somehow the request went through")
}
}
func TestSessionPostRequestInvalidURLNoParams(t *testing.T) {
session := NewSession(nil)
if _, err := session.Post("%../dir/", &RequestOptions{Data: map[string]string{"One": "Two"}}); err == nil {
t.Error("Somehow the request went through")
}
}
func TestXMLPostRequestInvalidURL(t *testing.T) {
resp, _ := Post("%../dir/",
&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
if resp.Error == nil {
t.Error("Somehow the request went through")
}
}
func TestXMLSessionPostRequestInvalidURL(t *testing.T) {
session := NewSession(nil)
_, err := session.Post("%../dir/",
&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
if err == nil {
t.Error("Somehow the request went through")
}
}
func TestBasicPostJsonRequestInvalidURL(t *testing.T) {
_, err := Post("%../dir/",
&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
}
func TestSessionPostJsonRequestInvalidURL(t *testing.T) {
session := NewSession(nil)
_, err := session.Post("%../dir/",
&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
}
func TestBasicPostJsonRequestInvalidJSON(t *testing.T) {
resp, err := Post("http://httpbin.org/post",
&RequestOptions{JSON: math.NaN(), IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
if resp.Ok == true {
t.Error("Somehow the request is OK")
}
}
func TestSessionPostJsonRequestInvalidJSON(t *testing.T) {
session := NewSession(nil)
resp, err := session.Post("http://httpbin.org/post",
&RequestOptions{JSON: math.NaN(), IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
if resp.Ok == true {
t.Error("Somehow the request is OK")
}
}
func TestBasicPostJsonRequestInvalidXML(t *testing.T) {
resp, err := Post("http://httpbin.org/post",
&RequestOptions{XML: map[string]string{"One": "two"}, IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
if resp.Ok == true {
t.Error("Somehow the request is OK")
}
}
func TestSessionPostJsonRequestInvalidXML(t *testing.T) {
session := NewSession(nil)
resp, err := session.Post("http://httpbin.org/post",
&RequestOptions{XML: map[string]string{"One": "two"}, IsAjax: true})
if err == nil {
t.Error("Somehow the request went through")
}
if resp.Ok == true {
t.Error("Somehow the request is OK")
}
}
func TestBasicPostRequestUploadInvalidURL(t *testing.T) {
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
defer fd[0].FileContents.Close()
resp, _ := Post("%../dir/",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if resp.Error == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestSessionPostRequestUploadInvalidURL(t *testing.T) {
session := NewSession(nil)
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
defer fd[0].FileContents.Close()
_, err = session.Post("%../dir/",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if err == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestBasicPostRequestUploadInvalidFileUpload(t *testing.T) {
resp, _ := Post("%../dir/",
&RequestOptions{
Files: []FileUpload{{FileName: `\x00%'"üfdsufhid\Ä\"D\\\"JS%25//'"H•\\\\'"¶•ªç∂\uf8\x8AKÔÓÔ`, FileContents: nil}},
Data: map[string]string{"One": "Two"},
})
if resp.Error == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestSessionPostRequestUploadInvalidFileUpload(t *testing.T) {
session := NewSession(nil)
_, err := session.Post("%../dir/",
&RequestOptions{
Files: []FileUpload{{FileName: "üfdsufhidÄDJSHAKÔÓÔ", FileContents: nil}},
Data: map[string]string{"One": "Two"},
})
if err == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestXMLPostRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
myXMLStruct := &XMLPostMessage{}
xml.Unmarshal([]byte(myJSONStruct.Data), myXMLStruct)
if myXMLStruct.Age != 1 {
t.Errorf("Unable to serialize XML response from within JSON %#v ", myXMLStruct)
}
}
func TestXMLPostRequestReaderBody(t *testing.T) {
msg := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
derBytes, err := xml.Marshal(msg)
if err != nil {
t.Fatal("Unable to marshal XML", err)
}
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{RequestBody: bytes.NewReader(derBytes)})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
myXMLStruct := &XMLPostMessage{}
xml.Unmarshal([]byte(myJSONStruct.Data), myXMLStruct)
if myXMLStruct.Age != 1 {
t.Errorf("Unable to serialize XML response from within JSON %#v ", myXMLStruct)
}
}
func TestXMLMarshaledStringPostRequest(t *testing.T) {
xmlStruct := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
encoded, _ := xml.Marshal(xmlStruct)
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{XML: string(encoded)})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to response to JSON", err)
}
if myJSONStruct.Data != string(encoded) {
t.Error("Response is not valid", myJSONStruct.Data, string(encoded))
}
}
func TestXMLMarshaledBytesPostRequest(t *testing.T) {
xmlStruct := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
encoded, _ := xml.Marshal(xmlStruct)
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{XML: encoded})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to response to JSON", err)
}
if myJSONStruct.Data != string(encoded) {
t.Error("Response is not valid", myJSONStruct.Data, string(encoded))
}
}
func TestXMLNilPostRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post", &RequestOptions{XML: nil})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to response to JSON", err)
}
if myJSONStruct.Data != "" {
t.Error("Response is not valid", myJSONStruct.Data)
}
}
func TestBasicPostRequestUploadErrorReader(t *testing.T) {
var rd dataAndErrorBuffer
rd.err = fmt.Errorf("Random Error")
_, err := Post("http://httpbin.org/post",
&RequestOptions{
Files: []FileUpload{{FileName: "Random.test", FileContents: rd}},
Data: map[string]string{"One": "Two"},
})
if err == nil {
t.Error("Somehow our test didn't fail...")
}
}
func TestBasicPostRequestUploadErrorEOFReader(t *testing.T) {
var rd dataAndErrorBuffer
rd.err = io.EOF
_, err := Post("http://httpbin.org/post",
&RequestOptions{
Files: []FileUpload{{FileName: "Random.test", FileContents: rd}},
Data: map[string]string{"One": "Two"},
})
if err != nil {
t.Error("Somehow our test didn't fail... ", err)
}
}
func TestBasicPostRequestUpload(t *testing.T) {
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostFileUpload{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.Files.File != "saucy sauce" {
t.Error("File upload contents have been modified: ", myJSONStruct.Files.File)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Form.One != "Two" {
t.Error("Unable to parse form properly", myJSONStruct.Form)
}
}
func TestBasicPostRequestUploadWithMime(t *testing.T) {
fd, err := os.Open("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{
Files: []FileUpload{{FileContents: fd, FileMime: "text/plain"}},
Data: map[string]string{"One": "Two"},
})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostFileUpload{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.Files.File != "saucy sauce" {
t.Error("File upload contents have been modified: ", myJSONStruct.Files.File)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Form.One != "Two" {
t.Error("Unable to parse form properly", myJSONStruct.Form)
}
// TODO: Ensure file field contains correct content-type, field, and
// filename information as soon as
// https://github.com/kennethreitz/httpbin/pull/388 gets merged
// (Or figure out a way to test this case the PR is rejected)
}
func TestBasicPostRequestUploadMultipleFiles(t *testing.T) {
fd, err := FileUploadFromGlob("testdata/*")
if err != nil {
t.Error("Unable to glob file: ", err)
}
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicMultiFileUploadResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.Files.File2 != "saucy sauce" {
t.Error("File upload contents have been modified: ", myJSONStruct.Files.File2)
}
if myJSONStruct.Files.File1 != "I am just here to test the glob" {
t.Error("File upload contents have been modified: ", myJSONStruct.Files.File1)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Form.One != "Two" {
t.Error("Unable to parse form properly", myJSONStruct.Form)
}
}
func TestBasicPostJsonBytesRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{JSON: []byte(`{"One":"Two"}`), IsAjax: true})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.JSON.One != "Two" {
t.Error("Invalid post response: ", myJSONStruct.JSON.One)
}
if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
t.Error("JSON not properly returned: ", myJSONStruct.Data)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
}
}
func TestBasicPostJsonStringRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{JSON: `{"One":"Two"}`, IsAjax: true})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.JSON.One != "Two" {
t.Error("Invalid post response: ", myJSONStruct.JSON.One)
}
if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
t.Error("JSON not properly returned: ", myJSONStruct.Data)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
}
}
func TestBasicPostJsonRequest(t *testing.T) {
resp, _ := Post("http://httpbin.org/post",
&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostJSONResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.JSON.One != "Two" {
t.Error("Invalid post response: ", myJSONStruct.JSON.One)
}
if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
t.Error("JSON not properly returned: ", myJSONStruct.Data)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
}
}
func TestPostSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Post("http://httpbin.org/post", &RequestOptions{Data: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
// verifyResponse will verify the following conditions
// 1. The request didn't return an error
// 2. The response returned an OK (a status code within the 200 range)
// 3. The output can be coerced to JSON (this may change later)
// It should only be run when testing GET request to http://httpbin.org/post expecting JSON
func verifyOkPostResponse(resp *Response, t *testing.T) *BasicPostResponse {
if resp.Error != nil {
t.Fatal("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
myJSONStruct := &BasicPostResponse{}
if err := resp.JSON(myJSONStruct); err != nil {
t.Error("Unable to coerce to JSON", err)
}
if myJSONStruct.URL != "http://httpbin.org/post" {
t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
}
if myJSONStruct.Headers.Host != "httpbin.org" {
t.Error("The host header is invalid")
}
if myJSONStruct.Form.One != "Two" {
t.Errorf("Invalid post response: %#v", myJSONStruct.Form)
}
if resp.Bytes() != nil {
t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
}
if resp.String() != "" {
t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
}
if resp.StatusCode != 200 {
t.Error("Response returned a non-200 code")
}
return myJSONStruct
}
func TestPostInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Post("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

163
vendor/github.com/levigross/grequests/base_put_test.go generated vendored Normal file
View File

@ -0,0 +1,163 @@
package grequests
import (
"net/url"
"testing"
)
func TestBasicPutRequest(t *testing.T) {
resp, err := Put("http://httpbin.org/put", nil)
if err != nil {
t.Error("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
}
func TestBasicPutUploadRequest(t *testing.T) {
t.Skip("httpbin.org is broken, as of https://github.com/kennethreitz/httpbin/issues/340#issuecomment-330176449")
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
resp, _ := Put("http://httpbin.org/put",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if resp.Error != nil {
t.Error("Unable to make request", resp.Error)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
}
func TestBasicPutUploadRequestInvalidURL(t *testing.T) {
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
_, err = Put("%../dir/",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if err == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestSessionPutUploadRequestInvalidURL(t *testing.T) {
fd, err := FileUploadFromDisk("testdata/mypassword")
if err != nil {
t.Error("Unable to open file: ", err)
}
session := NewSession(nil)
_, err = session.Put("%../dir/",
&RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if err == nil {
t.Fatal("Somehow able to make the request")
}
}
func TestPutSession(t *testing.T) {
session := NewSession(nil)
resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
resp, err = session.Put("http://httpbin.org/put", &RequestOptions{Data: map[string]string{"one": "two"}})
if err != nil {
t.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
t.Error("Request did not return OK")
}
cookieURL, err := url.Parse("http://httpbin.org")
if err != nil {
t.Error("We (for some reason) cannot parse the cookie URL")
}
if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
}
for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
switch cookie.Name {
case "one":
if cookie.Value != "two" {
t.Error("Cookie value is not valid", cookie)
}
case "two":
if cookie.Value != "three" {
t.Error("Cookie value is not valid", cookie)
}
case "three":
if cookie.Value != "four" {
t.Error("Cookie value is not valid", cookie)
}
default:
t.Error("We should not have any other cookies: ", cookie)
}
}
}
func TestPutInvalidURLSession(t *testing.T) {
session := NewSession(nil)
if _, err := session.Put("%../dir/", nil); err == nil {
t.Error("Some how the request was valid to make request ", err)
}
}

323
vendor/github.com/levigross/grequests/example_test.go generated vendored Normal file
View File

@ -0,0 +1,323 @@
package grequests_test
import (
"encoding/xml"
"io"
"log"
"net/http"
"net/url"
"github.com/levigross/grequests"
)
func Example_basicGet() {
// This is a very basic GET request
resp, err := grequests.Get("http://httpbin.org/get", nil)
if err != nil {
log.Println(err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp.String())
}
func Example_basicGetCustomHTTPClient() {
// This is a very basic GET request
resp, err := grequests.Get("http://httpbin.org/get", &grequests.RequestOptions{HTTPClient: http.DefaultClient})
if err != nil {
log.Println(err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp.String())
}
func Example_proxy() {
proxyURL, err := url.Parse("http://127.0.0.1:8080") // Proxy URL
if err != nil {
log.Panicln(err)
}
resp, err := grequests.Get("http://www.levigross.com/",
&grequests.RequestOptions{Proxies: map[string]*url.URL{proxyURL.Scheme: proxyURL}})
if err != nil {
log.Println(err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp)
}
func Example_cookies() {
resp, err := grequests.Get("http://httpbin.org/cookies",
&grequests.RequestOptions{
Cookies: []*http.Cookie{
{
Name: "TestCookie",
Value: "Random Value",
HttpOnly: true,
Secure: false,
}, {
Name: "AnotherCookie",
Value: "Some Value",
HttpOnly: true,
Secure: false,
},
},
})
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp.String())
}
func Example_session() {
session := grequests.NewSession(nil)
resp, err := session.Get("http://httpbin.org/cookies/set", &grequests.RequestOptions{Params: map[string]string{"one": "two"}})
if err != nil {
log.Fatal("Cannot set cookie: ", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp.String())
}
func Example_parse_XML() {
type GetXMLSample struct {
XMLName xml.Name `xml:"slideshow"`
Title string `xml:"title,attr"`
Date string `xml:"date,attr"`
Author string `xml:"author,attr"`
Slide []struct {
Type string `xml:"type,attr"`
Title string `xml:"title"`
} `xml:"slide"`
}
resp, err := grequests.Get("http://httpbin.org/xml", nil)
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
userXML := &GetXMLSample{}
// func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
// return input, nil
// }
// If the server returns XML encoded in another charset (not UTF-8) you
// must provide an encoder function that looks like the one I wrote above.
// If you an consuming UTF-8 just pass `nil` into the second arg
if err := resp.XML(userXML, xmlASCIIDecoder); err != nil {
log.Println("Unable to consume the response as XML: ", err)
}
if userXML.Title != "Sample Slide Show" {
log.Printf("Invalid XML serialization %#v", userXML)
}
}
func Example_customUserAgent() {
ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1"}
resp, err := grequests.Get("http://httpbin.org/get", ro)
if err != nil {
log.Fatal("Oops something went wrong: ", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
log.Println(resp.String())
}
func Example_basicAuth() {
ro := &grequests.RequestOptions{Auth: []string{"Levi", "Bot"}}
resp, err := grequests.Get("http://httpbin.org/get", ro)
// Not the usual JSON so copy and paste from below
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_customHTTPHeader() {
ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1",
Headers: map[string]string{"X-Wonderful-Header": "1"}}
resp, err := grequests.Get("http://httpbin.org/get", ro)
// Not the usual JSON so copy and paste from below
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_acceptInvalidTLSCert() {
ro := &grequests.RequestOptions{InsecureSkipVerify: true}
resp, err := grequests.Get("https://www.pcwebshop.co.uk/", ro)
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_urlQueryParams() {
ro := &grequests.RequestOptions{
Params: map[string]string{"Hello": "World", "Goodbye": "World"},
}
resp, err := grequests.Get("http://httpbin.org/get", ro)
// url will now be http://httpbin.org/get?hello=world&goodbye=world
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_downloadFile() {
resp, err := grequests.Get("http://httpbin.org/get", nil)
if err != nil {
log.Println("Unable to make request", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
if err := resp.DownloadToFile("randomFile"); err != nil {
log.Println("Unable to download to file: ", err)
}
if err != nil {
log.Println("Unable to download file", err)
}
}
func Example_postForm() {
resp, err := grequests.Post("http://httpbin.org/post",
&grequests.RequestOptions{Data: map[string]string{"One": "Two"}})
// This is the basic form POST. The request body will be `one=two`
if err != nil {
log.Println("Cannot post: ", err)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_postXML() {
type XMLPostMessage struct {
Name string
Age int
Height int
}
resp, err := grequests.Post("http://httpbin.org/post",
&grequests.RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
// The request body will contain the XML generated by the `XMLPostMessage` struct
if err != nil {
log.Println("Unable to make request", resp.Error)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_postFileUpload() {
fd, err := grequests.FileUploadFromDisk("test_files/mypassword")
if err != nil {
log.Println("Unable to open file: ", err)
}
// This will upload the file as a multipart mime request
resp, err := grequests.Post("http://httpbin.org/post",
&grequests.RequestOptions{
Files: fd,
Data: map[string]string{"One": "Two"},
})
if err != nil {
log.Println("Unable to make request", resp.Error)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func Example_postJSONAJAX() {
resp, err := grequests.Post("http://httpbin.org/post",
&grequests.RequestOptions{
JSON: map[string]string{"One": "Two"},
IsAjax: true, // this adds the X-Requested-With: XMLHttpRequest header
})
if err != nil {
log.Println("Unable to make request", resp.Error)
}
if resp.Ok != true {
log.Println("Request did not return OK")
}
}
func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
return input, nil
}

View File

@ -0,0 +1,53 @@
package grequests
import "testing"
func TestErrorOpenFile(t *testing.T) {
fd, err := FileUploadFromDisk("I am Not A File")
if err == nil {
t.Error("We are not getting an error back from our non existent file: ")
}
if fd != nil {
t.Error("We actually got back a pointer: ", fd)
}
}
func TestGLOBFiles(t *testing.T) {
fd, err := FileUploadFromGlob("testdata/*")
if err != nil {
t.Error("Got an invalid GLOB: ", err)
}
if len(fd) != 2 {
t.Error("Some how we have more than two files in our glob", len(fd), fd)
}
}
func TestInvalidGlob(t *testing.T) {
if _, err := FileUploadFromGlob("[-]"); err == nil {
t.Error("Somehow the glob worked")
}
}
func TestNoGlobFiles(t *testing.T) {
if _, err := FileUploadFromGlob("notapath"); err == nil {
t.Error("Somehow got a valid GLOB")
}
}
func TestGlobWithDir(t *testing.T) {
fd, err := FileUploadFromGlob("*test*")
if err != nil {
t.Error("Glob failed", err)
}
for _, f := range fd {
if f.FileName == "test_files" {
t.Error(f, "is a dir (which cannot be uploaded)")
}
}
}

39
vendor/github.com/levigross/grequests/request_test.go generated vendored Normal file
View File

@ -0,0 +1,39 @@
package grequests
import "testing"
func TestAddQueryStringParams(t *testing.T) {
userURL, err := buildURLParams("https://www.google.com/", map[string]string{"1": "2", "3": "4"})
if err != nil {
t.Error("URL Parse Error: ", err)
}
if userURL != "https://www.google.com/?1=2&3=4" {
t.Error("URL params not properly built", userURL)
}
}
func TestSortAddQueryStringParams(t *testing.T) {
userURL, err := buildURLParams("https://www.google.com/", map[string]string{"3": "4", "1": "2"})
if err != nil {
t.Error("URL Parse Error: ", err)
}
if userURL != "https://www.google.com/?1=2&3=4" {
t.Error("URL params not properly built and sorted", userURL)
}
}
func TestAddQueryStringParamsExistingParam(t *testing.T) {
userURL, err := buildURLParams("https://www.google.com/?5=6", map[string]string{"3": "4", "1": "2"})
if err != nil {
t.Error("URL Parse Error: ", err)
}
if userURL != "https://www.google.com/?1=2&3=4&5=6" {
t.Error("URL params not properly built and sorted", userURL)
}
}

26
vendor/github.com/levigross/grequests/response_test.go generated vendored Normal file
View File

@ -0,0 +1,26 @@
package grequests
import (
"strconv"
"testing"
)
func TestResponseOk(t *testing.T) {
status := []int{200, 201, 202, 203, 204, 205, 206, 207, 208, 226}
for _, status := range status {
verifyResponseOkForStatus(status, t)
}
}
func verifyResponseOkForStatus(status int, t *testing.T) {
url := "http://httpbin.org/status/" + strconv.Itoa(status)
resp, err := Get(url, nil)
if err != nil {
t.Error("Unable to make request", err)
}
if resp.Ok != true {
t.Errorf("Request did not return OK. Received status code %d rather a 2xx.", resp.StatusCode)
}
}

View File

@ -0,0 +1 @@
I am just here to test the glob

View File

@ -0,0 +1 @@
saucy sauce

1
vendor/github.com/levigross/grequests/utils_test.go generated vendored Normal file
View File

@ -0,0 +1 @@
package grequests