github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/request/method_test.go (about) 1 package main 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/gospider007/requests" 8 ) 9 10 func TestMethodGet(t *testing.T) { 11 resp, err := requests.Get(nil, "https://httpbin.org/anything") 12 if err != nil { 13 t.Fatal(err) 14 } 15 jsonData, err := resp.Json() 16 if err != nil { 17 t.Fatal(err) 18 } 19 if jsonData.Get("method").String() != http.MethodGet { 20 t.Fatal("method error") 21 } 22 } 23 func TestMethodPost(t *testing.T) { 24 resp, err := requests.Post(nil, "https://httpbin.org/anything") 25 if err != nil { 26 t.Fatal(err) 27 } 28 jsonData, err := resp.Json() 29 if err != nil { 30 t.Fatal(err) 31 } 32 if jsonData.Get("method").String() != http.MethodPost { 33 t.Fatal("method error") 34 } 35 } 36 func TestMethodPost2(t *testing.T) { 37 resp, err := requests.Request(nil, "post", "https://httpbin.org/anything") 38 if err != nil { 39 t.Fatal(err) 40 } 41 jsonData, err := resp.Json() 42 if err != nil { 43 t.Fatal(err) 44 } 45 if jsonData.Get("method").String() != http.MethodPost { 46 t.Fatal("method error") 47 } 48 }