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

Function TestExtractMetadata_Comprehensive

pkg/gosqlx/extract_test.go:566–606  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

564}
565
566func 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
608func TestExtractMetadata_WithCTE(t *testing.T) {
609 sql := `WITH active_users AS (

Callers

nothing calls this directly

Calls 8

ParseFunction · 0.85
ExtractMetadataFunction · 0.85
stringSlicesEqualFunction · 0.70
containsFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected