MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestCall_Success

Function TestCall_Success

internal/request/request_test.go:53–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestCall_Success(t *testing.T) {
54 // Mock server to return a dummy response
55 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
56 assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
57 w.WriteHeader(http.StatusOK)
58 _, err := w.Write([]byte(`{"status":"success"}`))
59 assert.NoError(t, err)
60 }))
61 defer server.Close()
62
63 // Create a new request to the mock server
64 req, err := http.NewRequest("GET", server.URL, nil)
65 assert.NoError(t, err)
66
67 var response map[string]string
68 resp, err := request.Call(req, &response)
69 assert.NoError(t, err)
70 assert.Equal(t, http.StatusOK, resp.StatusCode)
71 assert.Equal(t, "success", response["status"])
72}
73
74func TestCall_Fail_DecodeResponse(t *testing.T) {
75 // Mock server to return a malformed response

Callers

nothing calls this directly

Calls 3

CallFunction · 0.92
GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected