| 461 | } |
| 462 | |
| 463 | func TestDatabaseFileCreation(t *testing.T) { |
| 464 | tmpDir := t.TempDir() |
| 465 | dbPath := filepath.Join(tmpDir, "subdir", "test.db") |
| 466 | |
| 467 | // Should fail because parent directory doesn't exist |
| 468 | _, err := New(dbPath) |
| 469 | if err == nil { |
| 470 | t.Error("Should fail when parent directory doesn't exist") |
| 471 | } |
| 472 | |
| 473 | // Create parent directory |
| 474 | _ = os.MkdirAll(filepath.Dir(dbPath), 0755) |
| 475 | |
| 476 | svc, err := New(dbPath) |
| 477 | if err != nil { |
| 478 | t.Fatalf("New should succeed after creating parent dir: %v", err) |
| 479 | } |
| 480 | _ = svc.Close() |
| 481 | |
| 482 | // Verify file exists |
| 483 | if _, err := os.Stat(dbPath); os.IsNotExist(err) { |
| 484 | t.Error("Database file should be created") |
| 485 | } |
| 486 | } |