MCPcopy Create free account
hub / github.com/bytebase/bytebase / handler

Method handler

backend/api/mcp/tool_schema_test.go:115–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115func (m *metadataMock) handler() http.Handler {
116 listHandler := mockListDatabases(m.databases)
117 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
118 if strings.Contains(r.URL.Path, "DatabaseService/GetDatabaseMetadata") {
119 var captured capturedRequest
120 _ = json.NewDecoder(r.Body).Decode(&captured)
121
122 m.capturedMu.Lock()
123 m.capturedCalls = append(m.capturedCalls, captured)
124 m.capturedMu.Unlock()
125
126 idx := int(atomic.AddInt32(&m.calls, 1)) - 1
127 var resp map[string]any
128 if idx < len(m.responses) {
129 resp = m.responses[idx]
130 } else if len(m.responses) > 0 {
131 // Reuse last response for additional calls.
132 resp = m.responses[len(m.responses)-1]
133 }
134 if resp == nil {
135 resp = map[string]any{"name": "", "schemas": []any{}}
136 }
137
138 w.Header().Set("Content-Type", "application/json")
139 w.WriteHeader(http.StatusOK)
140 _ = json.NewEncoder(w).Encode(resp)
141 return
142 }
143 listHandler.ServeHTTP(w, r)
144 })
145}
146
147func (m *metadataMock) lastCall() capturedRequest {
148 m.capturedMu.Lock()

Callers 1

mockMetadataServerFunction · 0.45

Calls 4

mockListDatabasesFunction · 0.85
DecodeMethod · 0.80
NewDecoderMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected