real_namespace_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package engine
  2. import (
  3. "context"
  4. "testing"
  5. )
  6. // TestRealNamespaceDiscovery tests the real namespace discovery functionality
  7. func TestRealNamespaceDiscovery(t *testing.T) {
  8. engine := NewSQLEngine("localhost:8888")
  9. // Test SHOW DATABASES with real namespace discovery
  10. result, err := engine.ExecuteSQL(context.Background(), "SHOW DATABASES")
  11. if err != nil {
  12. t.Fatalf("SHOW DATABASES failed: %v", err)
  13. }
  14. // Should have Database column
  15. if len(result.Columns) != 1 || result.Columns[0] != "Database" {
  16. t.Errorf("Expected 1 column 'Database', got %v", result.Columns)
  17. }
  18. // With no fallback sample data, result may be empty if no real MQ cluster
  19. t.Logf("Discovered %d namespaces (no fallback data):", len(result.Rows))
  20. if len(result.Rows) == 0 {
  21. t.Log(" (No namespaces found - requires real SeaweedFS MQ cluster)")
  22. } else {
  23. for _, row := range result.Rows {
  24. if len(row) > 0 {
  25. t.Logf(" - %s", row[0].ToString())
  26. }
  27. }
  28. }
  29. }
  30. // TestRealTopicDiscovery tests the real topic discovery functionality
  31. func TestRealTopicDiscovery(t *testing.T) {
  32. engine := NewSQLEngine("localhost:8888")
  33. // Test SHOW TABLES with real topic discovery (use double quotes for PostgreSQL)
  34. result, err := engine.ExecuteSQL(context.Background(), "SHOW TABLES FROM \"default\"")
  35. if err != nil {
  36. t.Fatalf("SHOW TABLES failed: %v", err)
  37. }
  38. // Should have table name column
  39. expectedColumn := "Tables_in_default"
  40. if len(result.Columns) != 1 || result.Columns[0] != expectedColumn {
  41. t.Errorf("Expected 1 column '%s', got %v", expectedColumn, result.Columns)
  42. }
  43. // With no fallback sample data, result may be empty if no real MQ cluster or namespace doesn't exist
  44. t.Logf("Discovered %d topics in 'default' namespace (no fallback data):", len(result.Rows))
  45. if len(result.Rows) == 0 {
  46. t.Log(" (No topics found - requires real SeaweedFS MQ cluster with 'default' namespace)")
  47. } else {
  48. for _, row := range result.Rows {
  49. if len(row) > 0 {
  50. t.Logf(" - %s", row[0].ToString())
  51. }
  52. }
  53. }
  54. }
  55. // TestNamespaceDiscoveryNoFallback tests behavior when filer is unavailable (no sample data)
  56. func TestNamespaceDiscoveryNoFallback(t *testing.T) {
  57. // This test demonstrates the no-fallback behavior when no real MQ cluster is running
  58. engine := NewSQLEngine("localhost:8888")
  59. // Get broker client to test directly
  60. brokerClient := engine.catalog.brokerClient
  61. if brokerClient == nil {
  62. t.Fatal("Expected brokerClient to be initialized")
  63. }
  64. // Test namespace listing (should fail without real cluster)
  65. namespaces, err := brokerClient.ListNamespaces(context.Background())
  66. if err != nil {
  67. t.Logf("ListNamespaces failed as expected: %v", err)
  68. namespaces = []string{} // Set empty for the rest of the test
  69. }
  70. // With no fallback sample data, should return empty lists
  71. if len(namespaces) != 0 {
  72. t.Errorf("Expected empty namespace list with no fallback, got %v", namespaces)
  73. }
  74. // Test topic listing (should return empty list)
  75. topics, err := brokerClient.ListTopics(context.Background(), "default")
  76. if err != nil {
  77. t.Fatalf("ListTopics failed: %v", err)
  78. }
  79. // Should have no fallback topics
  80. if len(topics) != 0 {
  81. t.Errorf("Expected empty topic list with no fallback, got %v", topics)
  82. }
  83. t.Log("No fallback behavior - returns empty lists when filer unavailable")
  84. }