--------------------------------------------------------------------------- handleExtractMetadata ---------------------------------------------------------------------------
(t *testing.T)
| 240 | // --------------------------------------------------------------------------- |
| 241 | |
| 242 | func 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 |
nothing calls this directly
no test coverage detected