MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestHandleExtractMetadata

Function TestHandleExtractMetadata

pkg/mcp/tools_test.go:242–274  ·  view source on GitHub ↗

--------------------------------------------------------------------------- handleExtractMetadata ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

240// ---------------------------------------------------------------------------
241
242func TestHandleExtractMetadata(t *testing.T) {
243 ctx := context.Background()
244
245 t.Run("valid SQL returns metadata keys", func(t *testing.T) {
246 req := makeReq(map[string]any{"sql": "SELECT u.id, o.name FROM users u JOIN orders o ON u.id = o.user_id"})
247 res, err := handleExtractMetadata(ctx, req)
248 if err != nil {
249 t.Fatalf("unexpected error: %v", err)
250 }
251 data := unmarshalResult(t, res)
252 for _, key := range []string{"tables", "columns", "functions"} {
253 if _, ok := data[key]; !ok {
254 t.Errorf("expected key %q in result", key)
255 }
256 }
257 })
258
259 t.Run("empty sql returns protocol error", func(t *testing.T) {
260 req := makeReq(map[string]any{"sql": ""})
261 _, err := handleExtractMetadata(ctx, req)
262 if err == nil {
263 t.Fatal("expected error for empty sql, got nil")
264 }
265 })
266
267 t.Run("missing sql param returns protocol error", func(t *testing.T) {
268 req := makeReq(map[string]any{})
269 _, err := handleExtractMetadata(ctx, req)
270 if err == nil {
271 t.Fatal("expected error for missing sql param, got nil")
272 }
273 })
274}
275
276// ---------------------------------------------------------------------------
277// handleSecurityScan

Callers

nothing calls this directly

Calls 6

makeReqFunction · 0.85
handleExtractMetadataFunction · 0.85
unmarshalResultFunction · 0.85
RunMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected