package examples import ( "context" "net/http" "net/http/httptest" "strings" "testing" ) func TestPostJSON(t *testing.T) { count := 0 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { count++ w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"ok":true}`)) })) defer s.Close() b, e := PostJSON(context.Background(), s.Client(), s.URL, []byte(`{"command":"balance"}`)) if e != nil { t.Fatal(e) } if count != 1 || !strings.Contains(string(b), `"ok":true`) { t.Fatalf("count=%d response=%s", count, b) } }