MCPcopy Create free account
hub / github.com/dave/blast / TestPost

Function TestPost

httpworker/httpworker_test.go:39–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37}
38
39func TestPost(t *testing.T) {
40 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41 if r.Method != "POST" {
42 t.Errorf("Unexpected method: %s", r.Method)
43 }
44 b, err := ioutil.ReadAll(r.Body)
45 if err != nil {
46 t.Error(err)
47 }
48 if string(b) != "abc" {
49 t.Errorf("Unexpected body: %s", string(b))
50 }
51 }))
52 defer ts.Close()
53
54 payload := map[string]interface{}{
55 "method": "POST",
56 "url": ts.URL,
57 "body": "abc",
58 }
59 response, err := New().Send(context.Background(), payload)
60 expected := map[string]interface{}{
61 "status": 200,
62 }
63 if err != nil {
64 log.Fatal(err)
65 }
66 if !reflect.DeepEqual(response, expected) {
67 t.Fatalf("Unexpected: %#v", response)
68 }
69}
70
71func TestHeaders(t *testing.T) {
72 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 3

NewFunction · 0.70
SendMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected