@@ -38,7 +38,7 @@ fn runtime() -> &'static Runtime {
3838/// Throttling parameters
3939///
4040/// Note: Throttle implements [`FromStr`] to read it from something like "10kiB,10MB"
41- #[ derive( Debug , Clone , Copy ) ]
41+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
4242pub struct Throttle {
4343 bandwidth : u32 ,
4444 burst : u32 ,
@@ -49,7 +49,7 @@ impl FromStr for Throttle {
4949 fn from_str ( s : & str ) -> Result < Self > {
5050 let mut values = s
5151 . split ( ',' )
52- . map ( |s| ByteSize :: from_str ( s) . map_err ( |err| anyhow ! ( "Error: {err}" ) ) )
52+ . map ( |s| ByteSize :: from_str ( s. trim ( ) ) . map_err ( |err| anyhow ! ( "Error: {err}" ) ) )
5353 . map ( |b| -> Result < u32 > { Ok ( b?. as_u64 ( ) . try_into ( ) ?) } ) ;
5454 let bandwidth = values
5555 . next ( )
@@ -287,3 +287,47 @@ impl WriteBackend for OpenDALBackend {
287287 Ok ( ( ) )
288288 }
289289}
290+
291+ #[ cfg( test) ]
292+ mod tests {
293+ use std:: fs;
294+
295+ use super :: * ;
296+ use rstest:: rstest;
297+ use serde:: Deserialize ;
298+
299+ #[ rstest]
300+ #[ case( "10kB,10MB" , Throttle { bandwidth: 10_000 , burst: 10_000_000 } ) ]
301+ #[ case( "10 kB,10 MB" , Throttle { bandwidth: 10_000 , burst: 10_000_000 } ) ]
302+ #[ case( "10kB, 10MB" , Throttle { bandwidth: 10_000 , burst: 10_000_000 } ) ]
303+ #[ case( " 10kB, 10MB" , Throttle { bandwidth: 10_000 , burst: 10_000_000 } ) ]
304+ #[ case( "10kiB,10MiB" , Throttle { bandwidth: 10_240 , burst: 10_485_760 } ) ]
305+ fn correct_throttle ( #[ case] input : & str , #[ case] expected : Throttle ) {
306+ assert_eq ! ( Throttle :: from_str( input) . unwrap( ) , expected) ;
307+ }
308+
309+ #[ rstest]
310+ #[ case( "" ) ]
311+ #[ case( "10kiB" ) ]
312+ #[ case( "no_number,10MiB" ) ]
313+ #[ case( "10kB;10MB" ) ]
314+ fn invalid_throttle ( #[ case] input : & str ) {
315+ assert ! ( Throttle :: from_str( input) . is_err( ) ) ;
316+ }
317+
318+ #[ rstest]
319+ fn new_opendal_backend (
320+ #[ files( "tests/fixtures/opendal/*.toml" ) ] test_case : PathBuf ,
321+ ) -> Result < ( ) > {
322+ #[ derive( Deserialize ) ]
323+ struct TestCase {
324+ path : String ,
325+ options : HashMap < String , String > ,
326+ }
327+
328+ let test: TestCase = toml:: from_str ( & fs:: read_to_string ( test_case) ?) ?;
329+
330+ _ = OpenDALBackend :: new ( test. path , test. options ) ?;
331+ Ok ( ( ) )
332+ }
333+ }
0 commit comments