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
347 | 347 | const case22_send_byte_int = "/send_byte_int" |
348 | 348 | const case22_send_byte_int_pointer = "/send_byte_int_pointer" |
349 | 349 | const case23_send_duplicate_query_params = "/send_duplicate_query_params" |
350 | const case24_send_query_and_request_body = "/send_query_and_request_body" | |
350 | 351 | |
351 | 352 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
352 | 353 | // check method is POST before going to check other features |
479 | 480 | } |
480 | 481 | if values["param"][0] != "4" || values["param"][1] != "3" || values["param"][2] != "2" || values["param"][3] != "1" { |
481 | 482 | 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]) | |
482 | 496 | } |
483 | 497 | } |
484 | 498 | })) |
630 | 644 | Send("param=1"). |
631 | 645 | Send("param=2"). |
632 | 646 | Send("param=3¶m=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). | |
633 | 655 | End() |
634 | 656 | } |
635 | 657 | |
1581 | 1603 | defer ts.Close() |
1582 | 1604 | |
1583 | 1605 | 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"}, | |
1586 | 1608 | }).End() |
1587 | 1609 | } |
1588 | 1610 | |
1708 | 1730 | t.Fatal(err) |
1709 | 1731 | } |
1710 | 1732 | |
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) | |
1712 | 1734 | if curlComand != expected { |
1713 | 1735 | t.Fatalf("\nExpected curlCommand=%v\n but actual result=%v", expected, curlComand) |
1714 | 1736 | } |