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

Function TestHandleAnalyzeSQL_InvalidSQLPartialResults

pkg/mcp/tools_test.go:695–742  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

693}
694
695func TestHandleAnalyzeSQL_InvalidSQLPartialResults(t *testing.T) {
696 ctx := context.Background()
697 req := makeReq(map[string]any{"sql": "SELECT FROM"})
698 res, err := handleAnalyzeSQL(ctx, req)
699 if err != nil {
700 t.Fatalf("unexpected protocol error: %v", err)
701 }
702 data := unmarshalResult(t, res)
703
704 // Validate should report valid=false (it returns a result, not an error).
705 validateData, ok := data["validate"].(map[string]any)
706 if !ok {
707 t.Fatal("expected 'validate' sub-result to be a map")
708 }
709 valid, ok := validateData["valid"].(bool)
710 if !ok || valid {
711 t.Errorf("expected validate.valid=false for invalid SQL, got %v", validateData["valid"])
712 }
713
714 // Security should still succeed.
715 securityData, ok := data["security"].(map[string]any)
716 if !ok {
717 t.Fatal("expected 'security' sub-result to be a map")
718 }
719 if _, ok := securityData["is_clean"]; !ok {
720 t.Error("expected 'is_clean' key in security sub-result")
721 }
722
723 // Lint should still succeed.
724 lintData, ok := data["lint"].(map[string]any)
725 if !ok {
726 t.Fatal("expected 'lint' sub-result to be a map")
727 }
728 if _, ok := lintData["violation_count"]; !ok {
729 t.Error("expected 'violation_count' key in lint sub-result")
730 }
731
732 // Parse, metadata, and format should have errors since "SELECT FROM" fails to parse.
733 errs, ok := data["errors"].(map[string]any)
734 if !ok {
735 t.Fatal("expected 'errors' map for failed sub-results")
736 }
737 for _, key := range []string{"parse", "metadata", "format"} {
738 if _, ok := errs[key]; !ok {
739 t.Errorf("expected error entry for %q in errors map", key)
740 }
741 }
742}

Callers

nothing calls this directly

Calls 6

makeReqFunction · 0.85
handleAnalyzeSQLFunction · 0.85
unmarshalResultFunction · 0.85
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected