package sqlite_test import ( "errors" "testing" "context" "os" "path/filepath" "git.hrafn.xyz/aether/notes/internal/store/sqlite" ) func TestCreateSQLiteStore(t *testing.T) { testcases := []struct { name string dbPath string expectedError bool }{ { name: "valid path", dbPath: filepath.Join(t.TempDir(), "test.db"), expectedError: false, }, { name: "invalid path", dbPath: filepath.Join(t.TempDir(), "Really", "Deep", "Dir", "That", "Does", "Not", "Exist", "test.db"), expectedError: true, }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { store, err := sqlite.NewSQLiteStore(context.Background(), tc.dbPath) if tc.expectedError { if err == nil { t.Errorf("expected an error but got none") } } else { if err != nil { t.Errorf("unexpected error: %v", err) } } if !tc.expectedError && store == nil { t.Errorf("expected a store but got none") } defer func() { if store != nil { store.Close() } // Clean up the database file after the test if _, err := os.Stat(tc.dbPath); !errors.Is(err, os.ErrNotExist) { if err := os.Remove(tc.dbPath); err != nil { t.Errorf("failed to clean up database file: %v", err) } } }() }) } }