How to use getRequest method of http Package

Best Venom code snippet using http.getRequest

sendgrid_test.go

Source:sendgrid_test.go Github

copy

Full Screen

1package sendgrid2import (3 "bytes"4 "fmt"5 "io"6 "net/http"7 "net/http/httptest"8 "os"9 "os/exec"10 "runtime"11 "strings"12 "testing"13 "time"14 "github.com/sendgrid/rest"15)16var (17 testAPIKey = "SENDGRID_APIKEY"18 testHost = ""19 prismPath = "prism"20 prismArgs = []string{"run", "-s", "https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"}21 prismCmd *exec.Cmd22 buffer bytes.Buffer23 curl *exec.Cmd24 sh *exec.Cmd25)26func TestMain(m *testing.M) {27 // By default prism runs on localhost:401028 // Learn how to configure prism here: https://designer.stoplight.io/docs/prism29 testHost = "http://localhost:4010"30 if runtime.GOOS == "windows" {31 prismPath += ".exe"32 }33 // Check if prism is installed, if not, install it34 if _, err := os.Stat(prismPath); os.IsNotExist(err) {35 if runtime.GOOS != "windows" {36 curl = exec.Command("curl", "https://raw.githubusercontent.com/stoplightio/prism/master/install.sh")37 sh = exec.Command("sh")38 read, write := io.Pipe()39 curl.Stdout = write40 sh.Stdin = read41 sh.Stdout = &buffer42 curl.Start()43 sh.Start()44 curl.Wait()45 write.Close()46 sh.Wait()47 _, err := io.Copy(os.Stdout, &buffer)48 if err != nil {49 fmt.Println("Error downloading the prism binary, you can try downloading directly here (https://github.com/stoplightio/prism/releases) and place in your $GOPATH/bin directory: ", err)50 }51 } else {52 fmt.Fprintf(os.Stderr, "Please download the Windows binary (https://github.com/stoplightio/prism/releases) and place it in your $GOPATH/bin directory")53 os.Exit(1)54 }55 } else {56 updatePrismCmd := exec.Command(prismPath, "up")57 err := updatePrismCmd.Start()58 if err != nil {59 fmt.Println("Error updating prism, please download an update! (https://github.com/stoplightio/prism/releases)", err)60 } else {61 fmt.Println("Waiting for prism to update...")62 err = updatePrismCmd.Wait()63 if err != nil {64 fmt.Println("Error updating prism, please download an update! (https://github.com/stoplightio/prism/releases)", err)65 }66 fmt.Println("Prism is now up to date!")67 }68 }69 prismCmd = exec.Command(prismPath, prismArgs...)70 // If you want to see prism's ouput uncomment below.71 // prismReader, err := prismCmd.StdoutPipe()72 // if err != nil {73 // fmt.Println("Error creating StdoutPipe for Cmd", err)74 // }75 // scanner := bufio.NewScanner(prismReader)76 // go func() {77 // for scanner.Scan() {78 // fmt.Printf("prism | %s\n", scanner.Text())79 // }80 // }()81 go func() {82 fmt.Println("Start Prism")83 err := prismCmd.Start()84 if err != nil {85 fmt.Println("Error starting prism", err)86 }87 }()88 // Need to give prism enough time to launch!89 duration := time.Second * 1590 time.Sleep(duration)91 exitCode := m.Run()92 if prismCmd != nil {93 prismCmd.Process.Kill()94 prismCmd = nil95 }96 os.Exit(exitCode)97}98func TestSendGridVersion(t *testing.T) {99 if Version != "3.1.0" {100 t.Error("SendGrid version does not match")101 }102}103func TestGetRequest(t *testing.T) {104 request := GetRequest("", "", "")105 if request.BaseURL != "https://api.sendgrid.com" {106 t.Error("Host default not set")107 }108 if request.Headers["Authorization"] != "Bearer " {109 t.Error("Wrong default Authorization")110 }111 if request.Headers["User-Agent"] != "sendgrid/"+Version+";go" {112 t.Error("Wrong default User Agent")113 }114 request = GetRequest("API_KEY", "/v3/endpoint", "https://test.api.com")115 if request.BaseURL != "https://test.api.com/v3/endpoint" {116 t.Error("Host not set correctly")117 }118 if request.Headers["Authorization"] != "Bearer API_KEY" {119 t.Error("Wrong Authorization")120 }121 if request.Headers["User-Agent"] != "sendgrid/"+Version+";go" {122 t.Error("Wrong User Agent")123 }124 if request.Headers["Accept"] != "application/json" {125 t.Error("Wrong Accept header")126 }127}128func TestCustomHTTPClient(t *testing.T) {129 fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {130 time.Sleep(time.Millisecond * 20)131 fmt.Fprintln(w, "{\"message\": \"success\"}")132 }))133 defer fakeServer.Close()134 apiKey := "SENDGRID_APIKEY"135 host := fakeServer.URL136 request := GetRequest(apiKey, "/v3/test_endpoint", host)137 request.Method = "GET"138 var custom rest.Client139 custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}140 _, err := custom.API(request)141 if err == nil {142 t.Error("A timeout did not trigger as expected")143 }144 if strings.Contains(err.Error(), "Client.Timeout exceeded while awaiting headers") == false {145 t.Error("We did not receive the Timeout error")146 }147}148func Test_test_access_settings_activity_get(t *testing.T) {149 apiKey := "SENDGRID_APIKEY"150 host := "http://localhost:4010"151 request := GetRequest(apiKey, "/v3/access_settings/activity", host)152 request.Method = "GET"153 queryParams := make(map[string]string)154 queryParams["limit"] = "1"155 request.QueryParams = queryParams156 request.Headers["X-Mock"] = "200"157 response, err := API(request)158 if err != nil {159 fmt.Println(err)160 }161 if response.StatusCode != 200 {162 t.Error("Wrong status code returned")163 }164}165func Test_test_access_settings_whitelist_post(t *testing.T) {166 apiKey := "SENDGRID_APIKEY"167 host := "http://localhost:4010"168 request := GetRequest(apiKey, "/v3/access_settings/whitelist", host)169 request.Method = "POST"170 request.Body = []byte(` {171 "ips": [172 {173 "ip": "192.168.1.1"174 },175 {176 "ip": "192.*.*.*"177 },178 {179 "ip": "192.168.1.3/32"180 }181 ]182}`)183 request.Headers["X-Mock"] = "201"184 response, err := API(request)185 if err != nil {186 fmt.Println(err)187 }188 if response.StatusCode != 201 {189 t.Error("Wrong status code returned")190 }191}192func Test_test_access_settings_whitelist_get(t *testing.T) {193 apiKey := "SENDGRID_APIKEY"194 host := "http://localhost:4010"195 request := GetRequest(apiKey, "/v3/access_settings/whitelist", host)196 request.Method = "GET"197 request.Headers["X-Mock"] = "200"198 response, err := API(request)199 if err != nil {200 fmt.Println(err)201 }202 if response.StatusCode != 200 {203 t.Error("Wrong status code returned")204 }205}206func Test_test_access_settings_whitelist_delete(t *testing.T) {207 apiKey := "SENDGRID_APIKEY"208 host := "http://localhost:4010"209 request := GetRequest(apiKey, "/v3/access_settings/whitelist", host)210 request.Method = "DELETE"211 request.Body = []byte(` {212 "ids": [213 1,214 2,215 3216 ]217}`)218 request.Headers["X-Mock"] = "204"219 response, err := API(request)220 if err != nil {221 fmt.Println(err)222 }223 if response.StatusCode != 204 {224 t.Error("Wrong status code returned")225 }226}227func Test_test_access_settings_whitelist__rule_id__get(t *testing.T) {228 apiKey := "SENDGRID_APIKEY"229 host := "http://localhost:4010"230 request := GetRequest(apiKey, "/v3/access_settings/whitelist/{rule_id}", host)231 request.Method = "GET"232 request.Headers["X-Mock"] = "200"233 response, err := API(request)234 if err != nil {235 fmt.Println(err)236 }237 if response.StatusCode != 200 {238 t.Error("Wrong status code returned")239 }240}241func Test_test_access_settings_whitelist__rule_id__delete(t *testing.T) {242 apiKey := "SENDGRID_APIKEY"243 host := "http://localhost:4010"244 request := GetRequest(apiKey, "/v3/access_settings/whitelist/{rule_id}", host)245 request.Method = "DELETE"246 request.Headers["X-Mock"] = "204"247 response, err := API(request)248 if err != nil {249 fmt.Println(err)250 }251 if response.StatusCode != 204 {252 t.Error("Wrong status code returned")253 }254}255func Test_test_alerts_post(t *testing.T) {256 apiKey := "SENDGRID_APIKEY"257 host := "http://localhost:4010"258 request := GetRequest(apiKey, "/v3/alerts", host)259 request.Method = "POST"260 request.Body = []byte(` {261 "email_to": "example@example.com",262 "frequency": "daily",263 "type": "stats_notification"264}`)265 request.Headers["X-Mock"] = "201"266 response, err := API(request)267 if err != nil {268 fmt.Println(err)269 }270 if response.StatusCode != 201 {271 t.Error("Wrong status code returned")272 }273}274func Test_test_alerts_get(t *testing.T) {275 apiKey := "SENDGRID_APIKEY"276 host := "http://localhost:4010"277 request := GetRequest(apiKey, "/v3/alerts", host)278 request.Method = "GET"279 request.Headers["X-Mock"] = "200"280 response, err := API(request)281 if err != nil {282 fmt.Println(err)283 }284 if response.StatusCode != 200 {285 t.Error("Wrong status code returned")286 }287}288func Test_test_alerts__alert_id__patch(t *testing.T) {289 apiKey := "SENDGRID_APIKEY"290 host := "http://localhost:4010"291 request := GetRequest(apiKey, "/v3/alerts/{alert_id}", host)292 request.Method = "PATCH"293 request.Body = []byte(` {294 "email_to": "example@example.com"295}`)296 request.Headers["X-Mock"] = "200"297 response, err := API(request)298 if err != nil {299 fmt.Println(err)300 }301 if response.StatusCode != 200 {302 t.Error("Wrong status code returned")303 }304}305func Test_test_alerts__alert_id__get(t *testing.T) {306 apiKey := "SENDGRID_APIKEY"307 host := "http://localhost:4010"308 request := GetRequest(apiKey, "/v3/alerts/{alert_id}", host)309 request.Method = "GET"310 request.Headers["X-Mock"] = "200"311 response, err := API(request)312 if err != nil {313 fmt.Println(err)314 }315 if response.StatusCode != 200 {316 t.Error("Wrong status code returned")317 }318}319func Test_test_alerts__alert_id__delete(t *testing.T) {320 apiKey := "SENDGRID_APIKEY"321 host := "http://localhost:4010"322 request := GetRequest(apiKey, "/v3/alerts/{alert_id}", host)323 request.Method = "DELETE"324 request.Headers["X-Mock"] = "204"325 response, err := API(request)326 if err != nil {327 fmt.Println(err)328 }329 if response.StatusCode != 204 {330 t.Error("Wrong status code returned")331 }332}333func Test_test_api_keys_post(t *testing.T) {334 apiKey := "SENDGRID_APIKEY"335 host := "http://localhost:4010"336 request := GetRequest(apiKey, "/v3/api_keys", host)337 request.Method = "POST"338 request.Body = []byte(` {339 "name": "My API Key",340 "sample": "data",341 "scopes": [342 "mail.send",343 "alerts.create",344 "alerts.read"345 ]346}`)347 request.Headers["X-Mock"] = "201"348 response, err := API(request)349 if err != nil {350 fmt.Println(err)351 }352 if response.StatusCode != 201 {353 t.Error("Wrong status code returned")354 }355}356func Test_test_api_keys_get(t *testing.T) {357 apiKey := "SENDGRID_APIKEY"358 host := "http://localhost:4010"359 request := GetRequest(apiKey, "/v3/api_keys", host)360 request.Method = "GET"361 queryParams := make(map[string]string)362 queryParams["limit"] = "1"363 request.QueryParams = queryParams364 request.Headers["X-Mock"] = "200"365 response, err := API(request)366 if err != nil {367 fmt.Println(err)368 }369 if response.StatusCode != 200 {370 t.Error("Wrong status code returned")371 }372}373func Test_test_api_keys__api_key_id__put(t *testing.T) {374 apiKey := "SENDGRID_APIKEY"375 host := "http://localhost:4010"376 request := GetRequest(apiKey, "/v3/api_keys/{api_key_id}", host)377 request.Method = "PUT"378 request.Body = []byte(` {379 "name": "A New Hope",380 "scopes": [381 "user.profile.read",382 "user.profile.update"383 ]384}`)385 request.Headers["X-Mock"] = "200"386 response, err := API(request)387 if err != nil {388 fmt.Println(err)389 }390 if response.StatusCode != 200 {391 t.Error("Wrong status code returned")392 }393}394func Test_test_api_keys__api_key_id__patch(t *testing.T) {395 apiKey := "SENDGRID_APIKEY"396 host := "http://localhost:4010"397 request := GetRequest(apiKey, "/v3/api_keys/{api_key_id}", host)398 request.Method = "PATCH"399 request.Body = []byte(` {400 "name": "A New Hope"401}`)402 request.Headers["X-Mock"] = "200"403 response, err := API(request)404 if err != nil {405 fmt.Println(err)406 }407 if response.StatusCode != 200 {408 t.Error("Wrong status code returned")409 }410}411func Test_test_api_keys__api_key_id__get(t *testing.T) {412 apiKey := "SENDGRID_APIKEY"413 host := "http://localhost:4010"414 request := GetRequest(apiKey, "/v3/api_keys/{api_key_id}", host)415 request.Method = "GET"416 request.Headers["X-Mock"] = "200"417 response, err := API(request)418 if err != nil {419 fmt.Println(err)420 }421 if response.StatusCode != 200 {422 t.Error("Wrong status code returned")423 }424}425func Test_test_api_keys__api_key_id__delete(t *testing.T) {426 apiKey := "SENDGRID_APIKEY"427 host := "http://localhost:4010"428 request := GetRequest(apiKey, "/v3/api_keys/{api_key_id}", host)429 request.Method = "DELETE"430 request.Headers["X-Mock"] = "204"431 response, err := API(request)432 if err != nil {433 fmt.Println(err)434 }435 if response.StatusCode != 204 {436 t.Error("Wrong status code returned")437 }438}439func Test_test_asm_groups_post(t *testing.T) {440 apiKey := "SENDGRID_APIKEY"441 host := "http://localhost:4010"442 request := GetRequest(apiKey, "/v3/asm/groups", host)443 request.Method = "POST"444 request.Body = []byte(` {445 "description": "Suggestions for products our users might like.",446 "is_default": true,447 "name": "Product Suggestions"448}`)449 request.Headers["X-Mock"] = "201"450 response, err := API(request)451 if err != nil {452 fmt.Println(err)453 }454 if response.StatusCode != 201 {455 t.Error("Wrong status code returned")456 }457}458func Test_test_asm_groups_get(t *testing.T) {459 apiKey := "SENDGRID_APIKEY"460 host := "http://localhost:4010"461 request := GetRequest(apiKey, "/v3/asm/groups", host)462 request.Method = "GET"463 queryParams := make(map[string]string)464 queryParams["id"] = "1"465 request.QueryParams = queryParams466 request.Headers["X-Mock"] = "200"467 response, err := API(request)468 if err != nil {469 fmt.Println(err)470 }471 if response.StatusCode != 200 {472 t.Error("Wrong status code returned")473 }474}475func Test_test_asm_groups__group_id__patch(t *testing.T) {476 apiKey := "SENDGRID_APIKEY"477 host := "http://localhost:4010"478 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}", host)479 request.Method = "PATCH"480 request.Body = []byte(` {481 "description": "Suggestions for items our users might like.",482 "id": 103,483 "name": "Item Suggestions"484}`)485 request.Headers["X-Mock"] = "201"486 response, err := API(request)487 if err != nil {488 fmt.Println(err)489 }490 if response.StatusCode != 201 {491 t.Error("Wrong status code returned")492 }493}494func Test_test_asm_groups__group_id__get(t *testing.T) {495 apiKey := "SENDGRID_APIKEY"496 host := "http://localhost:4010"497 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}", host)498 request.Method = "GET"499 request.Headers["X-Mock"] = "200"500 response, err := API(request)501 if err != nil {502 fmt.Println(err)503 }504 if response.StatusCode != 200 {505 t.Error("Wrong status code returned")506 }507}508func Test_test_asm_groups__group_id__delete(t *testing.T) {509 apiKey := "SENDGRID_APIKEY"510 host := "http://localhost:4010"511 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}", host)512 request.Method = "DELETE"513 request.Headers["X-Mock"] = "204"514 response, err := API(request)515 if err != nil {516 fmt.Println(err)517 }518 if response.StatusCode != 204 {519 t.Error("Wrong status code returned")520 }521}522func Test_test_asm_groups__group_id__suppressions_post(t *testing.T) {523 apiKey := "SENDGRID_APIKEY"524 host := "http://localhost:4010"525 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}/suppressions", host)526 request.Method = "POST"527 request.Body = []byte(` {528 "recipient_emails": [529 "test1@example.com",530 "test2@example.com"531 ]532}`)533 request.Headers["X-Mock"] = "201"534 response, err := API(request)535 if err != nil {536 fmt.Println(err)537 }538 if response.StatusCode != 201 {539 t.Error("Wrong status code returned")540 }541}542func Test_test_asm_groups__group_id__suppressions_get(t *testing.T) {543 apiKey := "SENDGRID_APIKEY"544 host := "http://localhost:4010"545 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}/suppressions", host)546 request.Method = "GET"547 request.Headers["X-Mock"] = "200"548 response, err := API(request)549 if err != nil {550 fmt.Println(err)551 }552 if response.StatusCode != 200 {553 t.Error("Wrong status code returned")554 }555}556func Test_test_asm_groups__group_id__suppressions_search_post(t *testing.T) {557 apiKey := "SENDGRID_APIKEY"558 host := "http://localhost:4010"559 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}/suppressions/search", host)560 request.Method = "POST"561 request.Body = []byte(` {562 "recipient_emails": [563 "exists1@example.com",564 "exists2@example.com",565 "doesnotexists@example.com"566 ]567}`)568 request.Headers["X-Mock"] = "200"569 response, err := API(request)570 if err != nil {571 fmt.Println(err)572 }573 if response.StatusCode != 200 {574 t.Error("Wrong status code returned")575 }576}577func Test_test_asm_groups__group_id__suppressions__email__delete(t *testing.T) {578 apiKey := "SENDGRID_APIKEY"579 host := "http://localhost:4010"580 request := GetRequest(apiKey, "/v3/asm/groups/{group_id}/suppressions/{email}", host)581 request.Method = "DELETE"582 request.Headers["X-Mock"] = "204"583 response, err := API(request)584 if err != nil {585 fmt.Println(err)586 }587 if response.StatusCode != 204 {588 t.Error("Wrong status code returned")589 }590}591func Test_test_asm_suppressions_get(t *testing.T) {592 apiKey := "SENDGRID_APIKEY"593 host := "http://localhost:4010"594 request := GetRequest(apiKey, "/v3/asm/suppressions", host)595 request.Method = "GET"596 request.Headers["X-Mock"] = "200"597 response, err := API(request)598 if err != nil {599 fmt.Println(err)600 }601 if response.StatusCode != 200 {602 t.Error("Wrong status code returned")603 }604}605func Test_test_asm_suppressions_global_post(t *testing.T) {606 apiKey := "SENDGRID_APIKEY"607 host := "http://localhost:4010"608 request := GetRequest(apiKey, "/v3/asm/suppressions/global", host)609 request.Method = "POST"610 request.Body = []byte(` {611 "recipient_emails": [612 "test1@example.com",613 "test2@example.com"614 ]615}`)616 request.Headers["X-Mock"] = "201"617 response, err := API(request)618 if err != nil {619 fmt.Println(err)620 }621 if response.StatusCode != 201 {622 t.Error("Wrong status code returned")623 }624}625func Test_test_asm_suppressions_global__email__get(t *testing.T) {626 apiKey := "SENDGRID_APIKEY"627 host := "http://localhost:4010"628 request := GetRequest(apiKey, "/v3/asm/suppressions/global/{email}", host)629 request.Method = "GET"630 request.Headers["X-Mock"] = "200"631 response, err := API(request)632 if err != nil {633 fmt.Println(err)634 }635 if response.StatusCode != 200 {636 t.Error("Wrong status code returned")637 }638}639func Test_test_asm_suppressions_global__email__delete(t *testing.T) {640 apiKey := "SENDGRID_APIKEY"641 host := "http://localhost:4010"642 request := GetRequest(apiKey, "/v3/asm/suppressions/global/{email}", host)643 request.Method = "DELETE"644 request.Headers["X-Mock"] = "204"645 response, err := API(request)646 if err != nil {647 fmt.Println(err)648 }649 if response.StatusCode != 204 {650 t.Error("Wrong status code returned")651 }652}653func Test_test_asm_suppressions__email__get(t *testing.T) {654 apiKey := "SENDGRID_APIKEY"655 host := "http://localhost:4010"656 request := GetRequest(apiKey, "/v3/asm/suppressions/{email}", host)657 request.Method = "GET"658 request.Headers["X-Mock"] = "200"659 response, err := API(request)660 if err != nil {661 fmt.Println(err)662 }663 if response.StatusCode != 200 {664 t.Error("Wrong status code returned")665 }666}667func Test_test_browsers_stats_get(t *testing.T) {668 apiKey := "SENDGRID_APIKEY"669 host := "http://localhost:4010"670 request := GetRequest(apiKey, "/v3/browsers/stats", host)671 request.Method = "GET"672 queryParams := make(map[string]string)673 queryParams["end_date"] = "2016-04-01"674 queryParams["aggregated_by"] = "day"675 queryParams["browsers"] = "test_string"676 queryParams["limit"] = "test_string"677 queryParams["offset"] = "test_string"678 queryParams["start_date"] = "2016-01-01"679 request.QueryParams = queryParams680 request.Headers["X-Mock"] = "200"681 response, err := API(request)682 if err != nil {683 fmt.Println(err)684 }685 if response.StatusCode != 200 {686 t.Error("Wrong status code returned")687 }688}689func Test_test_campaigns_post(t *testing.T) {690 apiKey := "SENDGRID_APIKEY"691 host := "http://localhost:4010"692 request := GetRequest(apiKey, "/v3/campaigns", host)693 request.Method = "POST"694 request.Body = []byte(` {695 "categories": [696 "spring line"697 ],698 "custom_unsubscribe_url": "",699 "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",700 "ip_pool": "marketing",701 "list_ids": [702 110,703 124704 ],705 "plain_content": "Check out our spring line!",706 "segment_ids": [707 110708 ],709 "sender_id": 124451,710 "subject": "New Products for Spring!",711 "suppression_group_id": 42,712 "title": "March Newsletter"713}`)714 request.Headers["X-Mock"] = "201"715 response, err := API(request)716 if err != nil {717 fmt.Println(err)718 }719 if response.StatusCode != 201 {720 t.Error("Wrong status code returned")721 }722}723func Test_test_campaigns_get(t *testing.T) {724 apiKey := "SENDGRID_APIKEY"725 host := "http://localhost:4010"726 request := GetRequest(apiKey, "/v3/campaigns", host)727 request.Method = "GET"728 queryParams := make(map[string]string)729 queryParams["limit"] = "1"730 queryParams["offset"] = "1"731 request.QueryParams = queryParams732 request.Headers["X-Mock"] = "200"733 response, err := API(request)734 if err != nil {735 fmt.Println(err)736 }737 if response.StatusCode != 200 {738 t.Error("Wrong status code returned")739 }740}741func Test_test_campaigns__campaign_id__patch(t *testing.T) {742 apiKey := "SENDGRID_APIKEY"743 host := "http://localhost:4010"744 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}", host)745 request.Method = "PATCH"746 request.Body = []byte(` {747 "categories": [748 "summer line"749 ],750 "html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",751 "plain_content": "Check out our summer line!",752 "subject": "New Products for Summer!",753 "title": "May Newsletter"754}`)755 request.Headers["X-Mock"] = "200"756 response, err := API(request)757 if err != nil {758 fmt.Println(err)759 }760 if response.StatusCode != 200 {761 t.Error("Wrong status code returned")762 }763}764func Test_test_campaigns__campaign_id__get(t *testing.T) {765 apiKey := "SENDGRID_APIKEY"766 host := "http://localhost:4010"767 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}", host)768 request.Method = "GET"769 request.Headers["X-Mock"] = "200"770 response, err := API(request)771 if err != nil {772 fmt.Println(err)773 }774 if response.StatusCode != 200 {775 t.Error("Wrong status code returned")776 }777}778func Test_test_campaigns__campaign_id__delete(t *testing.T) {779 apiKey := "SENDGRID_APIKEY"780 host := "http://localhost:4010"781 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}", host)782 request.Method = "DELETE"783 request.Headers["X-Mock"] = "204"784 response, err := API(request)785 if err != nil {786 fmt.Println(err)787 }788 if response.StatusCode != 204 {789 t.Error("Wrong status code returned")790 }791}792func Test_test_campaigns__campaign_id__schedules_patch(t *testing.T) {793 apiKey := "SENDGRID_APIKEY"794 host := "http://localhost:4010"795 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules", host)796 request.Method = "PATCH"797 request.Body = []byte(` {798 "send_at": 1489451436799}`)800 request.Headers["X-Mock"] = "200"801 response, err := API(request)802 if err != nil {803 fmt.Println(err)804 }805 if response.StatusCode != 200 {806 t.Error("Wrong status code returned")807 }808}809func Test_test_campaigns__campaign_id__schedules_post(t *testing.T) {810 apiKey := "SENDGRID_APIKEY"811 host := "http://localhost:4010"812 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules", host)813 request.Method = "POST"814 request.Body = []byte(` {815 "send_at": 1489771528816}`)817 request.Headers["X-Mock"] = "201"818 response, err := API(request)819 if err != nil {820 fmt.Println(err)821 }822 if response.StatusCode != 201 {823 t.Error("Wrong status code returned")824 }825}826func Test_test_campaigns__campaign_id__schedules_get(t *testing.T) {827 apiKey := "SENDGRID_APIKEY"828 host := "http://localhost:4010"829 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules", host)830 request.Method = "GET"831 request.Headers["X-Mock"] = "200"832 response, err := API(request)833 if err != nil {834 fmt.Println(err)835 }836 if response.StatusCode != 200 {837 t.Error("Wrong status code returned")838 }839}840func Test_test_campaigns__campaign_id__schedules_delete(t *testing.T) {841 apiKey := "SENDGRID_APIKEY"842 host := "http://localhost:4010"843 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules", host)844 request.Method = "DELETE"845 request.Headers["X-Mock"] = "204"846 response, err := API(request)847 if err != nil {848 fmt.Println(err)849 }850 if response.StatusCode != 204 {851 t.Error("Wrong status code returned")852 }853}854func Test_test_campaigns__campaign_id__schedules_now_post(t *testing.T) {855 apiKey := "SENDGRID_APIKEY"856 host := "http://localhost:4010"857 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules/now", host)858 request.Method = "POST"859 request.Headers["X-Mock"] = "201"860 response, err := API(request)861 if err != nil {862 fmt.Println(err)863 }864 if response.StatusCode != 201 {865 t.Error("Wrong status code returned")866 }867}868func Test_test_campaigns__campaign_id__schedules_test_post(t *testing.T) {869 apiKey := "SENDGRID_APIKEY"870 host := "http://localhost:4010"871 request := GetRequest(apiKey, "/v3/campaigns/{campaign_id}/schedules/test", host)872 request.Method = "POST"873 request.Body = []byte(` {874 "to": "your.email@example.com"875}`)876 request.Headers["X-Mock"] = "204"877 response, err := API(request)878 if err != nil {879 fmt.Println(err)880 }881 if response.StatusCode != 204 {882 t.Error("Wrong status code returned")883 }884}885func Test_test_categories_get(t *testing.T) {886 apiKey := "SENDGRID_APIKEY"887 host := "http://localhost:4010"888 request := GetRequest(apiKey, "/v3/categories", host)889 request.Method = "GET"890 queryParams := make(map[string]string)891 queryParams["category"] = "test_string"892 queryParams["limit"] = "1"893 queryParams["offset"] = "1"894 request.QueryParams = queryParams895 request.Headers["X-Mock"] = "200"896 response, err := API(request)897 if err != nil {898 fmt.Println(err)899 }900 if response.StatusCode != 200 {901 t.Error("Wrong status code returned")902 }903}904func Test_test_categories_stats_get(t *testing.T) {905 apiKey := "SENDGRID_APIKEY"906 host := "http://localhost:4010"907 request := GetRequest(apiKey, "/v3/categories/stats", host)908 request.Method = "GET"909 queryParams := make(map[string]string)910 queryParams["end_date"] = "2016-04-01"911 queryParams["aggregated_by"] = "day"912 queryParams["limit"] = "1"913 queryParams["offset"] = "1"914 queryParams["start_date"] = "2016-01-01"915 queryParams["categories"] = "test_string"916 request.QueryParams = queryParams917 request.Headers["X-Mock"] = "200"918 response, err := API(request)919 if err != nil {920 fmt.Println(err)921 }922 if response.StatusCode != 200 {923 t.Error("Wrong status code returned")924 }925}926func Test_test_categories_stats_sums_get(t *testing.T) {927 apiKey := "SENDGRID_APIKEY"928 host := "http://localhost:4010"929 request := GetRequest(apiKey, "/v3/categories/stats/sums", host)930 request.Method = "GET"931 queryParams := make(map[string]string)932 queryParams["end_date"] = "2016-04-01"933 queryParams["aggregated_by"] = "day"934 queryParams["limit"] = "1"935 queryParams["sort_by_metric"] = "test_string"936 queryParams["offset"] = "1"937 queryParams["start_date"] = "2016-01-01"938 queryParams["sort_by_direction"] = "asc"939 request.QueryParams = queryParams940 request.Headers["X-Mock"] = "200"941 response, err := API(request)942 if err != nil {943 fmt.Println(err)944 }945 if response.StatusCode != 200 {946 t.Error("Wrong status code returned")947 }948}949func Test_test_clients_stats_get(t *testing.T) {950 apiKey := "SENDGRID_APIKEY"951 host := "http://localhost:4010"952 request := GetRequest(apiKey, "/v3/clients/stats", host)953 request.Method = "GET"954 queryParams := make(map[string]string)955 queryParams["aggregated_by"] = "day"956 queryParams["start_date"] = "2016-01-01"957 queryParams["end_date"] = "2016-04-01"958 request.QueryParams = queryParams959 request.Headers["X-Mock"] = "200"960 response, err := API(request)961 if err != nil {962 fmt.Println(err)963 }964 if response.StatusCode != 200 {965 t.Error("Wrong status code returned")966 }967}968func Test_test_clients__client_type__stats_get(t *testing.T) {969 apiKey := "SENDGRID_APIKEY"970 host := "http://localhost:4010"971 request := GetRequest(apiKey, "/v3/clients/{client_type}/stats", host)972 request.Method = "GET"973 queryParams := make(map[string]string)974 queryParams["aggregated_by"] = "day"975 queryParams["start_date"] = "2016-01-01"976 queryParams["end_date"] = "2016-04-01"977 request.QueryParams = queryParams978 request.Headers["X-Mock"] = "200"979 response, err := API(request)980 if err != nil {981 fmt.Println(err)982 }983 if response.StatusCode != 200 {984 t.Error("Wrong status code returned")985 }986}987func Test_test_contactdb_custom_fields_post(t *testing.T) {988 apiKey := "SENDGRID_APIKEY"989 host := "http://localhost:4010"990 request := GetRequest(apiKey, "/v3/contactdb/custom_fields", host)991 request.Method = "POST"992 request.Body = []byte(` {993 "name": "pet",994 "type": "text"995}`)996 request.Headers["X-Mock"] = "201"997 response, err := API(request)998 if err != nil {999 fmt.Println(err)1000 }1001 if response.StatusCode != 201 {1002 t.Error("Wrong status code returned")1003 }1004}1005func Test_test_contactdb_custom_fields_get(t *testing.T) {1006 apiKey := "SENDGRID_APIKEY"1007 host := "http://localhost:4010"1008 request := GetRequest(apiKey, "/v3/contactdb/custom_fields", host)1009 request.Method = "GET"1010 request.Headers["X-Mock"] = "200"1011 response, err := API(request)1012 if err != nil {1013 fmt.Println(err)1014 }1015 if response.StatusCode != 200 {1016 t.Error("Wrong status code returned")1017 }1018}1019func Test_test_contactdb_custom_fields__custom_field_id__get(t *testing.T) {1020 apiKey := "SENDGRID_APIKEY"1021 host := "http://localhost:4010"1022 request := GetRequest(apiKey, "/v3/contactdb/custom_fields/{custom_field_id}", host)1023 request.Method = "GET"1024 request.Headers["X-Mock"] = "200"1025 response, err := API(request)1026 if err != nil {1027 fmt.Println(err)1028 }1029 if response.StatusCode != 200 {1030 t.Error("Wrong status code returned")1031 }1032}1033func Test_test_contactdb_custom_fields__custom_field_id__delete(t *testing.T) {1034 apiKey := "SENDGRID_APIKEY"1035 host := "http://localhost:4010"1036 request := GetRequest(apiKey, "/v3/contactdb/custom_fields/{custom_field_id}", host)1037 request.Method = "DELETE"1038 request.Headers["X-Mock"] = "202"1039 response, err := API(request)1040 if err != nil {1041 fmt.Println(err)1042 }1043 if response.StatusCode != 202 {1044 t.Error("Wrong status code returned")1045 }1046}1047func Test_test_contactdb_lists_post(t *testing.T) {1048 apiKey := "SENDGRID_APIKEY"1049 host := "http://localhost:4010"1050 request := GetRequest(apiKey, "/v3/contactdb/lists", host)1051 request.Method = "POST"1052 request.Body = []byte(` {1053 "name": "your list name"1054}`)1055 request.Headers["X-Mock"] = "201"1056 response, err := API(request)1057 if err != nil {1058 fmt.Println(err)1059 }1060 if response.StatusCode != 201 {1061 t.Error("Wrong status code returned")1062 }1063}1064func Test_test_contactdb_lists_get(t *testing.T) {1065 apiKey := "SENDGRID_APIKEY"1066 host := "http://localhost:4010"1067 request := GetRequest(apiKey, "/v3/contactdb/lists", host)1068 request.Method = "GET"1069 request.Headers["X-Mock"] = "200"1070 response, err := API(request)1071 if err != nil {1072 fmt.Println(err)1073 }1074 if response.StatusCode != 200 {1075 t.Error("Wrong status code returned")1076 }1077}1078func Test_test_contactdb_lists_delete(t *testing.T) {1079 apiKey := "SENDGRID_APIKEY"1080 host := "http://localhost:4010"1081 request := GetRequest(apiKey, "/v3/contactdb/lists", host)1082 request.Method = "DELETE"1083 request.Body = []byte(` [1084 1,1085 2,1086 3,1087 41088]`)1089 request.Headers["X-Mock"] = "204"1090 response, err := API(request)1091 if err != nil {1092 fmt.Println(err)1093 }1094 if response.StatusCode != 204 {1095 t.Error("Wrong status code returned")1096 }1097}1098func Test_test_contactdb_lists__list_id__patch(t *testing.T) {1099 apiKey := "SENDGRID_APIKEY"1100 host := "http://localhost:4010"1101 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}", host)1102 request.Method = "PATCH"1103 request.Body = []byte(` {1104 "name": "newlistname"1105}`)1106 queryParams := make(map[string]string)1107 queryParams["list_id"] = "1"1108 request.QueryParams = queryParams1109 request.Headers["X-Mock"] = "200"1110 response, err := API(request)1111 if err != nil {1112 fmt.Println(err)1113 }1114 if response.StatusCode != 200 {1115 t.Error("Wrong status code returned")1116 }1117}1118func Test_test_contactdb_lists__list_id__get(t *testing.T) {1119 apiKey := "SENDGRID_APIKEY"1120 host := "http://localhost:4010"1121 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}", host)1122 request.Method = "GET"1123 queryParams := make(map[string]string)1124 queryParams["list_id"] = "1"1125 request.QueryParams = queryParams1126 request.Headers["X-Mock"] = "200"1127 response, err := API(request)1128 if err != nil {1129 fmt.Println(err)1130 }1131 if response.StatusCode != 200 {1132 t.Error("Wrong status code returned")1133 }1134}1135func Test_test_contactdb_lists__list_id__delete(t *testing.T) {1136 apiKey := "SENDGRID_APIKEY"1137 host := "http://localhost:4010"1138 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}", host)1139 request.Method = "DELETE"1140 queryParams := make(map[string]string)1141 queryParams["delete_contacts"] = "true"1142 request.QueryParams = queryParams1143 request.Headers["X-Mock"] = "202"1144 response, err := API(request)1145 if err != nil {1146 fmt.Println(err)1147 }1148 if response.StatusCode != 202 {1149 t.Error("Wrong status code returned")1150 }1151}1152func Test_test_contactdb_lists__list_id__recipients_post(t *testing.T) {1153 apiKey := "SENDGRID_APIKEY"1154 host := "http://localhost:4010"1155 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}/recipients", host)1156 request.Method = "POST"1157 request.Body = []byte(` [1158 "recipient_id1",1159 "recipient_id2"1160]`)1161 request.Headers["X-Mock"] = "201"1162 response, err := API(request)1163 if err != nil {1164 fmt.Println(err)1165 }1166 if response.StatusCode != 201 {1167 t.Error("Wrong status code returned")1168 }1169}1170func Test_test_contactdb_lists__list_id__recipients_get(t *testing.T) {1171 apiKey := "SENDGRID_APIKEY"1172 host := "http://localhost:4010"1173 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}/recipients", host)1174 request.Method = "GET"1175 queryParams := make(map[string]string)1176 queryParams["page"] = "1"1177 queryParams["page_size"] = "1"1178 queryParams["list_id"] = "1"1179 request.QueryParams = queryParams1180 request.Headers["X-Mock"] = "200"1181 response, err := API(request)1182 if err != nil {1183 fmt.Println(err)1184 }1185 if response.StatusCode != 200 {1186 t.Error("Wrong status code returned")1187 }1188}1189func Test_test_contactdb_lists__list_id__recipients__recipient_id__post(t *testing.T) {1190 apiKey := "SENDGRID_APIKEY"1191 host := "http://localhost:4010"1192 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}/recipients/{recipient_id}", host)1193 request.Method = "POST"1194 request.Headers["X-Mock"] = "201"1195 response, err := API(request)1196 if err != nil {1197 fmt.Println(err)1198 }1199 if response.StatusCode != 201 {1200 t.Error("Wrong status code returned")1201 }1202}1203func Test_test_contactdb_lists__list_id__recipients__recipient_id__delete(t *testing.T) {1204 apiKey := "SENDGRID_APIKEY"1205 host := "http://localhost:4010"1206 request := GetRequest(apiKey, "/v3/contactdb/lists/{list_id}/recipients/{recipient_id}", host)1207 request.Method = "DELETE"1208 queryParams := make(map[string]string)1209 queryParams["recipient_id"] = "1"1210 queryParams["list_id"] = "1"1211 request.QueryParams = queryParams1212 request.Headers["X-Mock"] = "204"1213 response, err := API(request)1214 if err != nil {1215 fmt.Println(err)1216 }1217 if response.StatusCode != 204 {1218 t.Error("Wrong status code returned")1219 }1220}1221func Test_test_contactdb_recipients_patch(t *testing.T) {1222 apiKey := "SENDGRID_APIKEY"1223 host := "http://localhost:4010"1224 request := GetRequest(apiKey, "/v3/contactdb/recipients", host)1225 request.Method = "PATCH"1226 request.Body = []byte(` [1227 {1228 "email": "jones@example.com",1229 "first_name": "Guy",1230 "last_name": "Jones"1231 }1232]`)1233 request.Headers["X-Mock"] = "201"1234 response, err := API(request)1235 if err != nil {1236 fmt.Println(err)1237 }1238 if response.StatusCode != 201 {1239 t.Error("Wrong status code returned")1240 }1241}1242func Test_test_contactdb_recipients_post(t *testing.T) {1243 apiKey := "SENDGRID_APIKEY"1244 host := "http://localhost:4010"1245 request := GetRequest(apiKey, "/v3/contactdb/recipients", host)1246 request.Method = "POST"1247 request.Body = []byte(` [1248 {1249 "age": 25,1250 "email": "example@example.com",1251 "first_name": "",1252 "last_name": "User"1253 },1254 {1255 "age": 25,1256 "email": "example2@example.com",1257 "first_name": "Example",1258 "last_name": "User"1259 }1260]`)1261 request.Headers["X-Mock"] = "201"1262 response, err := API(request)1263 if err != nil {1264 fmt.Println(err)1265 }1266 if response.StatusCode != 201 {1267 t.Error("Wrong status code returned")1268 }1269}1270func Test_test_contactdb_recipients_get(t *testing.T) {1271 apiKey := "SENDGRID_APIKEY"1272 host := "http://localhost:4010"1273 request := GetRequest(apiKey, "/v3/contactdb/recipients", host)1274 request.Method = "GET"1275 queryParams := make(map[string]string)1276 queryParams["page"] = "1"1277 queryParams["page_size"] = "1"1278 request.QueryParams = queryParams1279 request.Headers["X-Mock"] = "200"1280 response, err := API(request)1281 if err != nil {1282 fmt.Println(err)1283 }1284 if response.StatusCode != 200 {1285 t.Error("Wrong status code returned")1286 }1287}1288func Test_test_contactdb_recipients_delete(t *testing.T) {1289 apiKey := "SENDGRID_APIKEY"1290 host := "http://localhost:4010"1291 request := GetRequest(apiKey, "/v3/contactdb/recipients", host)1292 request.Method = "DELETE"1293 request.Body = []byte(` [1294 "recipient_id1",1295 "recipient_id2"1296]`)1297 request.Headers["X-Mock"] = "200"1298 response, err := API(request)1299 if err != nil {1300 fmt.Println(err)1301 }1302 if response.StatusCode != 200 {1303 t.Error("Wrong status code returned")1304 }1305}1306func Test_test_contactdb_recipients_billable_count_get(t *testing.T) {1307 apiKey := "SENDGRID_APIKEY"1308 host := "http://localhost:4010"1309 request := GetRequest(apiKey, "/v3/contactdb/recipients/billable_count", host)1310 request.Method = "GET"1311 request.Headers["X-Mock"] = "200"1312 response, err := API(request)1313 if err != nil {1314 fmt.Println(err)1315 }1316 if response.StatusCode != 200 {1317 t.Error("Wrong status code returned")1318 }1319}1320func Test_test_contactdb_recipients_count_get(t *testing.T) {1321 apiKey := "SENDGRID_APIKEY"1322 host := "http://localhost:4010"1323 request := GetRequest(apiKey, "/v3/contactdb/recipients/count", host)1324 request.Method = "GET"1325 request.Headers["X-Mock"] = "200"1326 response, err := API(request)1327 if err != nil {1328 fmt.Println(err)1329 }1330 if response.StatusCode != 200 {1331 t.Error("Wrong status code returned")1332 }1333}1334func Test_test_contactdb_recipients_search_get(t *testing.T) {1335 apiKey := "SENDGRID_APIKEY"1336 host := "http://localhost:4010"1337 request := GetRequest(apiKey, "/v3/contactdb/recipients/search", host)1338 request.Method = "GET"1339 queryParams := make(map[string]string)1340 queryParams["{field_name}"] = "test_string"1341 request.QueryParams = queryParams1342 request.Headers["X-Mock"] = "200"1343 response, err := API(request)1344 if err != nil {1345 fmt.Println(err)1346 }1347 if response.StatusCode != 200 {1348 t.Error("Wrong status code returned")1349 }1350}1351func Test_test_contactdb_recipients__recipient_id__get(t *testing.T) {1352 apiKey := "SENDGRID_APIKEY"1353 host := "http://localhost:4010"1354 request := GetRequest(apiKey, "/v3/contactdb/recipients/{recipient_id}", host)1355 request.Method = "GET"1356 request.Headers["X-Mock"] = "200"1357 response, err := API(request)1358 if err != nil {1359 fmt.Println(err)1360 }1361 if response.StatusCode != 200 {1362 t.Error("Wrong status code returned")1363 }1364}1365func Test_test_contactdb_recipients__recipient_id__delete(t *testing.T) {1366 apiKey := "SENDGRID_APIKEY"1367 host := "http://localhost:4010"1368 request := GetRequest(apiKey, "/v3/contactdb/recipients/{recipient_id}", host)1369 request.Method = "DELETE"1370 request.Headers["X-Mock"] = "204"1371 response, err := API(request)1372 if err != nil {1373 fmt.Println(err)1374 }1375 if response.StatusCode != 204 {1376 t.Error("Wrong status code returned")1377 }1378}1379func Test_test_contactdb_recipients__recipient_id__lists_get(t *testing.T) {1380 apiKey := "SENDGRID_APIKEY"1381 host := "http://localhost:4010"1382 request := GetRequest(apiKey, "/v3/contactdb/recipients/{recipient_id}/lists", host)1383 request.Method = "GET"1384 request.Headers["X-Mock"] = "200"1385 response, err := API(request)1386 if err != nil {1387 fmt.Println(err)1388 }1389 if response.StatusCode != 200 {1390 t.Error("Wrong status code returned")1391 }1392}1393func Test_test_contactdb_reserved_fields_get(t *testing.T) {1394 apiKey := "SENDGRID_APIKEY"1395 host := "http://localhost:4010"1396 request := GetRequest(apiKey, "/v3/contactdb/reserved_fields", host)1397 request.Method = "GET"1398 request.Headers["X-Mock"] = "200"1399 response, err := API(request)1400 if err != nil {1401 fmt.Println(err)1402 }1403 if response.StatusCode != 200 {1404 t.Error("Wrong status code returned")1405 }1406}1407func Test_test_contactdb_segments_post(t *testing.T) {1408 apiKey := "SENDGRID_APIKEY"1409 host := "http://localhost:4010"1410 request := GetRequest(apiKey, "/v3/contactdb/segments", host)1411 request.Method = "POST"1412 request.Body = []byte(` {1413 "conditions": [1414 {1415 "and_or": "",1416 "field": "last_name",1417 "operator": "eq",1418 "value": "Miller"1419 },1420 {1421 "and_or": "and",1422 "field": "last_clicked",1423 "operator": "gt",1424 "value": "01/02/2015"1425 },1426 {1427 "and_or": "or",1428 "field": "clicks.campaign_identifier",1429 "operator": "eq",1430 "value": "513"1431 }1432 ],1433 "list_id": 4,1434 "name": "Last Name Miller"1435}`)1436 request.Headers["X-Mock"] = "200"1437 response, err := API(request)1438 if err != nil {1439 fmt.Println(err)1440 }1441 if response.StatusCode != 200 {1442 t.Error("Wrong status code returned")1443 }1444}1445func Test_test_contactdb_segments_get(t *testing.T) {1446 apiKey := "SENDGRID_APIKEY"1447 host := "http://localhost:4010"1448 request := GetRequest(apiKey, "/v3/contactdb/segments", host)1449 request.Method = "GET"1450 request.Headers["X-Mock"] = "200"1451 response, err := API(request)1452 if err != nil {1453 fmt.Println(err)1454 }1455 if response.StatusCode != 200 {1456 t.Error("Wrong status code returned")1457 }1458}1459func Test_test_contactdb_segments__segment_id__patch(t *testing.T) {1460 apiKey := "SENDGRID_APIKEY"1461 host := "http://localhost:4010"1462 request := GetRequest(apiKey, "/v3/contactdb/segments/{segment_id}", host)1463 request.Method = "PATCH"1464 request.Body = []byte(` {1465 "conditions": [1466 {1467 "and_or": "",1468 "field": "last_name",1469 "operator": "eq",1470 "value": "Miller"1471 }1472 ],1473 "list_id": 5,1474 "name": "The Millers"1475}`)1476 queryParams := make(map[string]string)1477 queryParams["segment_id"] = "test_string"1478 request.QueryParams = queryParams1479 request.Headers["X-Mock"] = "200"1480 response, err := API(request)1481 if err != nil {1482 fmt.Println(err)1483 }1484 if response.StatusCode != 200 {1485 t.Error("Wrong status code returned")1486 }1487}1488func Test_test_contactdb_segments__segment_id__get(t *testing.T) {1489 apiKey := "SENDGRID_APIKEY"1490 host := "http://localhost:4010"1491 request := GetRequest(apiKey, "/v3/contactdb/segments/{segment_id}", host)1492 request.Method = "GET"1493 queryParams := make(map[string]string)1494 queryParams["segment_id"] = "1"1495 request.QueryParams = queryParams1496 request.Headers["X-Mock"] = "200"1497 response, err := API(request)1498 if err != nil {1499 fmt.Println(err)1500 }1501 if response.StatusCode != 200 {1502 t.Error("Wrong status code returned")1503 }1504}1505func Test_test_contactdb_segments__segment_id__delete(t *testing.T) {1506 apiKey := "SENDGRID_APIKEY"1507 host := "http://localhost:4010"1508 request := GetRequest(apiKey, "/v3/contactdb/segments/{segment_id}", host)1509 request.Method = "DELETE"1510 queryParams := make(map[string]string)1511 queryParams["delete_contacts"] = "true"1512 request.QueryParams = queryParams1513 request.Headers["X-Mock"] = "204"1514 response, err := API(request)1515 if err != nil {1516 fmt.Println(err)1517 }1518 if response.StatusCode != 204 {1519 t.Error("Wrong status code returned")1520 }1521}1522func Test_test_contactdb_segments__segment_id__recipients_get(t *testing.T) {1523 apiKey := "SENDGRID_APIKEY"1524 host := "http://localhost:4010"1525 request := GetRequest(apiKey, "/v3/contactdb/segments/{segment_id}/recipients", host)1526 request.Method = "GET"1527 queryParams := make(map[string]string)1528 queryParams["page"] = "1"1529 queryParams["page_size"] = "1"1530 request.QueryParams = queryParams1531 request.Headers["X-Mock"] = "200"1532 response, err := API(request)1533 if err != nil {1534 fmt.Println(err)1535 }1536 if response.StatusCode != 200 {1537 t.Error("Wrong status code returned")1538 }1539}1540func Test_test_devices_stats_get(t *testing.T) {1541 apiKey := "SENDGRID_APIKEY"1542 host := "http://localhost:4010"1543 request := GetRequest(apiKey, "/v3/devices/stats", host)1544 request.Method = "GET"1545 queryParams := make(map[string]string)1546 queryParams["aggregated_by"] = "day"1547 queryParams["limit"] = "1"1548 queryParams["start_date"] = "2016-01-01"1549 queryParams["end_date"] = "2016-04-01"1550 queryParams["offset"] = "1"1551 request.QueryParams = queryParams1552 request.Headers["X-Mock"] = "200"1553 response, err := API(request)1554 if err != nil {1555 fmt.Println(err)1556 }1557 if response.StatusCode != 200 {1558 t.Error("Wrong status code returned")1559 }1560}1561func Test_test_geo_stats_get(t *testing.T) {1562 apiKey := "SENDGRID_APIKEY"1563 host := "http://localhost:4010"1564 request := GetRequest(apiKey, "/v3/geo/stats", host)1565 request.Method = "GET"1566 queryParams := make(map[string]string)1567 queryParams["end_date"] = "2016-04-01"1568 queryParams["country"] = "US"1569 queryParams["aggregated_by"] = "day"1570 queryParams["limit"] = "1"1571 queryParams["offset"] = "1"1572 queryParams["start_date"] = "2016-01-01"1573 request.QueryParams = queryParams1574 request.Headers["X-Mock"] = "200"1575 response, err := API(request)1576 if err != nil {1577 fmt.Println(err)1578 }1579 if response.StatusCode != 200 {1580 t.Error("Wrong status code returned")1581 }1582}1583func Test_test_ips_get(t *testing.T) {1584 apiKey := "SENDGRID_APIKEY"1585 host := "http://localhost:4010"1586 request := GetRequest(apiKey, "/v3/ips", host)1587 request.Method = "GET"1588 queryParams := make(map[string]string)1589 queryParams["subuser"] = "test_string"1590 queryParams["ip"] = "test_string"1591 queryParams["limit"] = "1"1592 queryParams["exclude_whitelabels"] = "true"1593 queryParams["offset"] = "1"1594 request.QueryParams = queryParams1595 request.Headers["X-Mock"] = "200"1596 response, err := API(request)1597 if err != nil {1598 fmt.Println(err)1599 }1600 if response.StatusCode != 200 {1601 t.Error("Wrong status code returned")1602 }1603}1604func Test_test_ips_assigned_get(t *testing.T) {1605 apiKey := "SENDGRID_APIKEY"1606 host := "http://localhost:4010"1607 request := GetRequest(apiKey, "/v3/ips/assigned", host)1608 request.Method = "GET"1609 request.Headers["X-Mock"] = "200"1610 response, err := API(request)1611 if err != nil {1612 fmt.Println(err)1613 }1614 if response.StatusCode != 200 {1615 t.Error("Wrong status code returned")1616 }1617}1618func Test_test_ips_pools_post(t *testing.T) {1619 apiKey := "SENDGRID_APIKEY"1620 host := "http://localhost:4010"1621 request := GetRequest(apiKey, "/v3/ips/pools", host)1622 request.Method = "POST"1623 request.Body = []byte(` {1624 "name": "marketing"1625}`)1626 request.Headers["X-Mock"] = "200"1627 response, err := API(request)1628 if err != nil {1629 fmt.Println(err)1630 }1631 if response.StatusCode != 200 {1632 t.Error("Wrong status code returned")1633 }1634}1635func Test_test_ips_pools_get(t *testing.T) {1636 apiKey := "SENDGRID_APIKEY"1637 host := "http://localhost:4010"1638 request := GetRequest(apiKey, "/v3/ips/pools", host)1639 request.Method = "GET"1640 request.Headers["X-Mock"] = "200"1641 response, err := API(request)1642 if err != nil {1643 fmt.Println(err)1644 }1645 if response.StatusCode != 200 {1646 t.Error("Wrong status code returned")1647 }1648}1649func Test_test_ips_pools__pool_name__put(t *testing.T) {1650 apiKey := "SENDGRID_APIKEY"1651 host := "http://localhost:4010"1652 request := GetRequest(apiKey, "/v3/ips/pools/{pool_name}", host)1653 request.Method = "PUT"1654 request.Body = []byte(` {1655 "name": "new_pool_name"1656}`)1657 request.Headers["X-Mock"] = "200"1658 response, err := API(request)1659 if err != nil {1660 fmt.Println(err)1661 }1662 if response.StatusCode != 200 {1663 t.Error("Wrong status code returned")1664 }1665}1666func Test_test_ips_pools__pool_name__get(t *testing.T) {1667 apiKey := "SENDGRID_APIKEY"1668 host := "http://localhost:4010"1669 request := GetRequest(apiKey, "/v3/ips/pools/{pool_name}", host)1670 request.Method = "GET"1671 request.Headers["X-Mock"] = "200"1672 response, err := API(request)1673 if err != nil {1674 fmt.Println(err)1675 }1676 if response.StatusCode != 200 {1677 t.Error("Wrong status code returned")1678 }1679}1680func Test_test_ips_pools__pool_name__delete(t *testing.T) {1681 apiKey := "SENDGRID_APIKEY"1682 host := "http://localhost:4010"1683 request := GetRequest(apiKey, "/v3/ips/pools/{pool_name}", host)1684 request.Method = "DELETE"1685 request.Headers["X-Mock"] = "204"1686 response, err := API(request)1687 if err != nil {1688 fmt.Println(err)1689 }1690 if response.StatusCode != 204 {1691 t.Error("Wrong status code returned")1692 }1693}1694func Test_test_ips_pools__pool_name__ips_post(t *testing.T) {1695 apiKey := "SENDGRID_APIKEY"1696 host := "http://localhost:4010"1697 request := GetRequest(apiKey, "/v3/ips/pools/{pool_name}/ips", host)1698 request.Method = "POST"1699 request.Body = []byte(` {1700 "ip": "0.0.0.0"1701}`)1702 request.Headers["X-Mock"] = "201"1703 response, err := API(request)1704 if err != nil {1705 fmt.Println(err)1706 }1707 if response.StatusCode != 201 {1708 t.Error("Wrong status code returned")1709 }1710}1711func Test_test_ips_pools__pool_name__ips__ip__delete(t *testing.T) {1712 apiKey := "SENDGRID_APIKEY"1713 host := "http://localhost:4010"1714 request := GetRequest(apiKey, "/v3/ips/pools/{pool_name}/ips/{ip}", host)1715 request.Method = "DELETE"1716 request.Headers["X-Mock"] = "204"1717 response, err := API(request)1718 if err != nil {1719 fmt.Println(err)1720 }1721 if response.StatusCode != 204 {1722 t.Error("Wrong status code returned")1723 }1724}1725func Test_test_ips_warmup_post(t *testing.T) {1726 apiKey := "SENDGRID_APIKEY"1727 host := "http://localhost:4010"1728 request := GetRequest(apiKey, "/v3/ips/warmup", host)1729 request.Method = "POST"1730 request.Body = []byte(` {1731 "ip": "0.0.0.0"1732}`)1733 request.Headers["X-Mock"] = "200"1734 response, err := API(request)1735 if err != nil {1736 fmt.Println(err)1737 }1738 if response.StatusCode != 200 {1739 t.Error("Wrong status code returned")1740 }1741}1742func Test_test_ips_warmup_get(t *testing.T) {1743 apiKey := "SENDGRID_APIKEY"1744 host := "http://localhost:4010"1745 request := GetRequest(apiKey, "/v3/ips/warmup", host)1746 request.Method = "GET"1747 request.Headers["X-Mock"] = "200"1748 response, err := API(request)1749 if err != nil {1750 fmt.Println(err)1751 }1752 if response.StatusCode != 200 {1753 t.Error("Wrong status code returned")1754 }1755}1756func Test_test_ips_warmup__ip_address__get(t *testing.T) {1757 apiKey := "SENDGRID_APIKEY"1758 host := "http://localhost:4010"1759 request := GetRequest(apiKey, "/v3/ips/warmup/{ip_address}", host)1760 request.Method = "GET"1761 request.Headers["X-Mock"] = "200"1762 response, err := API(request)1763 if err != nil {1764 fmt.Println(err)1765 }1766 if response.StatusCode != 200 {1767 t.Error("Wrong status code returned")1768 }1769}1770func Test_test_ips_warmup__ip_address__delete(t *testing.T) {1771 apiKey := "SENDGRID_APIKEY"1772 host := "http://localhost:4010"1773 request := GetRequest(apiKey, "/v3/ips/warmup/{ip_address}", host)1774 request.Method = "DELETE"1775 request.Headers["X-Mock"] = "204"1776 response, err := API(request)1777 if err != nil {1778 fmt.Println(err)1779 }1780 if response.StatusCode != 204 {1781 t.Error("Wrong status code returned")1782 }1783}1784func Test_test_ips__ip_address__get(t *testing.T) {1785 apiKey := "SENDGRID_APIKEY"1786 host := "http://localhost:4010"1787 request := GetRequest(apiKey, "/v3/ips/{ip_address}", host)1788 request.Method = "GET"1789 request.Headers["X-Mock"] = "200"1790 response, err := API(request)1791 if err != nil {1792 fmt.Println(err)1793 }1794 if response.StatusCode != 200 {1795 t.Error("Wrong status code returned")1796 }1797}1798func Test_test_mail_batch_post(t *testing.T) {1799 apiKey := "SENDGRID_APIKEY"1800 host := "http://localhost:4010"1801 request := GetRequest(apiKey, "/v3/mail/batch", host)1802 request.Method = "POST"1803 request.Headers["X-Mock"] = "201"1804 response, err := API(request)1805 if err != nil {1806 fmt.Println(err)1807 }1808 if response.StatusCode != 201 {1809 t.Error("Wrong status code returned")1810 }1811}1812func Test_test_mail_batch__batch_id__get(t *testing.T) {1813 apiKey := "SENDGRID_APIKEY"1814 host := "http://localhost:4010"1815 request := GetRequest(apiKey, "/v3/mail/batch/{batch_id}", host)1816 request.Method = "GET"1817 request.Headers["X-Mock"] = "200"1818 response, err := API(request)1819 if err != nil {1820 fmt.Println(err)1821 }1822 if response.StatusCode != 200 {1823 t.Error("Wrong status code returned")1824 }1825}1826func Test_test_mail_send_post(t *testing.T) {1827 apiKey := "SENDGRID_APIKEY"1828 host := "http://localhost:4010"1829 request := GetRequest(apiKey, "/v3/mail/send", host)1830 request.Method = "POST"1831 request.Body = []byte(` {1832 "asm": {1833 "group_id": 1,1834 "groups_to_display": [1835 1,1836 2,1837 31838 ]1839 },1840 "attachments": [1841 {1842 "content": "[BASE64 encoded content block here]",1843 "content_id": "ii_139db99fdb5c3704",1844 "disposition": "inline",1845 "filename": "file1.jpg",1846 "name": "file1",1847 "type": "jpg"1848 }1849 ],1850 "batch_id": "[YOUR BATCH ID GOES HERE]",1851 "categories": [1852 "category1",1853 "category2"1854 ],1855 "content": [1856 {1857 "type": "text/html",1858 "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"1859 }1860 ],1861 "custom_args": {1862 "New Argument 1": "New Value 1",1863 "activationAttempt": "1",1864 "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"1865 },1866 "from": {1867 "email": "sam.smith@example.com",1868 "name": "Sam Smith"1869 },1870 "headers": {},1871 "ip_pool_name": "[YOUR POOL NAME GOES HERE]",1872 "mail_settings": {1873 "bcc": {1874 "email": "ben.doe@example.com",1875 "enable": true1876 },1877 "bypass_list_management": {1878 "enable": true1879 },1880 "footer": {1881 "enable": true,1882 "html": "<p>Thanks</br>The SendGrid Team</p>",1883 "text": "Thanks,/n The SendGrid Team"1884 },1885 "sandbox_mode": {1886 "enable": false1887 },1888 "spam_check": {1889 "enable": true,1890 "post_to_url": "http://example.com/compliance",1891 "threshold": 31892 }1893 },1894 "personalizations": [1895 {1896 "bcc": [1897 {1898 "email": "sam.doe@example.com",1899 "name": "Sam Doe"1900 }1901 ],1902 "cc": [1903 {1904 "email": "jane.doe@example.com",1905 "name": "Jane Doe"1906 }1907 ],1908 "custom_args": {1909 "New Argument 1": "New Value 1",1910 "activationAttempt": "1",1911 "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"1912 },1913 "headers": {1914 "X-Accept-Language": "en",1915 "X-Mailer": "MyApp"1916 },1917 "send_at": 1409348513,1918 "subject": "Hello, World!",1919 "substitutions": {1920 "id": "substitutions",1921 "type": "object"1922 },1923 "to": [1924 {1925 "email": "john.doe@example.com",1926 "name": "John Doe"1927 }1928 ]1929 }1930 ],1931 "reply_to": {1932 "email": "sam.smith@example.com",1933 "name": "Sam Smith"1934 },1935 "sections": {1936 "section": {1937 ":sectionName1": "section 1 text",1938 ":sectionName2": "section 2 text"1939 }1940 },1941 "send_at": 1409348513,1942 "subject": "Hello, World!",1943 "template_id": "[YOUR TEMPLATE ID GOES HERE]",1944 "tracking_settings": {1945 "click_tracking": {1946 "enable": true,1947 "enable_text": true1948 },1949 "ganalytics": {1950 "enable": true,1951 "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",1952 "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",1953 "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",1954 "utm_name": "[NAME OF YOUR CAMPAIGN]",1955 "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"1956 },1957 "open_tracking": {1958 "enable": true,1959 "substitution_tag": "%opentrack"1960 },1961 "subscription_tracking": {1962 "enable": true,1963 "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",1964 "substitution_tag": "<%click here%>",1965 "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."1966 }1967 }1968}`)1969 request.Headers["X-Mock"] = "202"1970 response, err := API(request)1971 if err != nil {1972 fmt.Println(err)1973 }1974 if response.StatusCode != 202 {1975 t.Error("Wrong status code returned")1976 }1977}1978func Test_test_mail_settings_get(t *testing.T) {1979 apiKey := "SENDGRID_APIKEY"1980 host := "http://localhost:4010"1981 request := GetRequest(apiKey, "/v3/mail_settings", host)1982 request.Method = "GET"1983 queryParams := make(map[string]string)1984 queryParams["limit"] = "1"1985 queryParams["offset"] = "1"1986 request.QueryParams = queryParams1987 request.Headers["X-Mock"] = "200"1988 response, err := API(request)1989 if err != nil {1990 fmt.Println(err)1991 }1992 if response.StatusCode != 200 {1993 t.Error("Wrong status code returned")1994 }1995}1996func Test_test_mail_settings_address_whitelist_patch(t *testing.T) {1997 apiKey := "SENDGRID_APIKEY"1998 host := "http://localhost:4010"1999 request := GetRequest(apiKey, "/v3/mail_settings/address_whitelist", host)2000 request.Method = "PATCH"2001 request.Body = []byte(` {2002 "enabled": true,2003 "list": [2004 "email1@example.com",2005 "example.com"2006 ]2007}`)2008 request.Headers["X-Mock"] = "200"2009 response, err := API(request)2010 if err != nil {2011 fmt.Println(err)2012 }2013 if response.StatusCode != 200 {2014 t.Error("Wrong status code returned")2015 }2016}2017func Test_test_mail_settings_address_whitelist_get(t *testing.T) {2018 apiKey := "SENDGRID_APIKEY"2019 host := "http://localhost:4010"2020 request := GetRequest(apiKey, "/v3/mail_settings/address_whitelist", host)2021 request.Method = "GET"2022 request.Headers["X-Mock"] = "200"2023 response, err := API(request)2024 if err != nil {2025 fmt.Println(err)2026 }2027 if response.StatusCode != 200 {2028 t.Error("Wrong status code returned")2029 }2030}2031func Test_test_mail_settings_bcc_patch(t *testing.T) {2032 apiKey := "SENDGRID_APIKEY"2033 host := "http://localhost:4010"2034 request := GetRequest(apiKey, "/v3/mail_settings/bcc", host)2035 request.Method = "PATCH"2036 request.Body = []byte(` {2037 "email": "email@example.com",2038 "enabled": false2039}`)2040 request.Headers["X-Mock"] = "200"2041 response, err := API(request)2042 if err != nil {2043 fmt.Println(err)2044 }2045 if response.StatusCode != 200 {2046 t.Error("Wrong status code returned")2047 }2048}2049func Test_test_mail_settings_bcc_get(t *testing.T) {2050 apiKey := "SENDGRID_APIKEY"2051 host := "http://localhost:4010"2052 request := GetRequest(apiKey, "/v3/mail_settings/bcc", host)2053 request.Method = "GET"2054 request.Headers["X-Mock"] = "200"2055 response, err := API(request)2056 if err != nil {2057 fmt.Println(err)2058 }2059 if response.StatusCode != 200 {2060 t.Error("Wrong status code returned")2061 }2062}2063func Test_test_mail_settings_bounce_purge_patch(t *testing.T) {2064 apiKey := "SENDGRID_APIKEY"2065 host := "http://localhost:4010"2066 request := GetRequest(apiKey, "/v3/mail_settings/bounce_purge", host)2067 request.Method = "PATCH"2068 request.Body = []byte(` {2069 "enabled": true,2070 "hard_bounces": 5,2071 "soft_bounces": 52072}`)2073 request.Headers["X-Mock"] = "200"2074 response, err := API(request)2075 if err != nil {2076 fmt.Println(err)2077 }2078 if response.StatusCode != 200 {2079 t.Error("Wrong status code returned")2080 }2081}2082func Test_test_mail_settings_bounce_purge_get(t *testing.T) {2083 apiKey := "SENDGRID_APIKEY"2084 host := "http://localhost:4010"2085 request := GetRequest(apiKey, "/v3/mail_settings/bounce_purge", host)2086 request.Method = "GET"2087 request.Headers["X-Mock"] = "200"2088 response, err := API(request)2089 if err != nil {2090 fmt.Println(err)2091 }2092 if response.StatusCode != 200 {2093 t.Error("Wrong status code returned")2094 }2095}2096func Test_test_mail_settings_footer_patch(t *testing.T) {2097 apiKey := "SENDGRID_APIKEY"2098 host := "http://localhost:4010"2099 request := GetRequest(apiKey, "/v3/mail_settings/footer", host)2100 request.Method = "PATCH"2101 request.Body = []byte(` {2102 "enabled": true,2103 "html_content": "...",2104 "plain_content": "..."2105}`)2106 request.Headers["X-Mock"] = "200"2107 response, err := API(request)2108 if err != nil {2109 fmt.Println(err)2110 }2111 if response.StatusCode != 200 {2112 t.Error("Wrong status code returned")2113 }2114}2115func Test_test_mail_settings_footer_get(t *testing.T) {2116 apiKey := "SENDGRID_APIKEY"2117 host := "http://localhost:4010"2118 request := GetRequest(apiKey, "/v3/mail_settings/footer", host)2119 request.Method = "GET"2120 request.Headers["X-Mock"] = "200"2121 response, err := API(request)2122 if err != nil {2123 fmt.Println(err)2124 }2125 if response.StatusCode != 200 {2126 t.Error("Wrong status code returned")2127 }2128}2129func Test_test_mail_settings_forward_bounce_patch(t *testing.T) {2130 apiKey := "SENDGRID_APIKEY"2131 host := "http://localhost:4010"2132 request := GetRequest(apiKey, "/v3/mail_settings/forward_bounce", host)2133 request.Method = "PATCH"2134 request.Body = []byte(` {2135 "email": "example@example.com",2136 "enabled": true2137}`)2138 request.Headers["X-Mock"] = "200"2139 response, err := API(request)2140 if err != nil {2141 fmt.Println(err)2142 }2143 if response.StatusCode != 200 {2144 t.Error("Wrong status code returned")2145 }2146}2147func Test_test_mail_settings_forward_bounce_get(t *testing.T) {2148 apiKey := "SENDGRID_APIKEY"2149 host := "http://localhost:4010"2150 request := GetRequest(apiKey, "/v3/mail_settings/forward_bounce", host)2151 request.Method = "GET"2152 request.Headers["X-Mock"] = "200"2153 response, err := API(request)2154 if err != nil {2155 fmt.Println(err)2156 }2157 if response.StatusCode != 200 {2158 t.Error("Wrong status code returned")2159 }2160}2161func Test_test_mail_settings_forward_spam_patch(t *testing.T) {2162 apiKey := "SENDGRID_APIKEY"2163 host := "http://localhost:4010"2164 request := GetRequest(apiKey, "/v3/mail_settings/forward_spam", host)2165 request.Method = "PATCH"2166 request.Body = []byte(` {2167 "email": "",2168 "enabled": false2169}`)2170 request.Headers["X-Mock"] = "200"2171 response, err := API(request)2172 if err != nil {2173 fmt.Println(err)2174 }2175 if response.StatusCode != 200 {2176 t.Error("Wrong status code returned")2177 }2178}2179func Test_test_mail_settings_forward_spam_get(t *testing.T) {2180 apiKey := "SENDGRID_APIKEY"2181 host := "http://localhost:4010"2182 request := GetRequest(apiKey, "/v3/mail_settings/forward_spam", host)2183 request.Method = "GET"2184 request.Headers["X-Mock"] = "200"2185 response, err := API(request)2186 if err != nil {2187 fmt.Println(err)2188 }2189 if response.StatusCode != 200 {2190 t.Error("Wrong status code returned")2191 }2192}2193func Test_test_mail_settings_plain_content_patch(t *testing.T) {2194 apiKey := "SENDGRID_APIKEY"2195 host := "http://localhost:4010"2196 request := GetRequest(apiKey, "/v3/mail_settings/plain_content", host)2197 request.Method = "PATCH"2198 request.Body = []byte(` {2199 "enabled": false2200}`)2201 request.Headers["X-Mock"] = "200"2202 response, err := API(request)2203 if err != nil {2204 fmt.Println(err)2205 }2206 if response.StatusCode != 200 {2207 t.Error("Wrong status code returned")2208 }2209}2210func Test_test_mail_settings_plain_content_get(t *testing.T) {2211 apiKey := "SENDGRID_APIKEY"2212 host := "http://localhost:4010"2213 request := GetRequest(apiKey, "/v3/mail_settings/plain_content", host)2214 request.Method = "GET"2215 request.Headers["X-Mock"] = "200"2216 response, err := API(request)2217 if err != nil {2218 fmt.Println(err)2219 }2220 if response.StatusCode != 200 {2221 t.Error("Wrong status code returned")2222 }2223}2224func Test_test_mail_settings_spam_check_patch(t *testing.T) {2225 apiKey := "SENDGRID_APIKEY"2226 host := "http://localhost:4010"2227 request := GetRequest(apiKey, "/v3/mail_settings/spam_check", host)2228 request.Method = "PATCH"2229 request.Body = []byte(` {2230 "enabled": true,2231 "max_score": 5,2232 "url": "url"2233}`)2234 request.Headers["X-Mock"] = "200"2235 response, err := API(request)2236 if err != nil {2237 fmt.Println(err)2238 }2239 if response.StatusCode != 200 {2240 t.Error("Wrong status code returned")2241 }2242}2243func Test_test_mail_settings_spam_check_get(t *testing.T) {2244 apiKey := "SENDGRID_APIKEY"2245 host := "http://localhost:4010"2246 request := GetRequest(apiKey, "/v3/mail_settings/spam_check", host)2247 request.Method = "GET"2248 request.Headers["X-Mock"] = "200"2249 response, err := API(request)2250 if err != nil {2251 fmt.Println(err)2252 }2253 if response.StatusCode != 200 {2254 t.Error("Wrong status code returned")2255 }2256}2257func Test_test_mail_settings_template_patch(t *testing.T) {2258 apiKey := "SENDGRID_APIKEY"2259 host := "http://localhost:4010"2260 request := GetRequest(apiKey, "/v3/mail_settings/template", host)2261 request.Method = "PATCH"2262 request.Body = []byte(` {2263 "enabled": true,2264 "html_content": "<% body %>"2265}`)2266 request.Headers["X-Mock"] = "200"2267 response, err := API(request)2268 if err != nil {2269 fmt.Println(err)2270 }2271 if response.StatusCode != 200 {2272 t.Error("Wrong status code returned")2273 }2274}2275func Test_test_mail_settings_template_get(t *testing.T) {2276 apiKey := "SENDGRID_APIKEY"2277 host := "http://localhost:4010"2278 request := GetRequest(apiKey, "/v3/mail_settings/template", host)2279 request.Method = "GET"2280 request.Headers["X-Mock"] = "200"2281 response, err := API(request)2282 if err != nil {2283 fmt.Println(err)2284 }2285 if response.StatusCode != 200 {2286 t.Error("Wrong status code returned")2287 }2288}2289func Test_test_mailbox_providers_stats_get(t *testing.T) {2290 apiKey := "SENDGRID_APIKEY"2291 host := "http://localhost:4010"2292 request := GetRequest(apiKey, "/v3/mailbox_providers/stats", host)2293 request.Method = "GET"2294 queryParams := make(map[string]string)2295 queryParams["end_date"] = "2016-04-01"2296 queryParams["mailbox_providers"] = "test_string"2297 queryParams["aggregated_by"] = "day"2298 queryParams["limit"] = "1"2299 queryParams["offset"] = "1"2300 queryParams["start_date"] = "2016-01-01"2301 request.QueryParams = queryParams2302 request.Headers["X-Mock"] = "200"2303 response, err := API(request)2304 if err != nil {2305 fmt.Println(err)2306 }2307 if response.StatusCode != 200 {2308 t.Error("Wrong status code returned")2309 }2310}2311func Test_test_partner_settings_get(t *testing.T) {2312 apiKey := "SENDGRID_APIKEY"2313 host := "http://localhost:4010"2314 request := GetRequest(apiKey, "/v3/partner_settings", host)2315 request.Method = "GET"2316 queryParams := make(map[string]string)2317 queryParams["limit"] = "1"2318 queryParams["offset"] = "1"2319 request.QueryParams = queryParams2320 request.Headers["X-Mock"] = "200"2321 response, err := API(request)2322 if err != nil {2323 fmt.Println(err)2324 }2325 if response.StatusCode != 200 {2326 t.Error("Wrong status code returned")2327 }2328}2329func Test_test_partner_settings_new_relic_patch(t *testing.T) {2330 apiKey := "SENDGRID_APIKEY"2331 host := "http://localhost:4010"2332 request := GetRequest(apiKey, "/v3/partner_settings/new_relic", host)2333 request.Method = "PATCH"2334 request.Body = []byte(` {2335 "enable_subuser_statistics": true,2336 "enabled": true,2337 "license_key": ""2338}`)2339 request.Headers["X-Mock"] = "200"2340 response, err := API(request)2341 if err != nil {2342 fmt.Println(err)2343 }2344 if response.StatusCode != 200 {2345 t.Error("Wrong status code returned")2346 }2347}2348func Test_test_partner_settings_new_relic_get(t *testing.T) {2349 apiKey := "SENDGRID_APIKEY"2350 host := "http://localhost:4010"2351 request := GetRequest(apiKey, "/v3/partner_settings/new_relic", host)2352 request.Method = "GET"2353 request.Headers["X-Mock"] = "200"2354 response, err := API(request)2355 if err != nil {2356 fmt.Println(err)2357 }2358 if response.StatusCode != 200 {2359 t.Error("Wrong status code returned")2360 }2361}2362func Test_test_scopes_get(t *testing.T) {2363 apiKey := "SENDGRID_APIKEY"2364 host := "http://localhost:4010"2365 request := GetRequest(apiKey, "/v3/scopes", host)2366 request.Method = "GET"2367 request.Headers["X-Mock"] = "200"2368 response, err := API(request)2369 if err != nil {2370 fmt.Println(err)2371 }2372 if response.StatusCode != 200 {2373 t.Error("Wrong status code returned")2374 }2375}2376func Test_test_senders_post(t *testing.T) {2377 apiKey := "SENDGRID_APIKEY"2378 host := "http://localhost:4010"2379 request := GetRequest(apiKey, "/v3/senders", host)2380 request.Method = "POST"2381 request.Body = []byte(` {2382 "address": "123 Elm St.",2383 "address_2": "Apt. 456",2384 "city": "Denver",2385 "country": "United States",2386 "from": {2387 "email": "from@example.com",2388 "name": "Example INC"2389 },2390 "nickname": "My Sender ID",2391 "reply_to": {2392 "email": "replyto@example.com",2393 "name": "Example INC"2394 },2395 "state": "Colorado",2396 "zip": "80202"2397}`)2398 request.Headers["X-Mock"] = "201"2399 response, err := API(request)2400 if err != nil {2401 fmt.Println(err)2402 }2403 if response.StatusCode != 201 {2404 t.Error("Wrong status code returned")2405 }2406}2407func Test_test_senders_get(t *testing.T) {2408 apiKey := "SENDGRID_APIKEY"2409 host := "http://localhost:4010"2410 request := GetRequest(apiKey, "/v3/senders", host)2411 request.Method = "GET"2412 request.Headers["X-Mock"] = "200"2413 response, err := API(request)2414 if err != nil {2415 fmt.Println(err)2416 }2417 if response.StatusCode != 200 {2418 t.Error("Wrong status code returned")2419 }2420}2421func Test_test_senders__sender_id__patch(t *testing.T) {2422 apiKey := "SENDGRID_APIKEY"2423 host := "http://localhost:4010"2424 request := GetRequest(apiKey, "/v3/senders/{sender_id}", host)2425 request.Method = "PATCH"2426 request.Body = []byte(` {2427 "address": "123 Elm St.",2428 "address_2": "Apt. 456",2429 "city": "Denver",2430 "country": "United States",2431 "from": {2432 "email": "from@example.com",2433 "name": "Example INC"2434 },2435 "nickname": "My Sender ID",2436 "reply_to": {2437 "email": "replyto@example.com",2438 "name": "Example INC"2439 },2440 "state": "Colorado",2441 "zip": "80202"2442}`)2443 request.Headers["X-Mock"] = "200"2444 response, err := API(request)2445 if err != nil {2446 fmt.Println(err)2447 }2448 if response.StatusCode != 200 {2449 t.Error("Wrong status code returned")2450 }2451}2452func Test_test_senders__sender_id__get(t *testing.T) {2453 apiKey := "SENDGRID_APIKEY"2454 host := "http://localhost:4010"2455 request := GetRequest(apiKey, "/v3/senders/{sender_id}", host)2456 request.Method = "GET"2457 request.Headers["X-Mock"] = "200"2458 response, err := API(request)2459 if err != nil {2460 fmt.Println(err)2461 }2462 if response.StatusCode != 200 {2463 t.Error("Wrong status code returned")2464 }2465}2466func Test_test_senders__sender_id__delete(t *testing.T) {2467 apiKey := "SENDGRID_APIKEY"2468 host := "http://localhost:4010"2469 request := GetRequest(apiKey, "/v3/senders/{sender_id}", host)2470 request.Method = "DELETE"2471 request.Headers["X-Mock"] = "204"2472 response, err := API(request)2473 if err != nil {2474 fmt.Println(err)2475 }2476 if response.StatusCode != 204 {2477 t.Error("Wrong status code returned")2478 }2479}2480func Test_test_senders__sender_id__resend_verification_post(t *testing.T) {2481 apiKey := "SENDGRID_APIKEY"2482 host := "http://localhost:4010"2483 request := GetRequest(apiKey, "/v3/senders/{sender_id}/resend_verification", host)2484 request.Method = "POST"2485 request.Headers["X-Mock"] = "204"2486 response, err := API(request)2487 if err != nil {2488 fmt.Println(err)2489 }2490 if response.StatusCode != 204 {2491 t.Error("Wrong status code returned")2492 }2493}2494func Test_test_stats_get(t *testing.T) {2495 apiKey := "SENDGRID_APIKEY"2496 host := "http://localhost:4010"2497 request := GetRequest(apiKey, "/v3/stats", host)2498 request.Method = "GET"2499 queryParams := make(map[string]string)2500 queryParams["aggregated_by"] = "day"2501 queryParams["limit"] = "1"2502 queryParams["start_date"] = "2016-01-01"2503 queryParams["end_date"] = "2016-04-01"2504 queryParams["offset"] = "1"2505 request.QueryParams = queryParams2506 request.Headers["X-Mock"] = "200"2507 response, err := API(request)2508 if err != nil {2509 fmt.Println(err)2510 }2511 if response.StatusCode != 200 {2512 t.Error("Wrong status code returned")2513 }2514}2515func Test_test_subusers_post(t *testing.T) {2516 apiKey := "SENDGRID_APIKEY"2517 host := "http://localhost:4010"2518 request := GetRequest(apiKey, "/v3/subusers", host)2519 request.Method = "POST"2520 request.Body = []byte(` {2521 "email": "John@example.com",2522 "ips": [2523 "1.1.1.1",2524 "2.2.2.2"2525 ],2526 "password": "johns_password",2527 "username": "John@example.com"2528}`)2529 request.Headers["X-Mock"] = "200"2530 response, err := API(request)2531 if err != nil {2532 fmt.Println(err)2533 }2534 if response.StatusCode != 200 {2535 t.Error("Wrong status code returned")2536 }2537}2538func Test_test_subusers_get(t *testing.T) {2539 apiKey := "SENDGRID_APIKEY"2540 host := "http://localhost:4010"2541 request := GetRequest(apiKey, "/v3/subusers", host)2542 request.Method = "GET"2543 queryParams := make(map[string]string)2544 queryParams["username"] = "test_string"2545 queryParams["limit"] = "1"2546 queryParams["offset"] = "1"2547 request.QueryParams = queryParams2548 request.Headers["X-Mock"] = "200"2549 response, err := API(request)2550 if err != nil {2551 fmt.Println(err)2552 }2553 if response.StatusCode != 200 {2554 t.Error("Wrong status code returned")2555 }2556}2557func Test_test_subusers_reputations_get(t *testing.T) {2558 apiKey := "SENDGRID_APIKEY"2559 host := "http://localhost:4010"2560 request := GetRequest(apiKey, "/v3/subusers/reputations", host)2561 request.Method = "GET"2562 queryParams := make(map[string]string)2563 queryParams["usernames"] = "test_string"2564 request.QueryParams = queryParams2565 request.Headers["X-Mock"] = "200"2566 response, err := API(request)2567 if err != nil {2568 fmt.Println(err)2569 }2570 if response.StatusCode != 200 {2571 t.Error("Wrong status code returned")2572 }2573}2574func Test_test_subusers_stats_get(t *testing.T) {2575 apiKey := "SENDGRID_APIKEY"2576 host := "http://localhost:4010"2577 request := GetRequest(apiKey, "/v3/subusers/stats", host)2578 request.Method = "GET"2579 queryParams := make(map[string]string)2580 queryParams["end_date"] = "2016-04-01"2581 queryParams["aggregated_by"] = "day"2582 queryParams["limit"] = "1"2583 queryParams["offset"] = "1"2584 queryParams["start_date"] = "2016-01-01"2585 queryParams["subusers"] = "test_string"2586 request.QueryParams = queryParams2587 request.Headers["X-Mock"] = "200"2588 response, err := API(request)2589 if err != nil {2590 fmt.Println(err)2591 }2592 if response.StatusCode != 200 {2593 t.Error("Wrong status code returned")2594 }2595}2596func Test_test_subusers_stats_monthly_get(t *testing.T) {2597 apiKey := "SENDGRID_APIKEY"2598 host := "http://localhost:4010"2599 request := GetRequest(apiKey, "/v3/subusers/stats/monthly", host)2600 request.Method = "GET"2601 queryParams := make(map[string]string)2602 queryParams["subuser"] = "test_string"2603 queryParams["limit"] = "1"2604 queryParams["sort_by_metric"] = "test_string"2605 queryParams["offset"] = "1"2606 queryParams["date"] = "test_string"2607 queryParams["sort_by_direction"] = "asc"2608 request.QueryParams = queryParams2609 request.Headers["X-Mock"] = "200"2610 response, err := API(request)2611 if err != nil {2612 fmt.Println(err)2613 }2614 if response.StatusCode != 200 {2615 t.Error("Wrong status code returned")2616 }2617}2618func Test_test_subusers_stats_sums_get(t *testing.T) {2619 apiKey := "SENDGRID_APIKEY"2620 host := "http://localhost:4010"2621 request := GetRequest(apiKey, "/v3/subusers/stats/sums", host)2622 request.Method = "GET"2623 queryParams := make(map[string]string)2624 queryParams["end_date"] = "2016-04-01"2625 queryParams["aggregated_by"] = "day"2626 queryParams["limit"] = "1"2627 queryParams["sort_by_metric"] = "test_string"2628 queryParams["offset"] = "1"2629 queryParams["start_date"] = "2016-01-01"2630 queryParams["sort_by_direction"] = "asc"2631 request.QueryParams = queryParams2632 request.Headers["X-Mock"] = "200"2633 response, err := API(request)2634 if err != nil {2635 fmt.Println(err)2636 }2637 if response.StatusCode != 200 {2638 t.Error("Wrong status code returned")2639 }2640}2641func Test_test_subusers__subuser_name__patch(t *testing.T) {2642 apiKey := "SENDGRID_APIKEY"2643 host := "http://localhost:4010"2644 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}", host)2645 request.Method = "PATCH"2646 request.Body = []byte(` {2647 "disabled": false2648}`)2649 request.Headers["X-Mock"] = "204"2650 response, err := API(request)2651 if err != nil {2652 fmt.Println(err)2653 }2654 if response.StatusCode != 204 {2655 t.Error("Wrong status code returned")2656 }2657}2658func Test_test_subusers__subuser_name__delete(t *testing.T) {2659 apiKey := "SENDGRID_APIKEY"2660 host := "http://localhost:4010"2661 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}", host)2662 request.Method = "DELETE"2663 request.Headers["X-Mock"] = "204"2664 response, err := API(request)2665 if err != nil {2666 fmt.Println(err)2667 }2668 if response.StatusCode != 204 {2669 t.Error("Wrong status code returned")2670 }2671}2672func Test_test_subusers__subuser_name__ips_put(t *testing.T) {2673 apiKey := "SENDGRID_APIKEY"2674 host := "http://localhost:4010"2675 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/ips", host)2676 request.Method = "PUT"2677 request.Body = []byte(` [2678 "127.0.0.1"2679]`)2680 request.Headers["X-Mock"] = "200"2681 response, err := API(request)2682 if err != nil {2683 fmt.Println(err)2684 }2685 if response.StatusCode != 200 {2686 t.Error("Wrong status code returned")2687 }2688}2689func Test_test_subusers__subuser_name__monitor_put(t *testing.T) {2690 apiKey := "SENDGRID_APIKEY"2691 host := "http://localhost:4010"2692 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/monitor", host)2693 request.Method = "PUT"2694 request.Body = []byte(` {2695 "email": "example@example.com",2696 "frequency": 5002697}`)2698 request.Headers["X-Mock"] = "200"2699 response, err := API(request)2700 if err != nil {2701 fmt.Println(err)2702 }2703 if response.StatusCode != 200 {2704 t.Error("Wrong status code returned")2705 }2706}2707func Test_test_subusers__subuser_name__monitor_post(t *testing.T) {2708 apiKey := "SENDGRID_APIKEY"2709 host := "http://localhost:4010"2710 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/monitor", host)2711 request.Method = "POST"2712 request.Body = []byte(` {2713 "email": "example@example.com",2714 "frequency": 500002715}`)2716 request.Headers["X-Mock"] = "200"2717 response, err := API(request)2718 if err != nil {2719 fmt.Println(err)2720 }2721 if response.StatusCode != 200 {2722 t.Error("Wrong status code returned")2723 }2724}2725func Test_test_subusers__subuser_name__monitor_get(t *testing.T) {2726 apiKey := "SENDGRID_APIKEY"2727 host := "http://localhost:4010"2728 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/monitor", host)2729 request.Method = "GET"2730 request.Headers["X-Mock"] = "200"2731 response, err := API(request)2732 if err != nil {2733 fmt.Println(err)2734 }2735 if response.StatusCode != 200 {2736 t.Error("Wrong status code returned")2737 }2738}2739func Test_test_subusers__subuser_name__monitor_delete(t *testing.T) {2740 apiKey := "SENDGRID_APIKEY"2741 host := "http://localhost:4010"2742 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/monitor", host)2743 request.Method = "DELETE"2744 request.Headers["X-Mock"] = "204"2745 response, err := API(request)2746 if err != nil {2747 fmt.Println(err)2748 }2749 if response.StatusCode != 204 {2750 t.Error("Wrong status code returned")2751 }2752}2753func Test_test_subusers__subuser_name__stats_monthly_get(t *testing.T) {2754 apiKey := "SENDGRID_APIKEY"2755 host := "http://localhost:4010"2756 request := GetRequest(apiKey, "/v3/subusers/{subuser_name}/stats/monthly", host)2757 request.Method = "GET"2758 queryParams := make(map[string]string)2759 queryParams["date"] = "test_string"2760 queryParams["sort_by_direction"] = "asc"2761 queryParams["limit"] = "1"2762 queryParams["sort_by_metric"] = "test_string"2763 queryParams["offset"] = "1"2764 request.QueryParams = queryParams2765 request.Headers["X-Mock"] = "200"2766 response, err := API(request)2767 if err != nil {2768 fmt.Println(err)2769 }2770 if response.StatusCode != 200 {2771 t.Error("Wrong status code returned")2772 }2773}2774func Test_test_suppression_blocks_get(t *testing.T) {2775 apiKey := "SENDGRID_APIKEY"2776 host := "http://localhost:4010"2777 request := GetRequest(apiKey, "/v3/suppression/blocks", host)2778 request.Method = "GET"2779 queryParams := make(map[string]string)2780 queryParams["start_time"] = "1"2781 queryParams["limit"] = "1"2782 queryParams["end_time"] = "1"2783 queryParams["offset"] = "1"2784 request.QueryParams = queryParams2785 request.Headers["X-Mock"] = "200"2786 response, err := API(request)2787 if err != nil {2788 fmt.Println(err)2789 }2790 if response.StatusCode != 200 {2791 t.Error("Wrong status code returned")2792 }2793}2794func Test_test_suppression_blocks_delete(t *testing.T) {2795 apiKey := "SENDGRID_APIKEY"2796 host := "http://localhost:4010"2797 request := GetRequest(apiKey, "/v3/suppression/blocks", host)2798 request.Method = "DELETE"2799 request.Body = []byte(` {2800 "delete_all": false,2801 "emails": [2802 "example1@example.com",2803 "example2@example.com"2804 ]2805}`)2806 request.Headers["X-Mock"] = "204"2807 response, err := API(request)2808 if err != nil {2809 fmt.Println(err)2810 }2811 if response.StatusCode != 204 {2812 t.Error("Wrong status code returned")2813 }2814}2815func Test_test_suppression_blocks__email__get(t *testing.T) {2816 apiKey := "SENDGRID_APIKEY"2817 host := "http://localhost:4010"2818 request := GetRequest(apiKey, "/v3/suppression/blocks/{email}", host)2819 request.Method = "GET"2820 request.Headers["X-Mock"] = "200"2821 response, err := API(request)2822 if err != nil {2823 fmt.Println(err)2824 }2825 if response.StatusCode != 200 {2826 t.Error("Wrong status code returned")2827 }2828}2829func Test_test_suppression_blocks__email__delete(t *testing.T) {2830 apiKey := "SENDGRID_APIKEY"2831 host := "http://localhost:4010"2832 request := GetRequest(apiKey, "/v3/suppression/blocks/{email}", host)2833 request.Method = "DELETE"2834 request.Headers["X-Mock"] = "204"2835 response, err := API(request)2836 if err != nil {2837 fmt.Println(err)2838 }2839 if response.StatusCode != 204 {2840 t.Error("Wrong status code returned")2841 }2842}2843func Test_test_suppression_bounces_get(t *testing.T) {2844 apiKey := "SENDGRID_APIKEY"2845 host := "http://localhost:4010"2846 request := GetRequest(apiKey, "/v3/suppression/bounces", host)2847 request.Method = "GET"2848 queryParams := make(map[string]string)2849 queryParams["start_time"] = "1"2850 queryParams["end_time"] = "1"2851 request.QueryParams = queryParams2852 request.Headers["X-Mock"] = "200"2853 response, err := API(request)2854 if err != nil {2855 fmt.Println(err)2856 }2857 if response.StatusCode != 200 {2858 t.Error("Wrong status code returned")2859 }2860}2861func Test_test_suppression_bounces_delete(t *testing.T) {2862 apiKey := "SENDGRID_APIKEY"2863 host := "http://localhost:4010"2864 request := GetRequest(apiKey, "/v3/suppression/bounces", host)2865 request.Method = "DELETE"2866 request.Body = []byte(` {2867 "delete_all": true,2868 "emails": [2869 "example@example.com",2870 "example2@example.com"2871 ]2872}`)2873 request.Headers["X-Mock"] = "204"2874 response, err := API(request)2875 if err != nil {2876 fmt.Println(err)2877 }2878 if response.StatusCode != 204 {2879 t.Error("Wrong status code returned")2880 }2881}2882func Test_test_suppression_bounces__email__get(t *testing.T) {2883 apiKey := "SENDGRID_APIKEY"2884 host := "http://localhost:4010"2885 request := GetRequest(apiKey, "/v3/suppression/bounces/{email}", host)2886 request.Method = "GET"2887 request.Headers["X-Mock"] = "200"2888 response, err := API(request)2889 if err != nil {2890 fmt.Println(err)2891 }2892 if response.StatusCode != 200 {2893 t.Error("Wrong status code returned")2894 }2895}2896func Test_test_suppression_bounces__email__delete(t *testing.T) {2897 apiKey := "SENDGRID_APIKEY"2898 host := "http://localhost:4010"2899 request := GetRequest(apiKey, "/v3/suppression/bounces/{email}", host)2900 request.Method = "DELETE"2901 queryParams := make(map[string]string)2902 queryParams["email_address"] = "example@example.com"2903 request.QueryParams = queryParams2904 request.Headers["X-Mock"] = "204"2905 response, err := API(request)2906 if err != nil {2907 fmt.Println(err)2908 }2909 if response.StatusCode != 204 {2910 t.Error("Wrong status code returned")2911 }2912}2913func Test_test_suppression_invalid_emails_get(t *testing.T) {2914 apiKey := "SENDGRID_APIKEY"2915 host := "http://localhost:4010"2916 request := GetRequest(apiKey, "/v3/suppression/invalid_emails", host)2917 request.Method = "GET"2918 queryParams := make(map[string]string)2919 queryParams["start_time"] = "1"2920 queryParams["limit"] = "1"2921 queryParams["end_time"] = "1"2922 queryParams["offset"] = "1"2923 request.QueryParams = queryParams2924 request.Headers["X-Mock"] = "200"2925 response, err := API(request)2926 if err != nil {2927 fmt.Println(err)2928 }2929 if response.StatusCode != 200 {2930 t.Error("Wrong status code returned")2931 }2932}2933func Test_test_suppression_invalid_emails_delete(t *testing.T) {2934 apiKey := "SENDGRID_APIKEY"2935 host := "http://localhost:4010"2936 request := GetRequest(apiKey, "/v3/suppression/invalid_emails", host)2937 request.Method = "DELETE"2938 request.Body = []byte(` {2939 "delete_all": false,2940 "emails": [2941 "example1@example.com",2942 "example2@example.com"2943 ]2944}`)2945 request.Headers["X-Mock"] = "204"2946 response, err := API(request)2947 if err != nil {2948 fmt.Println(err)2949 }2950 if response.StatusCode != 204 {2951 t.Error("Wrong status code returned")2952 }2953}2954func Test_test_suppression_invalid_emails__email__get(t *testing.T) {2955 apiKey := "SENDGRID_APIKEY"2956 host := "http://localhost:4010"2957 request := GetRequest(apiKey, "/v3/suppression/invalid_emails/{email}", host)2958 request.Method = "GET"2959 request.Headers["X-Mock"] = "200"2960 response, err := API(request)2961 if err != nil {2962 fmt.Println(err)2963 }2964 if response.StatusCode != 200 {2965 t.Error("Wrong status code returned")2966 }2967}2968func Test_test_suppression_invalid_emails__email__delete(t *testing.T) {2969 apiKey := "SENDGRID_APIKEY"2970 host := "http://localhost:4010"2971 request := GetRequest(apiKey, "/v3/suppression/invalid_emails/{email}", host)2972 request.Method = "DELETE"2973 request.Headers["X-Mock"] = "204"2974 response, err := API(request)2975 if err != nil {2976 fmt.Println(err)2977 }2978 if response.StatusCode != 204 {2979 t.Error("Wrong status code returned")2980 }2981}2982func Test_test_suppression_spam_report__email__get(t *testing.T) {2983 apiKey := "SENDGRID_APIKEY"2984 host := "http://localhost:4010"2985 request := GetRequest(apiKey, "/v3/suppression/spam_report/{email}", host)2986 request.Method = "GET"2987 request.Headers["X-Mock"] = "200"2988 response, err := API(request)2989 if err != nil {2990 fmt.Println(err)2991 }2992 if response.StatusCode != 200 {2993 t.Error("Wrong status code returned")2994 }2995}2996func Test_test_suppression_spam_report__email__delete(t *testing.T) {2997 apiKey := "SENDGRID_APIKEY"2998 host := "http://localhost:4010"2999 request := GetRequest(apiKey, "/v3/suppression/spam_report/{email}", host)3000 request.Method = "DELETE"3001 request.Headers["X-Mock"] = "204"3002 response, err := API(request)3003 if err != nil {3004 fmt.Println(err)3005 }3006 if response.StatusCode != 204 {3007 t.Error("Wrong status code returned")3008 }3009}3010func Test_test_suppression_spam_reports_get(t *testing.T) {3011 apiKey := "SENDGRID_APIKEY"3012 host := "http://localhost:4010"3013 request := GetRequest(apiKey, "/v3/suppression/spam_reports", host)3014 request.Method = "GET"3015 queryParams := make(map[string]string)3016 queryParams["start_time"] = "1"3017 queryParams["limit"] = "1"3018 queryParams["end_time"] = "1"3019 queryParams["offset"] = "1"3020 request.QueryParams = queryParams3021 request.Headers["X-Mock"] = "200"3022 response, err := API(request)3023 if err != nil {3024 fmt.Println(err)3025 }3026 if response.StatusCode != 200 {3027 t.Error("Wrong status code returned")3028 }3029}3030func Test_test_suppression_spam_reports_delete(t *testing.T) {3031 apiKey := "SENDGRID_APIKEY"3032 host := "http://localhost:4010"3033 request := GetRequest(apiKey, "/v3/suppression/spam_reports", host)3034 request.Method = "DELETE"3035 request.Body = []byte(` {3036 "delete_all": false,3037 "emails": [3038 "example1@example.com",3039 "example2@example.com"3040 ]3041}`)3042 request.Headers["X-Mock"] = "204"3043 response, err := API(request)3044 if err != nil {3045 fmt.Println(err)3046 }3047 if response.StatusCode != 204 {3048 t.Error("Wrong status code returned")3049 }3050}3051func Test_test_suppression_unsubscribes_get(t *testing.T) {3052 apiKey := "SENDGRID_APIKEY"3053 host := "http://localhost:4010"3054 request := GetRequest(apiKey, "/v3/suppression/unsubscribes", host)3055 request.Method = "GET"3056 queryParams := make(map[string]string)3057 queryParams["start_time"] = "1"3058 queryParams["limit"] = "1"3059 queryParams["end_time"] = "1"3060 queryParams["offset"] = "1"3061 request.QueryParams = queryParams3062 request.Headers["X-Mock"] = "200"3063 response, err := API(request)3064 if err != nil {3065 fmt.Println(err)3066 }3067 if response.StatusCode != 200 {3068 t.Error("Wrong status code returned")3069 }3070}3071func Test_test_templates_post(t *testing.T) {3072 apiKey := "SENDGRID_APIKEY"3073 host := "http://localhost:4010"3074 request := GetRequest(apiKey, "/v3/templates", host)3075 request.Method = "POST"3076 request.Body = []byte(` {3077 "name": "example_name"3078}`)3079 request.Headers["X-Mock"] = "201"3080 response, err := API(request)3081 if err != nil {3082 fmt.Println(err)3083 }3084 if response.StatusCode != 201 {3085 t.Error("Wrong status code returned")3086 }3087}3088func Test_test_templates_get(t *testing.T) {3089 apiKey := "SENDGRID_APIKEY"3090 host := "http://localhost:4010"3091 request := GetRequest(apiKey, "/v3/templates", host)3092 request.Method = "GET"3093 request.Headers["X-Mock"] = "200"3094 response, err := API(request)3095 if err != nil {3096 fmt.Println(err)3097 }3098 if response.StatusCode != 200 {3099 t.Error("Wrong status code returned")3100 }3101}3102func Test_test_templates__template_id__patch(t *testing.T) {3103 apiKey := "SENDGRID_APIKEY"3104 host := "http://localhost:4010"3105 request := GetRequest(apiKey, "/v3/templates/{template_id}", host)3106 request.Method = "PATCH"3107 request.Body = []byte(` {3108 "name": "new_example_name"3109}`)3110 request.Headers["X-Mock"] = "200"3111 response, err := API(request)3112 if err != nil {3113 fmt.Println(err)3114 }3115 if response.StatusCode != 200 {3116 t.Error("Wrong status code returned")3117 }3118}3119func Test_test_templates__template_id__get(t *testing.T) {3120 apiKey := "SENDGRID_APIKEY"3121 host := "http://localhost:4010"3122 request := GetRequest(apiKey, "/v3/templates/{template_id}", host)3123 request.Method = "GET"3124 request.Headers["X-Mock"] = "200"3125 response, err := API(request)3126 if err != nil {3127 fmt.Println(err)3128 }3129 if response.StatusCode != 200 {3130 t.Error("Wrong status code returned")3131 }3132}3133func Test_test_templates__template_id__delete(t *testing.T) {3134 apiKey := "SENDGRID_APIKEY"3135 host := "http://localhost:4010"3136 request := GetRequest(apiKey, "/v3/templates/{template_id}", host)3137 request.Method = "DELETE"3138 request.Headers["X-Mock"] = "204"3139 response, err := API(request)3140 if err != nil {3141 fmt.Println(err)3142 }3143 if response.StatusCode != 204 {3144 t.Error("Wrong status code returned")3145 }3146}3147func Test_test_templates__template_id__versions_post(t *testing.T) {3148 apiKey := "SENDGRID_APIKEY"3149 host := "http://localhost:4010"3150 request := GetRequest(apiKey, "/v3/templates/{template_id}/versions", host)3151 request.Method = "POST"3152 request.Body = []byte(` {3153 "active": 1,3154 "html_content": "<%body%>",3155 "name": "example_version_name",3156 "plain_content": "<%body%>",3157 "subject": "<%subject%>",3158 "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"3159}`)3160 request.Headers["X-Mock"] = "201"3161 response, err := API(request)3162 if err != nil {3163 fmt.Println(err)3164 }3165 if response.StatusCode != 201 {3166 t.Error("Wrong status code returned")3167 }3168}3169func Test_test_templates__template_id__versions__version_id__patch(t *testing.T) {3170 apiKey := "SENDGRID_APIKEY"3171 host := "http://localhost:4010"3172 request := GetRequest(apiKey, "/v3/templates/{template_id}/versions/{version_id}", host)3173 request.Method = "PATCH"3174 request.Body = []byte(` {3175 "active": 1,3176 "html_content": "<%body%>",3177 "name": "updated_example_name",3178 "plain_content": "<%body%>",3179 "subject": "<%subject%>"3180}`)3181 request.Headers["X-Mock"] = "200"3182 response, err := API(request)3183 if err != nil {3184 fmt.Println(err)3185 }3186 if response.StatusCode != 200 {3187 t.Error("Wrong status code returned")3188 }3189}3190func Test_test_templates__template_id__versions__version_id__get(t *testing.T) {3191 apiKey := "SENDGRID_APIKEY"3192 host := "http://localhost:4010"3193 request := GetRequest(apiKey, "/v3/templates/{template_id}/versions/{version_id}", host)3194 request.Method = "GET"3195 request.Headers["X-Mock"] = "200"3196 response, err := API(request)3197 if err != nil {3198 fmt.Println(err)3199 }3200 if response.StatusCode != 200 {3201 t.Error("Wrong status code returned")3202 }3203}3204func Test_test_templates__template_id__versions__version_id__delete(t *testing.T) {3205 apiKey := "SENDGRID_APIKEY"3206 host := "http://localhost:4010"3207 request := GetRequest(apiKey, "/v3/templates/{template_id}/versions/{version_id}", host)3208 request.Method = "DELETE"3209 request.Headers["X-Mock"] = "204"3210 response, err := API(request)3211 if err != nil {3212 fmt.Println(err)3213 }3214 if response.StatusCode != 204 {3215 t.Error("Wrong status code returned")3216 }3217}3218func Test_test_templates__template_id__versions__version_id__activate_post(t *testing.T) {3219 apiKey := "SENDGRID_APIKEY"3220 host := "http://localhost:4010"3221 request := GetRequest(apiKey, "/v3/templates/{template_id}/versions/{version_id}/activate", host)3222 request.Method = "POST"3223 request.Headers["X-Mock"] = "200"3224 response, err := API(request)3225 if err != nil {3226 fmt.Println(err)3227 }3228 if response.StatusCode != 200 {3229 t.Error("Wrong status code returned")3230 }3231}3232func Test_test_tracking_settings_get(t *testing.T) {3233 apiKey := "SENDGRID_APIKEY"3234 host := "http://localhost:4010"3235 request := GetRequest(apiKey, "/v3/tracking_settings", host)3236 request.Method = "GET"3237 queryParams := make(map[string]string)3238 queryParams["limit"] = "1"3239 queryParams["offset"] = "1"3240 request.QueryParams = queryParams3241 request.Headers["X-Mock"] = "200"3242 response, err := API(request)3243 if err != nil {3244 fmt.Println(err)3245 }3246 if response.StatusCode != 200 {3247 t.Error("Wrong status code returned")3248 }3249}3250func Test_test_tracking_settings_click_patch(t *testing.T) {3251 apiKey := "SENDGRID_APIKEY"3252 host := "http://localhost:4010"3253 request := GetRequest(apiKey, "/v3/tracking_settings/click", host)3254 request.Method = "PATCH"3255 request.Body = []byte(` {3256 "enabled": true3257}`)3258 request.Headers["X-Mock"] = "200"3259 response, err := API(request)3260 if err != nil {3261 fmt.Println(err)3262 }3263 if response.StatusCode != 200 {3264 t.Error("Wrong status code returned")3265 }3266}3267func Test_test_tracking_settings_click_get(t *testing.T) {3268 apiKey := "SENDGRID_APIKEY"3269 host := "http://localhost:4010"3270 request := GetRequest(apiKey, "/v3/tracking_settings/click", host)3271 request.Method = "GET"3272 request.Headers["X-Mock"] = "200"3273 response, err := API(request)3274 if err != nil {3275 fmt.Println(err)3276 }3277 if response.StatusCode != 200 {3278 t.Error("Wrong status code returned")3279 }3280}3281func Test_test_tracking_settings_google_analytics_patch(t *testing.T) {3282 apiKey := "SENDGRID_APIKEY"3283 host := "http://localhost:4010"3284 request := GetRequest(apiKey, "/v3/tracking_settings/google_analytics", host)3285 request.Method = "PATCH"3286 request.Body = []byte(` {3287 "enabled": true,3288 "utm_campaign": "website",3289 "utm_content": "",3290 "utm_medium": "email",3291 "utm_source": "sendgrid.com",3292 "utm_term": ""3293}`)3294 request.Headers["X-Mock"] = "200"3295 response, err := API(request)3296 if err != nil {3297 fmt.Println(err)3298 }3299 if response.StatusCode != 200 {3300 t.Error("Wrong status code returned")3301 }3302}3303func Test_test_tracking_settings_google_analytics_get(t *testing.T) {3304 apiKey := "SENDGRID_APIKEY"3305 host := "http://localhost:4010"3306 request := GetRequest(apiKey, "/v3/tracking_settings/google_analytics", host)3307 request.Method = "GET"3308 request.Headers["X-Mock"] = "200"3309 response, err := API(request)3310 if err != nil {3311 fmt.Println(err)3312 }3313 if response.StatusCode != 200 {3314 t.Error("Wrong status code returned")3315 }3316}3317func Test_test_tracking_settings_open_patch(t *testing.T) {3318 apiKey := "SENDGRID_APIKEY"3319 host := "http://localhost:4010"3320 request := GetRequest(apiKey, "/v3/tracking_settings/open", host)3321 request.Method = "PATCH"3322 request.Body = []byte(` {3323 "enabled": true3324}`)3325 request.Headers["X-Mock"] = "200"3326 response, err := API(request)3327 if err != nil {3328 fmt.Println(err)3329 }3330 if response.StatusCode != 200 {3331 t.Error("Wrong status code returned")3332 }3333}3334func Test_test_tracking_settings_open_get(t *testing.T) {3335 apiKey := "SENDGRID_APIKEY"3336 host := "http://localhost:4010"3337 request := GetRequest(apiKey, "/v3/tracking_settings/open", host)3338 request.Method = "GET"3339 request.Headers["X-Mock"] = "200"3340 response, err := API(request)3341 if err != nil {3342 fmt.Println(err)3343 }3344 if response.StatusCode != 200 {3345 t.Error("Wrong status code returned")3346 }3347}3348func Test_test_tracking_settings_subscription_patch(t *testing.T) {3349 apiKey := "SENDGRID_APIKEY"3350 host := "http://localhost:4010"3351 request := GetRequest(apiKey, "/v3/tracking_settings/subscription", host)3352 request.Method = "PATCH"3353 request.Body = []byte(` {3354 "enabled": true,3355 "html_content": "html content",3356 "landing": "landing page html",3357 "plain_content": "text content",3358 "replace": "replacement tag",3359 "url": "url"3360}`)3361 request.Headers["X-Mock"] = "200"3362 response, err := API(request)3363 if err != nil {3364 fmt.Println(err)3365 }3366 if response.StatusCode != 200 {3367 t.Error("Wrong status code returned")3368 }3369}3370func Test_test_tracking_settings_subscription_get(t *testing.T) {3371 apiKey := "SENDGRID_APIKEY"3372 host := "http://localhost:4010"3373 request := GetRequest(apiKey, "/v3/tracking_settings/subscription", host)3374 request.Method = "GET"3375 request.Headers["X-Mock"] = "200"3376 response, err := API(request)3377 if err != nil {3378 fmt.Println(err)3379 }3380 if response.StatusCode != 200 {3381 t.Error("Wrong status code returned")3382 }3383}3384func Test_test_user_account_get(t *testing.T) {3385 apiKey := "SENDGRID_APIKEY"3386 host := "http://localhost:4010"3387 request := GetRequest(apiKey, "/v3/user/account", host)3388 request.Method = "GET"3389 request.Headers["X-Mock"] = "200"3390 response, err := API(request)3391 if err != nil {3392 fmt.Println(err)3393 }3394 if response.StatusCode != 200 {3395 t.Error("Wrong status code returned")3396 }3397}3398func Test_test_user_credits_get(t *testing.T) {3399 apiKey := "SENDGRID_APIKEY"3400 host := "http://localhost:4010"3401 request := GetRequest(apiKey, "/v3/user/credits", host)3402 request.Method = "GET"3403 request.Headers["X-Mock"] = "200"3404 response, err := API(request)3405 if err != nil {3406 fmt.Println(err)3407 }3408 if response.StatusCode != 200 {3409 t.Error("Wrong status code returned")3410 }3411}3412func Test_test_user_email_put(t *testing.T) {3413 apiKey := "SENDGRID_APIKEY"3414 host := "http://localhost:4010"3415 request := GetRequest(apiKey, "/v3/user/email", host)3416 request.Method = "PUT"3417 request.Body = []byte(` {3418 "email": "example@example.com"3419}`)3420 request.Headers["X-Mock"] = "200"3421 response, err := API(request)3422 if err != nil {3423 fmt.Println(err)3424 }3425 if response.StatusCode != 200 {3426 t.Error("Wrong status code returned")3427 }3428}3429func Test_test_user_email_get(t *testing.T) {3430 apiKey := "SENDGRID_APIKEY"3431 host := "http://localhost:4010"3432 request := GetRequest(apiKey, "/v3/user/email", host)3433 request.Method = "GET"3434 request.Headers["X-Mock"] = "200"3435 response, err := API(request)3436 if err != nil {3437 fmt.Println(err)3438 }3439 if response.StatusCode != 200 {3440 t.Error("Wrong status code returned")3441 }3442}3443func Test_test_user_password_put(t *testing.T) {3444 apiKey := "SENDGRID_APIKEY"3445 host := "http://localhost:4010"3446 request := GetRequest(apiKey, "/v3/user/password", host)3447 request.Method = "PUT"3448 request.Body = []byte(` {3449 "new_password": "new_password",3450 "old_password": "old_password"3451}`)3452 request.Headers["X-Mock"] = "200"3453 response, err := API(request)3454 if err != nil {3455 fmt.Println(err)3456 }3457 if response.StatusCode != 200 {3458 t.Error("Wrong status code returned")3459 }3460}3461func Test_test_user_profile_patch(t *testing.T) {3462 apiKey := "SENDGRID_APIKEY"3463 host := "http://localhost:4010"3464 request := GetRequest(apiKey, "/v3/user/profile", host)3465 request.Method = "PATCH"3466 request.Body = []byte(` {3467 "city": "Orange",3468 "first_name": "Example",3469 "last_name": "User"3470}`)3471 request.Headers["X-Mock"] = "200"3472 response, err := API(request)3473 if err != nil {3474 fmt.Println(err)3475 }3476 if response.StatusCode != 200 {3477 t.Error("Wrong status code returned")3478 }3479}3480func Test_test_user_profile_get(t *testing.T) {3481 apiKey := "SENDGRID_APIKEY"3482 host := "http://localhost:4010"3483 request := GetRequest(apiKey, "/v3/user/profile", host)3484 request.Method = "GET"3485 request.Headers["X-Mock"] = "200"3486 response, err := API(request)3487 if err != nil {3488 fmt.Println(err)3489 }3490 if response.StatusCode != 200 {3491 t.Error("Wrong status code returned")3492 }3493}3494func Test_test_user_scheduled_sends_post(t *testing.T) {3495 apiKey := "SENDGRID_APIKEY"3496 host := "http://localhost:4010"3497 request := GetRequest(apiKey, "/v3/user/scheduled_sends", host)3498 request.Method = "POST"3499 request.Body = []byte(` {3500 "batch_id": "YOUR_BATCH_ID",3501 "status": "pause"3502}`)3503 request.Headers["X-Mock"] = "201"3504 response, err := API(request)3505 if err != nil {3506 fmt.Println(err)3507 }3508 if response.StatusCode != 201 {3509 t.Error("Wrong status code returned")3510 }3511}3512func Test_test_user_scheduled_sends_get(t *testing.T) {3513 apiKey := "SENDGRID_APIKEY"3514 host := "http://localhost:4010"3515 request := GetRequest(apiKey, "/v3/user/scheduled_sends", host)3516 request.Method = "GET"3517 request.Headers["X-Mock"] = "200"3518 response, err := API(request)3519 if err != nil {3520 fmt.Println(err)3521 }3522 if response.StatusCode != 200 {3523 t.Error("Wrong status code returned")3524 }3525}3526func Test_test_user_scheduled_sends__batch_id__patch(t *testing.T) {3527 apiKey := "SENDGRID_APIKEY"3528 host := "http://localhost:4010"3529 request := GetRequest(apiKey, "/v3/user/scheduled_sends/{batch_id}", host)3530 request.Method = "PATCH"3531 request.Body = []byte(` {3532 "status": "pause"3533}`)3534 request.Headers["X-Mock"] = "204"3535 response, err := API(request)3536 if err != nil {3537 fmt.Println(err)3538 }3539 if response.StatusCode != 204 {3540 t.Error("Wrong status code returned")3541 }3542}3543func Test_test_user_scheduled_sends__batch_id__get(t *testing.T) {3544 apiKey := "SENDGRID_APIKEY"3545 host := "http://localhost:4010"3546 request := GetRequest(apiKey, "/v3/user/scheduled_sends/{batch_id}", host)3547 request.Method = "GET"3548 request.Headers["X-Mock"] = "200"3549 response, err := API(request)3550 if err != nil {3551 fmt.Println(err)3552 }3553 if response.StatusCode != 200 {3554 t.Error("Wrong status code returned")3555 }3556}3557func Test_test_user_scheduled_sends__batch_id__delete(t *testing.T) {3558 apiKey := "SENDGRID_APIKEY"3559 host := "http://localhost:4010"3560 request := GetRequest(apiKey, "/v3/user/scheduled_sends/{batch_id}", host)3561 request.Method = "DELETE"3562 request.Headers["X-Mock"] = "204"3563 response, err := API(request)3564 if err != nil {3565 fmt.Println(err)3566 }3567 if response.StatusCode != 204 {3568 t.Error("Wrong status code returned")3569 }3570}3571func Test_test_user_settings_enforced_tls_patch(t *testing.T) {3572 apiKey := "SENDGRID_APIKEY"3573 host := "http://localhost:4010"3574 request := GetRequest(apiKey, "/v3/user/settings/enforced_tls", host)3575 request.Method = "PATCH"3576 request.Body = []byte(` {3577 "require_tls": true,3578 "require_valid_cert": false3579}`)3580 request.Headers["X-Mock"] = "200"3581 response, err := API(request)3582 if err != nil {3583 fmt.Println(err)3584 }3585 if response.StatusCode != 200 {3586 t.Error("Wrong status code returned")3587 }3588}3589func Test_test_user_settings_enforced_tls_get(t *testing.T) {3590 apiKey := "SENDGRID_APIKEY"3591 host := "http://localhost:4010"3592 request := GetRequest(apiKey, "/v3/user/settings/enforced_tls", host)3593 request.Method = "GET"3594 request.Headers["X-Mock"] = "200"3595 response, err := API(request)3596 if err != nil {3597 fmt.Println(err)3598 }3599 if response.StatusCode != 200 {3600 t.Error("Wrong status code returned")3601 }3602}3603func Test_test_user_username_put(t *testing.T) {3604 apiKey := "SENDGRID_APIKEY"3605 host := "http://localhost:4010"3606 request := GetRequest(apiKey, "/v3/user/username", host)3607 request.Method = "PUT"3608 request.Body = []byte(` {3609 "username": "test_username"3610}`)3611 request.Headers["X-Mock"] = "200"3612 response, err := API(request)3613 if err != nil {3614 fmt.Println(err)3615 }3616 if response.StatusCode != 200 {3617 t.Error("Wrong status code returned")3618 }3619}3620func Test_test_user_username_get(t *testing.T) {3621 apiKey := "SENDGRID_APIKEY"3622 host := "http://localhost:4010"3623 request := GetRequest(apiKey, "/v3/user/username", host)3624 request.Method = "GET"3625 request.Headers["X-Mock"] = "200"3626 response, err := API(request)3627 if err != nil {3628 fmt.Println(err)3629 }3630 if response.StatusCode != 200 {3631 t.Error("Wrong status code returned")3632 }3633}3634func Test_test_user_webhooks_event_settings_patch(t *testing.T) {3635 apiKey := "SENDGRID_APIKEY"3636 host := "http://localhost:4010"3637 request := GetRequest(apiKey, "/v3/user/webhooks/event/settings", host)3638 request.Method = "PATCH"3639 request.Body = []byte(` {3640 "bounce": true,3641 "click": true,3642 "deferred": true,3643 "delivered": true,3644 "dropped": true,3645 "enabled": true,3646 "group_resubscribe": true,3647 "group_unsubscribe": true,3648 "open": true,3649 "processed": true,3650 "spam_report": true,3651 "unsubscribe": true,3652 "url": "url"3653}`)3654 request.Headers["X-Mock"] = "200"3655 response, err := API(request)3656 if err != nil {3657 fmt.Println(err)3658 }3659 if response.StatusCode != 200 {3660 t.Error("Wrong status code returned")3661 }3662}3663func Test_test_user_webhooks_event_settings_get(t *testing.T) {3664 apiKey := "SENDGRID_APIKEY"3665 host := "http://localhost:4010"3666 request := GetRequest(apiKey, "/v3/user/webhooks/event/settings", host)3667 request.Method = "GET"3668 request.Headers["X-Mock"] = "200"3669 response, err := API(request)3670 if err != nil {3671 fmt.Println(err)3672 }3673 if response.StatusCode != 200 {3674 t.Error("Wrong status code returned")3675 }3676}3677func Test_test_user_webhooks_event_test_post(t *testing.T) {3678 apiKey := "SENDGRID_APIKEY"3679 host := "http://localhost:4010"3680 request := GetRequest(apiKey, "/v3/user/webhooks/event/test", host)3681 request.Method = "POST"3682 request.Body = []byte(` {3683 "url": "url"3684}`)3685 request.Headers["X-Mock"] = "204"3686 response, err := API(request)3687 if err != nil {3688 fmt.Println(err)3689 }3690 if response.StatusCode != 204 {3691 t.Error("Wrong status code returned")3692 }3693}3694func Test_test_user_webhooks_parse_settings_post(t *testing.T) {3695 apiKey := "SENDGRID_APIKEY"3696 host := "http://localhost:4010"3697 request := GetRequest(apiKey, "/v3/user/webhooks/parse/settings", host)3698 request.Method = "POST"3699 request.Body = []byte(` {3700 "hostname": "myhostname.com",3701 "send_raw": false,3702 "spam_check": true,3703 "url": "http://email.myhosthame.com"3704}`)3705 request.Headers["X-Mock"] = "201"3706 response, err := API(request)3707 if err != nil {3708 fmt.Println(err)3709 }3710 if response.StatusCode != 201 {3711 t.Error("Wrong status code returned")3712 }3713}3714func Test_test_user_webhooks_parse_settings_get(t *testing.T) {3715 apiKey := "SENDGRID_APIKEY"3716 host := "http://localhost:4010"3717 request := GetRequest(apiKey, "/v3/user/webhooks/parse/settings", host)3718 request.Method = "GET"3719 request.Headers["X-Mock"] = "200"3720 response, err := API(request)3721 if err != nil {3722 fmt.Println(err)3723 }3724 if response.StatusCode != 200 {3725 t.Error("Wrong status code returned")3726 }3727}3728func Test_test_user_webhooks_parse_settings__hostname__patch(t *testing.T) {3729 apiKey := "SENDGRID_APIKEY"3730 host := "http://localhost:4010"3731 request := GetRequest(apiKey, "/v3/user/webhooks/parse/settings/{hostname}", host)3732 request.Method = "PATCH"3733 request.Body = []byte(` {3734 "send_raw": true,3735 "spam_check": false,3736 "url": "http://newdomain.com/parse"3737}`)3738 request.Headers["X-Mock"] = "200"3739 response, err := API(request)3740 if err != nil {3741 fmt.Println(err)3742 }3743 if response.StatusCode != 200 {3744 t.Error("Wrong status code returned")3745 }3746}3747func Test_test_user_webhooks_parse_settings__hostname__get(t *testing.T) {3748 apiKey := "SENDGRID_APIKEY"3749 host := "http://localhost:4010"3750 request := GetRequest(apiKey, "/v3/user/webhooks/parse/settings/{hostname}", host)3751 request.Method = "GET"3752 request.Headers["X-Mock"] = "200"3753 response, err := API(request)3754 if err != nil {3755 fmt.Println(err)3756 }3757 if response.StatusCode != 200 {3758 t.Error("Wrong status code returned")3759 }3760}3761func Test_test_user_webhooks_parse_settings__hostname__delete(t *testing.T) {3762 apiKey := "SENDGRID_APIKEY"3763 host := "http://localhost:4010"3764 request := GetRequest(apiKey, "/v3/user/webhooks/parse/settings/{hostname}", host)3765 request.Method = "DELETE"3766 request.Headers["X-Mock"] = "204"3767 response, err := API(request)3768 if err != nil {3769 fmt.Println(err)3770 }3771 if response.StatusCode != 204 {3772 t.Error("Wrong status code returned")3773 }3774}3775func Test_test_user_webhooks_parse_stats_get(t *testing.T) {3776 apiKey := "SENDGRID_APIKEY"3777 host := "http://localhost:4010"3778 request := GetRequest(apiKey, "/v3/user/webhooks/parse/stats", host)3779 request.Method = "GET"3780 queryParams := make(map[string]string)3781 queryParams["aggregated_by"] = "day"3782 queryParams["limit"] = "test_string"3783 queryParams["start_date"] = "2016-01-01"3784 queryParams["end_date"] = "2016-04-01"3785 queryParams["offset"] = "test_string"3786 request.QueryParams = queryParams3787 request.Headers["X-Mock"] = "200"3788 response, err := API(request)3789 if err != nil {3790 fmt.Println(err)3791 }3792 if response.StatusCode != 200 {3793 t.Error("Wrong status code returned")3794 }3795}3796func Test_test_whitelabel_domains_post(t *testing.T) {3797 apiKey := "SENDGRID_APIKEY"3798 host := "http://localhost:4010"3799 request := GetRequest(apiKey, "/v3/whitelabel/domains", host)3800 request.Method = "POST"3801 request.Body = []byte(` {3802 "automatic_security": false,3803 "custom_spf": true,3804 "default": true,3805 "domain": "example.com",3806 "ips": [3807 "192.168.1.1",3808 "192.168.1.2"3809 ],3810 "subdomain": "news",3811 "username": "john@example.com"3812}`)3813 request.Headers["X-Mock"] = "201"3814 response, err := API(request)3815 if err != nil {3816 fmt.Println(err)3817 }3818 if response.StatusCode != 201 {3819 t.Error("Wrong status code returned")3820 }3821}3822func Test_test_whitelabel_domains_get(t *testing.T) {3823 apiKey := "SENDGRID_APIKEY"3824 host := "http://localhost:4010"3825 request := GetRequest(apiKey, "/v3/whitelabel/domains", host)3826 request.Method = "GET"3827 queryParams := make(map[string]string)3828 queryParams["username"] = "test_string"3829 queryParams["domain"] = "test_string"3830 queryParams["exclude_subusers"] = "true"3831 queryParams["limit"] = "1"3832 queryParams["offset"] = "1"3833 request.QueryParams = queryParams3834 request.Headers["X-Mock"] = "200"3835 response, err := API(request)3836 if err != nil {3837 fmt.Println(err)3838 }3839 if response.StatusCode != 200 {3840 t.Error("Wrong status code returned")3841 }3842}3843func Test_test_whitelabel_domains_default_get(t *testing.T) {3844 apiKey := "SENDGRID_APIKEY"3845 host := "http://localhost:4010"3846 request := GetRequest(apiKey, "/v3/whitelabel/domains/default", host)3847 request.Method = "GET"3848 request.Headers["X-Mock"] = "200"3849 response, err := API(request)3850 if err != nil {3851 fmt.Println(err)3852 }3853 if response.StatusCode != 200 {3854 t.Error("Wrong status code returned")3855 }3856}3857func Test_test_whitelabel_domains_subuser_get(t *testing.T) {3858 apiKey := "SENDGRID_APIKEY"3859 host := "http://localhost:4010"3860 request := GetRequest(apiKey, "/v3/whitelabel/domains/subuser", host)3861 request.Method = "GET"3862 request.Headers["X-Mock"] = "200"3863 response, err := API(request)3864 if err != nil {3865 fmt.Println(err)3866 }3867 if response.StatusCode != 200 {3868 t.Error("Wrong status code returned")3869 }3870}3871func Test_test_whitelabel_domains_subuser_delete(t *testing.T) {3872 apiKey := "SENDGRID_APIKEY"3873 host := "http://localhost:4010"3874 request := GetRequest(apiKey, "/v3/whitelabel/domains/subuser", host)3875 request.Method = "DELETE"3876 request.Headers["X-Mock"] = "204"3877 response, err := API(request)3878 if err != nil {3879 fmt.Println(err)3880 }3881 if response.StatusCode != 204 {3882 t.Error("Wrong status code returned")3883 }3884}3885func Test_test_whitelabel_domains__domain_id__patch(t *testing.T) {3886 apiKey := "SENDGRID_APIKEY"3887 host := "http://localhost:4010"3888 request := GetRequest(apiKey, "/v3/whitelabel/domains/{domain_id}", host)3889 request.Method = "PATCH"3890 request.Body = []byte(` {3891 "custom_spf": true,3892 "default": false3893}`)3894 request.Headers["X-Mock"] = "200"3895 response, err := API(request)3896 if err != nil {3897 fmt.Println(err)3898 }3899 if response.StatusCode != 200 {3900 t.Error("Wrong status code returned")3901 }3902}3903func Test_test_whitelabel_domains__domain_id__get(t *testing.T) {3904 apiKey := "SENDGRID_APIKEY"3905 host := "http://localhost:4010"3906 request := GetRequest(apiKey, "/v3/whitelabel/domains/{domain_id}", host)3907 request.Method = "GET"3908 request.Headers["X-Mock"] = "200"3909 response, err := API(request)3910 if err != nil {3911 fmt.Println(err)3912 }3913 if response.StatusCode != 200 {3914 t.Error("Wrong status code returned")3915 }3916}3917func Test_test_whitelabel_domains__domain_id__delete(t *testing.T) {3918 apiKey := "SENDGRID_APIKEY"3919 host := "http://localhost:4010"3920 request := GetRequest(apiKey, "/v3/whitelabel/domains/{domain_id}", host)3921 request.Method = "DELETE"3922 request.Headers["X-Mock"] = "204"3923 response, err := API(request)3924 if err != nil {3925 fmt.Println(err)3926 }3927 if response.StatusCode != 204 {3928 t.Error("Wrong status code returned")3929 }3930}3931func Test_test_whitelabel_domains__domain_id__subuser_post(t *testing.T) {3932 apiKey := "SENDGRID_APIKEY"3933 host := "http://localhost:4010"3934 request := GetRequest(apiKey, "/v3/whitelabel/domains/{domain_id}/subuser", host)3935 request.Method = "POST"3936 request.Body = []byte(` {3937 "username": "jane@example.com"3938}`)3939 request.Headers["X-Mock"] = "201"3940 response, err := API(request)3941 if err != nil {3942 fmt.Println(err)3943 }3944 if response.StatusCode != 201 {3945 t.Error("Wrong status code returned")3946 }3947}3948func Test_test_whitelabel_domains__id__ips_post(t *testing.T) {3949 apiKey := "SENDGRID_APIKEY"3950 host := "http://localhost:4010"3951 request := GetRequest(apiKey, "/v3/whitelabel/domains/{id}/ips", host)3952 request.Method = "POST"3953 request.Body = []byte(` {3954 "ip": "192.168.0.1"3955}`)3956 request.Headers["X-Mock"] = "200"3957 response, err := API(request)3958 if err != nil {3959 fmt.Println(err)3960 }3961 if response.StatusCode != 200 {3962 t.Error("Wrong status code returned")3963 }3964}3965func Test_test_whitelabel_domains__id__ips__ip__delete(t *testing.T) {3966 apiKey := "SENDGRID_APIKEY"3967 host := "http://localhost:4010"3968 request := GetRequest(apiKey, "/v3/whitelabel/domains/{id}/ips/{ip}", host)3969 request.Method = "DELETE"3970 request.Headers["X-Mock"] = "200"3971 response, err := API(request)3972 if err != nil {3973 fmt.Println(err)3974 }3975 if response.StatusCode != 200 {3976 t.Error("Wrong status code returned")3977 }3978}3979func Test_test_whitelabel_domains__id__validate_post(t *testing.T) {3980 apiKey := "SENDGRID_APIKEY"3981 host := "http://localhost:4010"3982 request := GetRequest(apiKey, "/v3/whitelabel/domains/{id}/validate", host)3983 request.Method = "POST"3984 request.Headers["X-Mock"] = "200"3985 response, err := API(request)3986 if err != nil {3987 fmt.Println(err)3988 }3989 if response.StatusCode != 200 {3990 t.Error("Wrong status code returned")3991 }3992}3993func Test_test_whitelabel_ips_post(t *testing.T) {3994 apiKey := "SENDGRID_APIKEY"3995 host := "http://localhost:4010"3996 request := GetRequest(apiKey, "/v3/whitelabel/ips", host)3997 request.Method = "POST"3998 request.Body = []byte(` {3999 "domain": "example.com",4000 "ip": "192.168.1.1",4001 "subdomain": "email"4002}`)4003 request.Headers["X-Mock"] = "201"4004 response, err := API(request)4005 if err != nil {4006 fmt.Println(err)4007 }4008 if response.StatusCode != 201 {4009 t.Error("Wrong status code returned")4010 }4011}4012func Test_test_whitelabel_ips_get(t *testing.T) {4013 apiKey := "SENDGRID_APIKEY"4014 host := "http://localhost:4010"4015 request := GetRequest(apiKey, "/v3/whitelabel/ips", host)4016 request.Method = "GET"4017 queryParams := make(map[string]string)4018 queryParams["ip"] = "test_string"4019 queryParams["limit"] = "1"4020 queryParams["offset"] = "1"4021 request.QueryParams = queryParams4022 request.Headers["X-Mock"] = "200"4023 response, err := API(request)4024 if err != nil {4025 fmt.Println(err)4026 }4027 if response.StatusCode != 200 {4028 t.Error("Wrong status code returned")4029 }4030}4031func Test_test_whitelabel_ips__id__get(t *testing.T) {4032 apiKey := "SENDGRID_APIKEY"4033 host := "http://localhost:4010"4034 request := GetRequest(apiKey, "/v3/whitelabel/ips/{id}", host)4035 request.Method = "GET"4036 request.Headers["X-Mock"] = "200"4037 response, err := API(request)4038 if err != nil {4039 fmt.Println(err)4040 }4041 if response.StatusCode != 200 {4042 t.Error("Wrong status code returned")4043 }4044}4045func Test_test_whitelabel_ips__id__delete(t *testing.T) {4046 apiKey := "SENDGRID_APIKEY"4047 host := "http://localhost:4010"4048 request := GetRequest(apiKey, "/v3/whitelabel/ips/{id}", host)4049 request.Method = "DELETE"4050 request.Headers["X-Mock"] = "204"4051 response, err := API(request)4052 if err != nil {4053 fmt.Println(err)4054 }4055 if response.StatusCode != 204 {4056 t.Error("Wrong status code returned")4057 }4058}4059func Test_test_whitelabel_ips__id__validate_post(t *testing.T) {4060 apiKey := "SENDGRID_APIKEY"4061 host := "http://localhost:4010"4062 request := GetRequest(apiKey, "/v3/whitelabel/ips/{id}/validate", host)4063 request.Method = "POST"4064 request.Headers["X-Mock"] = "200"4065 response, err := API(request)4066 if err != nil {4067 fmt.Println(err)4068 }4069 if response.StatusCode != 200 {4070 t.Error("Wrong status code returned")4071 }4072}4073func Test_test_whitelabel_links_post(t *testing.T) {4074 apiKey := "SENDGRID_APIKEY"4075 host := "http://localhost:4010"4076 request := GetRequest(apiKey, "/v3/whitelabel/links", host)4077 request.Method = "POST"4078 request.Body = []byte(` {4079 "default": true,4080 "domain": "example.com",4081 "subdomain": "mail"4082}`)4083 queryParams := make(map[string]string)4084 queryParams["limit"] = "1"4085 queryParams["offset"] = "1"4086 request.QueryParams = queryParams4087 request.Headers["X-Mock"] = "201"4088 response, err := API(request)4089 if err != nil {4090 fmt.Println(err)4091 }4092 if response.StatusCode != 201 {4093 t.Error("Wrong status code returned")4094 }4095}4096func Test_test_whitelabel_links_get(t *testing.T) {4097 apiKey := "SENDGRID_APIKEY"4098 host := "http://localhost:4010"4099 request := GetRequest(apiKey, "/v3/whitelabel/links", host)4100 request.Method = "GET"4101 queryParams := make(map[string]string)4102 queryParams["limit"] = "1"4103 request.QueryParams = queryParams4104 request.Headers["X-Mock"] = "200"4105 response, err := API(request)4106 if err != nil {4107 fmt.Println(err)4108 }4109 if response.StatusCode != 200 {4110 t.Error("Wrong status code returned")4111 }4112}4113func Test_test_whitelabel_links_default_get(t *testing.T) {4114 apiKey := "SENDGRID_APIKEY"4115 host := "http://localhost:4010"4116 request := GetRequest(apiKey, "/v3/whitelabel/links/default", host)4117 request.Method = "GET"4118 queryParams := make(map[string]string)4119 queryParams["domain"] = "test_string"4120 request.QueryParams = queryParams4121 request.Headers["X-Mock"] = "200"4122 response, err := API(request)4123 if err != nil {4124 fmt.Println(err)4125 }4126 if response.StatusCode != 200 {4127 t.Error("Wrong status code returned")4128 }4129}4130func Test_test_whitelabel_links_subuser_get(t *testing.T) {4131 apiKey := "SENDGRID_APIKEY"4132 host := "http://localhost:4010"4133 request := GetRequest(apiKey, "/v3/whitelabel/links/subuser", host)4134 request.Method = "GET"4135 queryParams := make(map[string]string)4136 queryParams["username"] = "test_string"4137 request.QueryParams = queryParams4138 request.Headers["X-Mock"] = "200"4139 response, err := API(request)4140 if err != nil {4141 fmt.Println(err)4142 }4143 if response.StatusCode != 200 {4144 t.Error("Wrong status code returned")4145 }4146}4147func Test_test_whitelabel_links_subuser_delete(t *testing.T) {4148 apiKey := "SENDGRID_APIKEY"4149 host := "http://localhost:4010"4150 request := GetRequest(apiKey, "/v3/whitelabel/links/subuser", host)4151 request.Method = "DELETE"4152 queryParams := make(map[string]string)4153 queryParams["username"] = "test_string"4154 request.QueryParams = queryParams4155 request.Headers["X-Mock"] = "204"4156 response, err := API(request)4157 if err != nil {4158 fmt.Println(err)4159 }4160 if response.StatusCode != 204 {4161 t.Error("Wrong status code returned")4162 }4163}4164func Test_test_whitelabel_links__id__patch(t *testing.T) {4165 apiKey := "SENDGRID_APIKEY"4166 host := "http://localhost:4010"4167 request := GetRequest(apiKey, "/v3/whitelabel/links/{id}", host)4168 request.Method = "PATCH"4169 request.Body = []byte(` {4170 "default": true4171}`)4172 request.Headers["X-Mock"] = "200"4173 response, err := API(request)4174 if err != nil {4175 fmt.Println(err)4176 }4177 if response.StatusCode != 200 {4178 t.Error("Wrong status code returned")4179 }4180}4181func Test_test_whitelabel_links__id__get(t *testing.T) {4182 apiKey := "SENDGRID_APIKEY"4183 host := "http://localhost:4010"4184 request := GetRequest(apiKey, "/v3/whitelabel/links/{id}", host)4185 request.Method = "GET"4186 request.Headers["X-Mock"] = "200"4187 response, err := API(request)4188 if err != nil {4189 fmt.Println(err)4190 }4191 if response.StatusCode != 200 {4192 t.Error("Wrong status code returned")4193 }4194}4195func Test_test_whitelabel_links__id__delete(t *testing.T) {4196 apiKey := "SENDGRID_APIKEY"4197 host := "http://localhost:4010"4198 request := GetRequest(apiKey, "/v3/whitelabel/links/{id}", host)4199 request.Method = "DELETE"4200 request.Headers["X-Mock"] = "204"4201 response, err := API(request)4202 if err != nil {4203 fmt.Println(err)4204 }4205 if response.StatusCode != 204 {4206 t.Error("Wrong status code returned")4207 }4208}4209func Test_test_whitelabel_links__id__validate_post(t *testing.T) {4210 apiKey := "SENDGRID_APIKEY"4211 host := "http://localhost:4010"4212 request := GetRequest(apiKey, "/v3/whitelabel/links/{id}/validate", host)4213 request.Method = "POST"4214 request.Headers["X-Mock"] = "200"4215 response, err := API(request)4216 if err != nil {4217 fmt.Println(err)4218 }4219 if response.StatusCode != 200 {4220 t.Error("Wrong status code returned")4221 }4222}4223func Test_test_whitelabel_links__link_id__subuser_post(t *testing.T) {4224 apiKey := "SENDGRID_APIKEY"4225 host := "http://localhost:4010"4226 request := GetRequest(apiKey, "/v3/whitelabel/links/{link_id}/subuser", host)4227 request.Method = "POST"4228 request.Body = []byte(` {4229 "username": "jane@example.com"4230}`)4231 request.Headers["X-Mock"] = "200"4232 response, err := API(request)4233 if err != nil {4234 fmt.Println(err)4235 }4236 if response.StatusCode != 200 {4237 t.Error("Wrong status code returned")4238 }4239}...

Full Screen

Full Screen

tracing_test.go

Source:tracing_test.go Github

copy

Full Screen

1package integration2import (3 "net/http"4 "os"5 "time"6 "github.com/go-check/check"7 "github.com/traefik/traefik/v2/integration/try"8 checker "github.com/vdemeester/shakers"9)10type TracingSuite struct {11 BaseSuite12 WhoAmiIP string13 WhoAmiPort int14 IP string15}16type TracingTemplate struct {17 WhoAmiIP string18 WhoAmiPort int19 IP string20 TraceContextHeaderName string21}22func (s *TracingSuite) SetUpSuite(c *check.C) {23 s.createComposeProject(c, "tracing")24 s.composeProject.Start(c, "whoami")25 s.WhoAmiIP = s.composeProject.Container(c, "whoami").NetworkSettings.IPAddress26 s.WhoAmiPort = 8027}28func (s *TracingSuite) startZipkin(c *check.C) {29 s.composeProject.Start(c, "zipkin")30 s.IP = s.composeProject.Container(c, "zipkin").NetworkSettings.IPAddress31 // Wait for Zipkin to turn ready.32 err := try.GetRequest("http://"+s.IP+":9411/api/v2/services", 20*time.Second, try.StatusCodeIs(http.StatusOK))33 c.Assert(err, checker.IsNil)34}35func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {36 s.startZipkin(c)37 defer s.composeProject.Stop(c, "zipkin")38 file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{39 WhoAmiIP: s.WhoAmiIP,40 WhoAmiPort: s.WhoAmiPort,41 IP: s.IP,42 })43 defer os.Remove(file)44 cmd, display := s.traefikCmd(withConfigFile(file))45 defer display(c)46 err := cmd.Start()47 c.Assert(err, checker.IsNil)48 defer s.killCmd(cmd)49 // wait for traefik50 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))51 c.Assert(err, checker.IsNil)52 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))53 c.Assert(err, checker.IsNil)54 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))55 c.Assert(err, checker.IsNil)56 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))57 c.Assert(err, checker.IsNil)58 // sleep for 4 seconds to be certain the configured time period has elapsed59 // then test another request and verify a 200 status code60 time.Sleep(4 * time.Second)61 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))62 c.Assert(err, checker.IsNil)63 // continue requests at 3 second intervals to test the other rate limit time period64 time.Sleep(3 * time.Second)65 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))66 c.Assert(err, checker.IsNil)67 time.Sleep(3 * time.Second)68 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))69 c.Assert(err, checker.IsNil)70 time.Sleep(3 * time.Second)71 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))72 c.Assert(err, checker.IsNil)73 err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit-1@file"))74 c.Assert(err, checker.IsNil)75}76func (s *TracingSuite) TestZipkinRetry(c *check.C) {77 s.startZipkin(c)78 defer s.composeProject.Stop(c, "zipkin")79 file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{80 WhoAmiIP: s.WhoAmiIP,81 WhoAmiPort: 81,82 IP: s.IP,83 })84 defer os.Remove(file)85 cmd, display := s.traefikCmd(withConfigFile(file))86 defer display(c)87 err := cmd.Start()88 c.Assert(err, checker.IsNil)89 defer s.killCmd(cmd)90 // wait for traefik91 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))92 c.Assert(err, checker.IsNil)93 err = try.GetRequest("http://127.0.0.1:8000/retry", 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway))94 c.Assert(err, checker.IsNil)95 err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service2/router2@file", "retry@file"))96 c.Assert(err, checker.IsNil)97}98func (s *TracingSuite) TestZipkinAuth(c *check.C) {99 s.startZipkin(c)100 defer s.composeProject.Stop(c, "zipkin")101 file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{102 WhoAmiIP: s.WhoAmiIP,103 WhoAmiPort: s.WhoAmiPort,104 IP: s.IP,105 })106 defer os.Remove(file)107 cmd, display := s.traefikCmd(withConfigFile(file))108 defer display(c)109 err := cmd.Start()110 c.Assert(err, checker.IsNil)111 defer s.killCmd(cmd)112 // wait for traefik113 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))114 c.Assert(err, checker.IsNil)115 err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))116 c.Assert(err, checker.IsNil)117 err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("entrypoint web", "basic-auth@file"))118 c.Assert(err, checker.IsNil)119}120func (s *TracingSuite) startJaeger(c *check.C) {121 s.composeProject.Start(c, "jaeger")122 s.IP = s.composeProject.Container(c, "jaeger").NetworkSettings.IPAddress123 // Wait for Jaeger to turn ready.124 err := try.GetRequest("http://"+s.IP+":16686/api/services", 20*time.Second, try.StatusCodeIs(http.StatusOK))125 c.Assert(err, checker.IsNil)126}127func (s *TracingSuite) TestJaegerRateLimit(c *check.C) {128 s.startJaeger(c)129 defer s.composeProject.Stop(c, "jaeger")130 file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{131 WhoAmiIP: s.WhoAmiIP,132 WhoAmiPort: s.WhoAmiPort,133 IP: s.IP,134 TraceContextHeaderName: "uber-trace-id",135 })136 defer os.Remove(file)137 cmd, display := s.traefikCmd(withConfigFile(file))138 defer display(c)139 err := cmd.Start()140 c.Assert(err, checker.IsNil)141 defer s.killCmd(cmd)142 // wait for traefik143 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))144 c.Assert(err, checker.IsNil)145 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))146 c.Assert(err, checker.IsNil)147 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))148 c.Assert(err, checker.IsNil)149 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))150 c.Assert(err, checker.IsNil)151 // sleep for 4 seconds to be certain the configured time period has elapsed152 // then test another request and verify a 200 status code153 time.Sleep(4 * time.Second)154 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))155 c.Assert(err, checker.IsNil)156 // continue requests at 3 second intervals to test the other rate limit time period157 time.Sleep(3 * time.Second)158 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))159 c.Assert(err, checker.IsNil)160 time.Sleep(3 * time.Second)161 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))162 c.Assert(err, checker.IsNil)163 err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))164 c.Assert(err, checker.IsNil)165 err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit-1@file"))166 c.Assert(err, checker.IsNil)167}168func (s *TracingSuite) TestJaegerRetry(c *check.C) {169 s.startJaeger(c)170 defer s.composeProject.Stop(c, "jaeger")171 file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{172 WhoAmiIP: s.WhoAmiIP,173 WhoAmiPort: 81,174 IP: s.IP,175 TraceContextHeaderName: "uber-trace-id",176 })177 defer os.Remove(file)178 cmd, display := s.traefikCmd(withConfigFile(file))179 defer display(c)180 err := cmd.Start()181 c.Assert(err, checker.IsNil)182 defer s.killCmd(cmd)183 // wait for traefik184 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))185 c.Assert(err, checker.IsNil)186 err = try.GetRequest("http://127.0.0.1:8000/retry", 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway))187 c.Assert(err, checker.IsNil)188 err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service2/router2@file", "retry@file"))189 c.Assert(err, checker.IsNil)190}191func (s *TracingSuite) TestJaegerAuth(c *check.C) {192 s.startJaeger(c)193 defer s.composeProject.Stop(c, "jaeger")194 file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{195 WhoAmiIP: s.WhoAmiIP,196 WhoAmiPort: s.WhoAmiPort,197 IP: s.IP,198 TraceContextHeaderName: "uber-trace-id",199 })200 defer os.Remove(file)201 cmd, display := s.traefikCmd(withConfigFile(file))202 defer display(c)203 err := cmd.Start()204 c.Assert(err, checker.IsNil)205 defer s.killCmd(cmd)206 // wait for traefik207 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))208 c.Assert(err, checker.IsNil)209 err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))210 c.Assert(err, checker.IsNil)211 err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("EntryPoint web", "basic-auth@file"))212 c.Assert(err, checker.IsNil)213}214func (s *TracingSuite) TestJaegerCustomHeader(c *check.C) {215 s.startJaeger(c)216 defer s.composeProject.Stop(c, "jaeger")217 file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{218 WhoAmiIP: s.WhoAmiIP,219 WhoAmiPort: s.WhoAmiPort,220 IP: s.IP,221 TraceContextHeaderName: "powpow",222 })223 defer os.Remove(file)224 cmd, display := s.traefikCmd(withConfigFile(file))225 defer display(c)226 err := cmd.Start()227 c.Assert(err, checker.IsNil)228 defer s.killCmd(cmd)229 // wait for traefik230 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))231 c.Assert(err, checker.IsNil)232 err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))233 c.Assert(err, checker.IsNil)234 err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("EntryPoint web", "basic-auth@file"))235 c.Assert(err, checker.IsNil)236}237func (s *TracingSuite) TestJaegerAuthCollector(c *check.C) {238 s.startJaeger(c)239 defer s.composeProject.Stop(c, "jaeger")240 file := s.adaptFile(c, "fixtures/tracing/simple-jaeger-collector.toml", TracingTemplate{241 WhoAmiIP: s.WhoAmiIP,242 WhoAmiPort: s.WhoAmiPort,243 IP: s.IP,244 })245 defer os.Remove(file)246 cmd, display := s.traefikCmd(withConfigFile(file))247 defer display(c)248 err := cmd.Start()249 c.Assert(err, checker.IsNil)250 defer s.killCmd(cmd)251 // wait for traefik252 err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))253 c.Assert(err, checker.IsNil)254 err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))255 c.Assert(err, checker.IsNil)256 err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("EntryPoint web", "basic-auth@file"))257 c.Assert(err, checker.IsNil)258}...

Full Screen

Full Screen

script_handlers_test.go

Source:script_handlers_test.go Github

copy

Full Screen

1package picker2import (3 "bytes"4 "net/http"5 "net/http/httptest"6 "os"7 "strings"8 "testing"9 "path"10 "google.golang.org/appengine/aetest"11)12func TestMain(m *testing.M) {13 startAppEngine()14 code := m.Run()15 os.Exit(code)16}17func startAppEngine() {18 inst, err := aetest.NewInstance(nil)19 if err != nil {20 panic(err)21 }22 defer inst.Close()23}24func TestGoChampionDropped(t *testing.T) {25 makeChampionDroppedCall("Aatrox", "team1pick1", http.StatusOK, "", t)26 makeChampionDroppedCall("Aatrox", "", http.StatusInternalServerError, "", t)27 makeChampionDroppedCall("", "team1pick1", http.StatusInternalServerError, "", t)28 jsonStr := "{\"champion_name\":\"Aatrox\"}"29 makeGoCall(jsonStr, "championDropped", http.StatusInternalServerError, "", t)30 jsonStr = "{\"droppable_name\":\"team1pick1\"}"31 makeGoCall(jsonStr, "championDropped", http.StatusInternalServerError, "", t)32 // No comma33 jsonStr = "{\"champion_name\":\"Aatrox\" \"droppable_name\":\"team1pick1\"}"34 makeGoCall(jsonStr, "championDropped", http.StatusInternalServerError, "", t)35 // A comma but no second field36 jsonStr = "{\"champion_name\":\"Aatrox\",}"37 makeGoCall(jsonStr, "championDropped", http.StatusInternalServerError, "", t)38 // No first field39 jsonStr = "{,\"droppable_name\":\"team1pick1\"}"40 makeGoCall(jsonStr, "championDropped", http.StatusInternalServerError, "", t)41}42func makeChampionDroppedCall(championName, droppableName string, expectedCode int, expectedString string, t *testing.T) {43 jsonStr := "{\"champion_name\":\"" + championName + "\", \"droppable_name\":\"" + droppableName + "\"}"44 makeGoCall(jsonStr, "championDropped", expectedCode, expectedString, t)45}46func TestBadGoScript(t *testing.T) {47 makeGETRequest("/scripts/go/someBadFunc", http.StatusNotFound, "", t)48}49func TestFileServingHandler(t *testing.T) {50 makeGETRequest("/scripts/js/champion_areas.js", http.StatusOK, "loadPortraits", t)51 makeGETRequest("/scripts/js/champion_areas.js/anotherdir", http.StatusNotFound, "", t)52 makeGETRequest("/scripts/js/champion_areas", http.StatusNotFound, "", t)53 makeGETRequest("/scripts/js/not_found", http.StatusNotFound, "", t)54 makeGETRequest("/scripts/js/", http.StatusOK, "champion_areas", t)55 makeGETRequest("/scripts/js", http.StatusNotFound, "", t)56 makeGETRequest("/", http.StatusOK, "Pick My Champion", t)57 makeGETRequest("/picker", http.StatusNotFound, "", t)58 makeGETRequest("/static/", http.StatusOK, "css", t)59 makeGETRequest("/static/css/", http.StatusOK, "picker", t)60 makeGETRequest("/static/css/notfound", http.StatusNotFound, "", t)61 makeGETRequest("/static/css/notfound.css", http.StatusNotFound, "", t)62 makeGETRequest("/static/css/picker.css", http.StatusOK, "championPortrait", t)63 makeGETRequest("/static/css/picker.css/anotherdir", http.StatusNotFound, "", t)64 makeGETRequest("/static/img/", http.StatusOK, "champion-portraits", t)65 makeGETRequest("/static/img/champion-portraits/", http.StatusOK, ".png", t)66 makeGETRequest("/static/img/champion-portraits/Aatrox.png", http.StatusOK, "", t)67}68func makeGETRequest(path string, expectedCode int, expectedString string, t *testing.T) {69 req, err := http.NewRequest("GET", path, nil)70 if err != nil {71 t.Errorf("Error making a request to %s: %s", path, err.Error())72 t.Fail()73 }74 rec := httptest.NewRecorder()75 r := makeRouter("../")76 r.ServeHTTP(rec, req)77 checkRecorder(expectedCode, expectedString, rec, t)78}79func TestGoListDirHandler(t *testing.T) {80 makeListDirCall("/static/img/champion-portraits/", http.StatusOK, "Aatrox", t)81 makeListDirCall("/static/img/", http.StatusOK, "champion-portraits", t)82 makeListDirCall("static/img/", http.StatusNotFound, "", t)83 makeListDirCall("/", http.StatusNotFound, "", t)84 makeListDirCall("/scripts", http.StatusNotFound, "", t)85 makeListDirCall("/path/to/unknown/dir", http.StatusNotFound, "", t)86 makeListDirCall("/static/img/badpath", http.StatusNotFound, "", t)87 makeListDirCall("/static/img/low/bad/subpath", http.StatusNotFound, "", t)88 makeListDirCall("/static/../../", http.StatusNotFound, "", t)89 makeListDirCall("/app.yaml", http.StatusNotFound, "", t)90 makeListDirCall("", http.StatusInternalServerError, "", t)91 // Test malformed JSON (missing ending })92 makeGoCall("{\"dir_path\":\"\"", "listDir", http.StatusInternalServerError, "", t)93 // Test malformed JSON (empty JSON)94 makeGoCall("{}", "listDir", http.StatusInternalServerError, "", t)95}96func makeListDirCall(path string, expectedCode int, expectedString string, t *testing.T) {97 jsonStr := "{\"dir_path\":\"" + path + "\"}"98 makeGoCall(jsonStr, "listDir", expectedCode, expectedString, t)99}100func makeGoCall(json, funcName string, expectedCode int, expectedString string, t *testing.T) {101 var jsonBytes = []byte(json)102 reqPath := path.Join("/scripts/go", funcName)103 req, err := http.NewRequest("POST", reqPath, bytes.NewBuffer(jsonBytes))104 req.Header.Add("content-type", "application/json")105 if err != nil {106 t.Errorf("Error making a request to /%s: %s", reqPath, err.Error())107 t.Fail()108 }109 rec := httptest.NewRecorder()110 r := makeRouter("../")111 r.ServeHTTP(rec, req)112 checkRecorder(expectedCode, expectedString, rec, t)113}114func checkReturnCode(expectedCode int, recorder *httptest.ResponseRecorder, t *testing.T) {115 if expectedCode != -1 && expectedCode != recorder.Code {116 t.Errorf("Received error code %s.", recorder.Code)117 t.Errorf("Received body: %s", recorder.Body)118 t.Fail()119 }120}121func checkBody(expectedString string, recorder *httptest.ResponseRecorder, t *testing.T) {122 buf := new(bytes.Buffer)123 buf.ReadFrom(recorder.Body)124 if expectedString != "" && !strings.Contains(buf.String(), expectedString) {125 t.Errorf("The body of the returned function did not contain an expected string (%s)", expectedString)126 t.Errorf("Received body: %s", recorder.Body)127 t.Fail()128 }129}130func checkRecorder(expectedCode int, expectedString string, recorder *httptest.ResponseRecorder, t *testing.T) {131 checkReturnCode(expectedCode, recorder, t)132 checkBody(expectedString, recorder, t)133}...

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 robots, err := ioutil.ReadAll(res.Body)7 res.Body.Close()8 if err != nil {9 panic(err)10 }11 fmt.Printf("%s", robots)12}13import (

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 defer resp.Body.Close()7 fmt.Println("Response status:", resp.Status)8 fmt.Println("Response headers:", resp.Header)9}10Response headers: map[Alt-Svc:[h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"], Cache-Control:[private, max-age=0], Content-Encoding:[gzip], Content-Type:[text/html; charset=ISO-8859-1], Date:[Sun, 07 Jul 2019 12:54:07 GMT], Expires:[-1], P3p:[CP="This is not a P3P policy! See g.co/p3p

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 defer resp.Body.Close()7 body, err := ioutil.ReadAll(resp.Body)8 if err != nil {9 panic(err)10 }11 fmt.Println(string(body))12}13import (14func main() {15 if err != nil {16 panic(err)17 }18 defer resp.Body.Close()19 body, err := ioutil.ReadAll(resp.Body)20 if err != nil {21 panic(err)22 }23 fmt.Println(string(body))24}25import (26func main() {27 client := &http.Client{}28 if err != nil {29 panic(err)30 }31 resp, err := client.Do(req)32 if err != nil {33 panic(err)34 }35 defer resp.Body.Close()36 body, err := ioutil.ReadAll(resp.Body)37 if err != nil {38 panic(err)39 }40 fmt.Println(string(body))41}42import (43func main() {44 client := &http.Client{}45 if err != nil {46 panic(err)47 }48 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")49 resp, err := client.Do(req)50 if err != nil {51 panic(err)52 }53 defer resp.Body.Close()54 body, err := ioutil.ReadAll(resp.Body)55 if err != nil {56 panic(err)57 }58 fmt.Println(string(body))59}60import (61func main() {62 client := &http.Client{}

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Printf("%s", err)5 } else {6 defer response.Body.Close()7 contents, err := ioutil.ReadAll(response.Body)8 if err != nil {9 fmt.Printf("%s", err)10 }11 fmt.Printf("%s12", string(contents))13 }14}15import (16func main() {17 data := url.Values{}18 data.Set("name", "John Doe")19 data.Add("email", "

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 fmt.Println(resp)7}8import (9func main() {10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(resp)14}15import (16func main() {17 if err != nil {18 fmt.Println(err)19 }20 fmt.Println(resp)21}22import (23func main() {24 if err != nil {25 fmt.Println(err)26 }27 fmt.Println(resp)28}29import (30func main() {31 if err != nil {32 fmt.Println(err)33 }34 client := &http.Client{}35 resp, err := client.Do(request)36 if err != nil {37 fmt.Println(err)38 }39 fmt.Println(resp)40}41import (42func main() {43 if err != nil {44 fmt.Println(err)45 }46 defer resp.Body.Close()47 body, err := ioutil.ReadAll(resp.Body)48 if err != nil {49 fmt.Println(err)50 }51 fmt.Println(string(body))52}53import (54func main() {

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := &http.Client{}4 if err != nil {5 log.Fatal(err)6 }7 resp, err := client.Do(req)8 if err != nil {9 log.Fatal(err)10 }11 defer resp.Body.Close()12 body, err := ioutil.ReadAll(resp.Body)13 if err != nil {14 log.Fatal(err)15 }16 fmt.Printf("%s17", string(body))18}19import (20func main() {21 client := &http.Client{}22 if err != nil {23 log.Fatal(err)24 }25 resp, err := client.Do(req)26 if err != nil {27 log.Fatal(err)28 }29 defer resp.Body.Close()30 body, err := ioutil.ReadAll(resp.Body)31 if err != nil {32 log.Fatal(err)33 }34 fmt.Printf("%s35", string(body))36}37import (38func main() {39 client := &http.Client{}

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 defer resp.Body.Close()7 body, err := ioutil.ReadAll(resp.Body)8 if err != nil {9 log.Fatal(err)10 }11 fmt.Printf("%s12}13import (14func main() {15 if err != nil {16 log.Fatal(err)17 }18 defer resp.Body.Close()19 body, err := ioutil.ReadAll(resp.Body)20 if err != nil {21 log.Fatal(err)22 }23 fmt.Printf("%s24}25import (26func main() {27 if err != nil {28 log.Fatal(err)29 }30 defer resp.Body.Close()31 body, err := ioutil.ReadAll(resp.Body)32 if err != nil {33 log.Fatal(err)34 }35 fmt.Printf("%s36}37import (38func main() {39 if err != nil {40 log.Fatal(err)41 }42 defer resp.Body.Close()43 body, err := ioutil.ReadAll(resp.Body)44 if err != nil {45 log.Fatal(err)46 }47 fmt.Printf("%s48}49import (50func main() {51 if err != nil {52 log.Fatal(err)53 }54 defer resp.Body.Close()

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 body, err := ioutil.ReadAll(res.Body)7 if err != nil {8 log.Fatal(err)9 }10 fmt.Printf("%s11}12import (13func main() {14 body := new(bytes.Buffer)15 body.Write([]byte("Hello World"))16 if err != nil {17 log.Fatal(err)18 }19 response, err := ioutil.ReadAll(res.Body)20 if err != nil {21 log.Fatal(err)22 }23 fmt.Printf("%s24}25import (26func main() {27 body := new(bytes.Buffer)28 body.Write([]byte("Hello World"))29 if err != nil {30 log.Fatal(err)31 }32 res, err := http.DefaultClient.Do(req)33 if err != nil {34 log.Fatal(err)35 }36 response, err := ioutil.ReadAll(res.Body)37 if err != nil {38 log.Fatal(err)39 }

Full Screen

Full Screen

getRequest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 robots, err := ioutil.ReadAll(resp.Body)7 resp.Body.Close()8 if err != nil {9 fmt.Println(err)10 }11 fmt.Printf("%s", robots)12}13import (14func main() {15 if err != nil {16 fmt.Println(err)17 }18 robots, err := ioutil.ReadAll(resp.Body)19 resp.Body.Close()20 if err != nil {21 fmt.Println(err)22 }23 fmt.Printf("%s", robots)24}25import (26func main() {27 if err != nil {28 fmt.Println(err)29 }30 robots, err := ioutil.ReadAll(resp.Body)31 resp.Body.Close()32 if err != nil {33 fmt.Println(err)34 }35 fmt.Printf("%s", robots)36}37import (38func main() {39 if err != nil {40 fmt.Println(err)41 }42 robots, err := ioutil.ReadAll(resp.Body)43 resp.Body.Close()44 if err != nil {45 fmt.Println(err)46 }47 fmt.Printf("%s", robots)48}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Venom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful