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

Function TestHandleParseSQL

pkg/mcp/tools_test.go:199–236  ·  view source on GitHub ↗

--------------------------------------------------------------------------- handleParseSQL ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

197// ---------------------------------------------------------------------------
198
199func TestHandleParseSQL(t *testing.T) {
200 ctx := context.Background()
201
202 t.Run("valid SQL returns statement info", func(t *testing.T) {
203 req := makeReq(map[string]any{"sql": "SELECT id FROM users; SELECT name FROM orders"})
204 res, err := handleParseSQL(ctx, req)
205 if err != nil {
206 t.Fatalf("unexpected error: %v", err)
207 }
208 data := unmarshalResult(t, res)
209 if _, ok := data["statement_count"]; !ok {
210 t.Error("expected 'statement_count' key in result")
211 }
212 if _, ok := data["statement_types"]; !ok {
213 t.Error("expected 'statement_types' key in result")
214 }
215 count, ok := data["statement_count"].(float64)
216 if !ok || count < 1 {
217 t.Errorf("expected at least 1 statement, got %v", count)
218 }
219 })
220
221 t.Run("empty sql returns protocol error", func(t *testing.T) {
222 req := makeReq(map[string]any{"sql": ""})
223 _, err := handleParseSQL(ctx, req)
224 if err == nil {
225 t.Fatal("expected error for empty sql, got nil")
226 }
227 })
228
229 t.Run("missing sql param returns protocol error", func(t *testing.T) {
230 req := makeReq(map[string]any{})
231 _, err := handleParseSQL(ctx, req)
232 if err == nil {
233 t.Fatal("expected error for missing sql param, got nil")
234 }
235 })
236}
237
238// ---------------------------------------------------------------------------
239// handleExtractMetadata

Callers

nothing calls this directly

Calls 7

makeReqFunction · 0.85
handleParseSQLFunction · 0.85
unmarshalResultFunction · 0.85
RunMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected