Commit 984c91e 1 parent 4171275 commit 984c91e Copy full SHA for 984c91e
File tree 2 files changed +24
-7
lines changed
2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -368,6 +368,7 @@ mod tests {
368
368
use std:: io:: Write ;
369
369
use std:: path:: Path ;
370
370
371
+ use bytes:: Bytes ;
371
372
use futures:: io:: AllowStdIo ;
372
373
use futures:: AsyncReadExt ;
373
374
use tempfile:: TempDir ;
@@ -490,4 +491,22 @@ mod tests {
490
491
let io = FileIO :: from_path ( "tmp/||c" ) ;
491
492
assert ! ( io. is_err( ) ) ;
492
493
}
494
+
495
+ #[ tokio:: test]
496
+ async fn test_memory_io ( ) {
497
+ let io = FileIOBuilder :: new ( "memory" ) . build ( ) . unwrap ( ) ;
498
+
499
+ let path = format ! ( "{}/1.txt" , TempDir :: new( ) . unwrap( ) . path( ) . to_str( ) . unwrap( ) ) ;
500
+
501
+ let output_file = io. new_output ( & path) . unwrap ( ) ;
502
+ output_file. write ( "test" . into ( ) ) . await . unwrap ( ) ;
503
+
504
+ assert ! ( io. is_exist( & path. clone( ) ) . await . unwrap( ) ) ;
505
+ let input_file = io. new_input ( & path) . unwrap ( ) ;
506
+ let content = input_file. read ( ) . await . unwrap ( ) ;
507
+ assert_eq ! ( content, Bytes :: from( "test" ) ) ;
508
+
509
+ io. delete ( & path) . await . unwrap ( ) ;
510
+ assert ! ( !io. is_exist( & path) . await . unwrap( ) ) ;
511
+ }
493
512
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ use crate::{Error, ErrorKind};
30
30
#[ derive( Debug ) ]
31
31
pub ( crate ) enum Storage {
32
32
#[ cfg( feature = "storage-memory" ) ]
33
- Memory ,
33
+ Memory ( Operator ) ,
34
34
#[ cfg( feature = "storage-fs" ) ]
35
35
LocalFs ,
36
36
#[ cfg( feature = "storage-s3" ) ]
@@ -56,7 +56,7 @@ impl Storage {
56
56
57
57
match scheme {
58
58
#[ cfg( feature = "storage-memory" ) ]
59
- Scheme :: Memory => Ok ( Self :: Memory ) ,
59
+ Scheme :: Memory => Ok ( Self :: Memory ( super :: memory_config_build ( ) ? ) ) ,
60
60
#[ cfg( feature = "storage-fs" ) ]
61
61
Scheme :: Fs => Ok ( Self :: LocalFs ) ,
62
62
#[ cfg( feature = "storage-s3" ) ]
@@ -96,13 +96,11 @@ impl Storage {
96
96
let path = path. as_ref ( ) ;
97
97
match self {
98
98
#[ cfg( feature = "storage-memory" ) ]
99
- Storage :: Memory => {
100
- let op = super :: memory_config_build ( ) ?;
101
-
99
+ Storage :: Memory ( op) => {
102
100
if let Some ( stripped) = path. strip_prefix ( "memory:/" ) {
103
- Ok ( ( op, stripped) )
101
+ Ok ( ( op. clone ( ) , stripped) )
104
102
} else {
105
- Ok ( ( op, & path[ 1 ..] ) )
103
+ Ok ( ( op. clone ( ) , & path[ 1 ..] ) )
106
104
}
107
105
}
108
106
#[ cfg( feature = "storage-fs" ) ]
You can’t perform that action at this time.
0 commit comments