Codebase list golang-github-parnurzeal-gorequest / b894326
Merge pull request #115 from hownowstephen/29-query-params-and-body Additional test for query + request body behaviour Quentin Perez authored 7 years ago GitHub committed 7 years ago
1 changed file(s) with 25 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
347347 const case22_send_byte_int = "/send_byte_int"
348348 const case22_send_byte_int_pointer = "/send_byte_int_pointer"
349349 const case23_send_duplicate_query_params = "/send_duplicate_query_params"
350 const case24_send_query_and_request_body = "/send_query_and_request_body"
350351
351352 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
352353 // check method is POST before going to check other features
479480 }
480481 if values["param"][0] != "4" || values["param"][1] != "3" || values["param"][2] != "2" || values["param"][3] != "1" {
481482 t.Error("Expected Body with 4 params and values", "| but got", sbody)
483 }
484 case case24_send_query_and_request_body:
485 t.Logf("case %v ", case24_send_query_and_request_body)
486 defer r.Body.Close()
487 body, _ := ioutil.ReadAll(r.Body)
488 sbody := string(body)
489 if sbody != `{"name":"jkbbwr"}` {
490 t.Error(`Expected Body "{"name":"jkbbwr"}"`, "| but got", sbody)
491 }
492
493 v := r.URL.Query()
494 if v["test"][0] != "true" {
495 t.Error("Expected test:true", "| but got", v["test"][0])
482496 }
483497 }
484498 }))
630644 Send("param=1").
631645 Send("param=2").
632646 Send("param=3&param=4").
647 End()
648
649 data24 := struct {
650 Name string `json:"name"`
651 }{"jkbbwr"}
652 New().Post(ts.URL + case24_send_query_and_request_body).
653 Query("test=true").
654 Send(data24).
633655 End()
634656 }
635657
15811603 defer ts.Close()
15821604
15831605 New().Get(ts.URL).AddCookies([]*http.Cookie{
1584 &http.Cookie{Name: "API-Cookie-Name1", Value: "api-cookie-value1"},
1585 &http.Cookie{Name: "API-Cookie-Name2", Value: "api-cookie-value2"},
1606 {Name: "API-Cookie-Name1", Value: "api-cookie-value1"},
1607 {Name: "API-Cookie-Name2", Value: "api-cookie-value2"},
15861608 }).End()
15871609 }
15881610
17081730 t.Fatal(err)
17091731 }
17101732
1711 expected := fmt.Sprintf(`curl -X PUT -d %q -H "Content-Type: application/json" '%v'`, strings.Replace(jsonData, " ", "", -1), endpoint)
1733 expected := fmt.Sprintf(`curl -X 'PUT' -d '%v' -H 'Content-Type: application/json' '%v'`, strings.Replace(jsonData, " ", "", -1), endpoint)
17121734 if curlComand != expected {
17131735 t.Fatalf("\nExpected curlCommand=%v\n but actual result=%v", expected, curlComand)
17141736 }