@@ -17,23 +17,26 @@ const LIBSQL_MAGIC: u64 = u64::from_be_bytes(*b"LIBSQL\0\0");
1717pub mod test {
1818 use std:: fs:: OpenOptions ;
1919 use std:: path:: PathBuf ;
20- use std:: { path:: Path , sync:: Arc } ;
20+ use std:: path:: Path ;
21+ use std:: sync:: Arc ;
2122
22- use libsql_sys:: { name:: NamespaceName , rusqlite:: OpenFlags } ;
23+ use libsql_sys:: rusqlite:: OpenFlags ;
24+ use libsql_sys:: name:: NamespaceName ;
2325 use tempfile:: { tempdir, TempDir } ;
2426 use tokio:: sync:: mpsc;
2527
2628 use crate :: checkpointer:: LibsqlCheckpointer ;
29+ use crate :: io:: Io ;
2730 use crate :: io:: StdIO ;
2831 use crate :: registry:: WalRegistry ;
2932 use crate :: shared_wal:: SharedWal ;
3033 use crate :: storage:: TestStorage ;
3134 use crate :: wal:: { LibsqlWal , LibsqlWalManager } ;
3235
33- pub struct TestEnv {
36+ pub struct TestEnv < IO : Io = StdIO > {
3437 pub tmp : TempDir ,
35- pub registry : Arc < WalRegistry < StdIO , TestStorage > > ,
36- pub wal : LibsqlWalManager < StdIO , TestStorage > ,
38+ pub registry : Arc < WalRegistry < IO , TestStorage < IO > > > ,
39+ pub wal : LibsqlWalManager < IO , TestStorage < IO > > ,
3740 }
3841
3942 impl TestEnv {
@@ -42,6 +45,12 @@ pub mod test {
4245 }
4346
4447 pub fn new_store ( store : bool ) -> Self {
48+ TestEnv :: new_io ( StdIO ( ( ) ) , store)
49+ }
50+ }
51+
52+ impl < IO : Io > TestEnv < IO > {
53+ pub fn new_io ( io : IO , store : bool ) -> Self {
4554 let tmp = tempdir ( ) . unwrap ( ) ;
4655 let resolver = |path : & Path | {
4756 let name = path
@@ -72,7 +81,7 @@ pub mod test {
7281 Self { tmp, registry, wal }
7382 }
7483
75- pub fn shared ( & self , namespace : & str ) -> Arc < SharedWal < StdIO > > {
84+ pub fn shared ( & self , namespace : & str ) -> Arc < SharedWal < IO > > {
7685 let path = self . tmp . path ( ) . join ( namespace) . join ( "data" ) ;
7786 let registry = self . registry . clone ( ) ;
7887 let namespace = NamespaceName :: from_string ( namespace. into ( ) ) ;
@@ -86,7 +95,7 @@ pub mod test {
8695 pub fn open_conn (
8796 & self ,
8897 namespace : & ' static str ,
89- ) -> libsql_sys:: Connection < LibsqlWal < StdIO > > {
98+ ) -> libsql_sys:: Connection < LibsqlWal < IO > > {
9099 let path = self . db_path ( namespace) ;
91100 let wal = self . wal . clone ( ) ;
92101 std:: fs:: create_dir_all ( & path) . unwrap ( ) ;
@@ -110,7 +119,7 @@ pub mod test {
110119 }
111120 }
112121
113- pub fn seal_current_segment ( shared : & SharedWal < StdIO > ) {
122+ pub fn seal_current_segment < IO : Io > ( shared : & SharedWal < IO > ) {
114123 let mut tx = shared. begin_read ( 99999 ) . into ( ) ;
115124 shared. upgrade ( & mut tx) . unwrap ( ) ;
116125 {
0 commit comments