engine_client_test.go
TEXT FILE584 B · Public source code for developers, search crawlers and AI agents
1package examples
2
3import (
4 "context"
5 "net/http"
6 "net/http/httptest"
7 "strings"
8 "testing"
9)
10
11func TestPostJSON(t *testing.T) {
12 count := 0
13 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
14 count++
15 w.Header().Set("Content-Type", "application/json")
16 w.Write([]byte(`{"ok":true}`))
17 }))
18 defer s.Close()
19 b, e := PostJSON(context.Background(), s.Client(), s.URL, []byte(`{"command":"balance"}`))
20 if e != nil {
21 t.Fatal(e)
22 }
23 if count != 1 || !strings.Contains(string(b), `"ok":true`) {
24 t.Fatalf("count=%d response=%s", count, b)
25 }
26}Read-only source · Select a line number to link directly · Raw download above
