MCPcopy Create free account
hub / github.com/BryanMwangi/pine / TestRequest_JSON

Function TestRequest_JSON

client_test.go:33–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestRequest_JSON(t *testing.T) {
34 client := NewClient()
35 req := client.Request()
36 testBody := map[string]string{"key": "value"}
37
38 if err := req.JSON(testBody); err != nil {
39 t.Fatalf("expected no error, got %v", err)
40 }
41 if req.body == nil {
42 t.Fatal("expected body to be set")
43 }
44
45 expectedContentType := "application/json"
46 if req.Header.Get("Content-Type") != expectedContentType {
47 t.Fatalf("expected Content-Type to be %s, got %s", expectedContentType, req.Header.Get("Content-Type"))
48 }
49
50 var result map[string]string
51 if err := json.NewDecoder(req.body).Decode(&result); err != nil {
52 t.Fatalf("failed to decode body: %v", err)
53 }
54 if result["key"] != "value" {
55 t.Errorf("expected key to be 'value', got %s", result["key"])
56 }
57}
58
59func TestRequest_SetHeaders(t *testing.T) {
60 client := NewClient()

Callers

nothing calls this directly

Calls 4

RequestMethod · 0.95
NewClientFunction · 0.85
JSONMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected