MCPcopy
hub / github.com/dosco/graphjin / TestCallerListWithQueryParams

Function TestCallerListWithQueryParams

core/openapi/caller_test.go:56–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestCallerListWithQueryParams(t *testing.T) {
57 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
58 if r.URL.Query().Get("actorId") != "u-7" {
59 t.Errorf("actorId = %q", r.URL.Query().Get("actorId"))
60 }
61 if r.URL.Query().Get("limit") != "50" {
62 t.Errorf("limit = %q", r.URL.Query().Get("limit"))
63 }
64 w.Header().Set("Content-Type", "application/json")
65 _, _ = w.Write([]byte(`{"data":[{"id":1},{"id":2}]}`))
66 }))
67 defer srv.Close()
68
69 op := &OpDescriptor{
70 OperationID: "listAuditLogs",
71 Method: "GET",
72 PathTemplate: "/audit-logs",
73 QueryParams: []ParamSpec{
74 {Name: "actorId", In: ParamInQuery},
75 {Name: "limit", In: ParamInQuery},
76 },
77 ResultPath: []string{"data"},
78 IsArrayResponse: true,
79 }
80 c := buildCaller(t, op, srv.URL, nil)
81
82 body, err := c.Call(context.Background(), CallParams{
83 QueryValues: map[string]string{"actorId": "u-7", "limit": "50"},
84 })
85 if err != nil {
86 t.Fatal(err)
87 }
88 // ResultPath strips the {data: [...]} wrapper.
89 if string(body) != `[{"id":1},{"id":2}]` {
90 t.Errorf("body = %s", body)
91 }
92}
93
94func TestCallerRetryOn401(t *testing.T) {
95 var calls int32

Callers

nothing calls this directly

Calls 7

buildCallerFunction · 0.85
GetMethod · 0.65
QueryMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
CallMethod · 0.65

Tested by

no test coverage detected