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

Function TestClient_ReadResponse

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

Source from the content-addressed store, hash-verified

134}
135
136func TestClient_ReadResponse(t *testing.T) {
137 // Setup a test server
138 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
139 w.WriteHeader(http.StatusOK)
140 w.Write([]byte("response body"))
141 }))
142 defer ts.Close()
143
144 client := NewClient()
145 req := client.Request()
146 req.SetRequestURI(ts.URL).SetMethod("GET")
147
148 if err := client.SendRequest(); err != nil {
149 t.Fatalf("expected no error, got %v", err)
150 }
151
152 code, body, err := client.ReadResponse()
153 if err != nil {
154 t.Fatalf("expected no error, got %v", err)
155 }
156 if code != http.StatusOK {
157 t.Fatalf("expected status code 200, got %d", code)
158 }
159 if string(body) != "response body" {
160 t.Fatalf("expected body 'response body', got %s", body)
161 }
162}
163
164func TestClient_ReadResponse_NoResponse(t *testing.T) {
165 client := NewClient()

Callers

nothing calls this directly

Calls 8

RequestMethod · 0.95
SendRequestMethod · 0.95
ReadResponseMethod · 0.95
NewClientFunction · 0.85
WriteHeaderMethod · 0.80
SetMethodMethod · 0.80
SetRequestURIMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected