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

Function TestErrorPathsIntegration

cmd/gosqlx/cmd/integration_test.go:355–383  ·  view source on GitHub ↗

TestErrorPathsIntegration tests error handling improvements

(t *testing.T)

Source from the content-addressed store, hash-verified

353
354// TestErrorPathsIntegration tests error handling improvements
355func TestErrorPathsIntegration(t *testing.T) {
356 t.Run("InvalidSQLPattern", func(t *testing.T) {
357 // Test that non-SQL input is properly rejected
358 _, err := DetectAndReadInput("just some random text that is not SQL")
359 if err == nil {
360 t.Error("Expected error for non-SQL input, got success")
361 }
362 if !strings.Contains(err.Error(), "does not appear to be valid SQL") {
363 t.Errorf("Expected SQL validation error, got: %v", err)
364 }
365 })
366
367 t.Run("EmptyFileHandling", func(t *testing.T) {
368 tmpDir := t.TempDir()
369 emptyFile := filepath.Join(tmpDir, "empty.sql")
370 err := os.WriteFile(emptyFile, []byte(""), 0644)
371 if err != nil {
372 t.Fatalf("Failed to create empty file: %v", err)
373 }
374
375 _, err = DetectAndReadInput(emptyFile)
376 if err == nil {
377 t.Error("Expected error for empty file, got success")
378 }
379 if !strings.Contains(err.Error(), "empty") {
380 t.Errorf("Expected empty file error, got: %v", err)
381 }
382 })
383}

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
DetectAndReadInputFunction · 0.70
ErrorfMethod · 0.65
FatalfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected