(t *testing.T)
| 564 | } |
| 565 | |
| 566 | func TestExtractMetadata_Comprehensive(t *testing.T) { |
| 567 | sql := `SELECT u.name, COUNT(o.id) as order_count, UPPER(u.email) |
| 568 | FROM users u |
| 569 | LEFT JOIN orders o ON u.id = o.user_id |
| 570 | WHERE u.active = true |
| 571 | GROUP BY u.name, u.email |
| 572 | HAVING COUNT(o.id) > 5 |
| 573 | ORDER BY order_count DESC` |
| 574 | |
| 575 | astNode, err := Parse(sql) |
| 576 | if err != nil { |
| 577 | t.Fatalf("Failed to parse SQL: %v", err) |
| 578 | } |
| 579 | |
| 580 | metadata := ExtractMetadata(astNode) |
| 581 | |
| 582 | // Check tables |
| 583 | expectedTables := []string{"users", "orders"} |
| 584 | if !stringSlicesEqual(metadata.Tables, expectedTables) { |
| 585 | t.Errorf("Expected tables %v, got %v", expectedTables, metadata.Tables) |
| 586 | } |
| 587 | |
| 588 | // Check columns |
| 589 | if !contains(metadata.Columns, "name") || !contains(metadata.Columns, "id") || |
| 590 | !contains(metadata.Columns, "email") || !contains(metadata.Columns, "active") || |
| 591 | !contains(metadata.Columns, "user_id") { |
| 592 | t.Errorf("Missing expected columns in: %v", metadata.Columns) |
| 593 | } |
| 594 | |
| 595 | // Check functions |
| 596 | expectedFunctions := []string{"COUNT", "UPPER"} |
| 597 | if !stringSlicesEqual(metadata.Functions, expectedFunctions) { |
| 598 | t.Errorf("Expected functions %v, got %v", expectedFunctions, metadata.Functions) |
| 599 | } |
| 600 | |
| 601 | // Check String() method |
| 602 | str := metadata.String() |
| 603 | if str == "" { |
| 604 | t.Error("Expected non-empty string from Metadata.String()") |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | func TestExtractMetadata_WithCTE(t *testing.T) { |
| 609 | sql := `WITH active_users AS ( |
nothing calls this directly
no test coverage detected