@@ -53,7 +53,7 @@ async fn test() -> anyhow::Result<()> {
5353
5454 // Add file
5555 run ! ( SubCommand :: Add {
56- path : [ "t1.txt" , "t2.txt" , "dir" ]
56+ paths : [ "t1.txt" , "t2.txt" , "dir" ]
5757 . map( ToString :: to_string)
5858 . to_vec( ) ,
5959 } ) ;
@@ -73,7 +73,7 @@ async fn test() -> anyhow::Result<()> {
7373 assert ! ( !temp_dir. join( "dir/t4.txt" ) . exists( ) ) ;
7474
7575 // Decrypt
76- run ! ( SubCommand :: Decrypt ) ;
76+ run ! ( SubCommand :: Decrypt { path : None } ) ;
7777 println ! ( "{}" , "After Decrypt" . green( ) ) ;
7878
7979 // Test
@@ -134,7 +134,7 @@ async fn test_reencrypt() -> anyhow::Result<()> {
134134
135135 // Add file
136136 run ! ( SubCommand :: Add {
137- path : [ "t1.txt" , "dir" ] . map( ToString :: to_string) . to_vec( ) ,
137+ paths : [ "t1.txt" , "dir" ] . map( ToString :: to_string) . to_vec( ) ,
138138 } ) ;
139139
140140 // Encrypt multiple times
@@ -154,7 +154,7 @@ async fn test_reencrypt() -> anyhow::Result<()> {
154154 assert ! ( !temp_dir. join( "dir/t4.txt" ) . exists( ) ) ;
155155
156156 // Decrypt
157- run ! ( SubCommand :: Decrypt ) ;
157+ run ! ( SubCommand :: Decrypt { path : None } ) ;
158158 println ! ( "{}" , "After Decrypt" . green( ) ) ;
159159
160160 // Test
@@ -214,13 +214,13 @@ async fn test_many_files() -> anyhow::Result<()> {
214214
215215 // Add file
216216 run ! ( SubCommand :: Add {
217- path : vec![ "dir" . into( ) ]
217+ paths : vec![ "dir" . into( ) ]
218218 } ) ;
219219
220220 // Encrypt
221221 run ! ( SubCommand :: Encrypt ) ;
222222 // Decrypt
223- run ! ( SubCommand :: Decrypt ) ;
223+ run ! ( SubCommand :: Decrypt { path : None } ) ;
224224
225225 // Test
226226 for _ in 1 ..10 {
@@ -231,3 +231,71 @@ async fn test_many_files() -> anyhow::Result<()> {
231231
232232 Ok ( ( ) )
233233}
234+
235+ #[ tokio:: test]
236+ async fn test_partial_decrypt ( ) -> anyhow:: Result < ( ) > {
237+ let _ = env_logger:: try_init ( ) ;
238+ let temp_dir = & TempDir :: default ( ) ;
239+ let exec = |cmd : & str | -> std:: io:: Result < Output > {
240+ let mut temp = cmd. split_whitespace ( ) ;
241+ let mut command = Command :: new ( temp. next ( ) . unwrap ( ) ) ;
242+ command. args ( temp) . current_dir ( temp_dir) . output ( )
243+ } ;
244+ macro_rules! run {
245+ ( $cmd: expr) => {
246+ run( & Cli {
247+ command: $cmd,
248+ repo: temp_dir. to_path_buf( ) ,
249+ } )
250+ . await ?;
251+ } ;
252+ }
253+
254+ exec ( "git init" ) ?;
255+ std:: fs:: create_dir ( temp_dir. join ( "dir" ) ) ?;
256+ std:: fs:: write ( temp_dir. join ( "t1.txt" ) , "Hello, world!" ) ?;
257+ std:: fs:: write ( temp_dir. join ( "dir/t4.txt" ) , "dir test" ) ?;
258+
259+ // Set key
260+ run ! ( SubCommand :: Set {
261+ field: SetField :: key,
262+ value: "123" . to_owned( ) ,
263+ } ) ;
264+
265+ // Add file
266+ run ! ( SubCommand :: Add {
267+ paths: [ "t1.txt" , "dir" ] . map( ToString :: to_string) . to_vec( ) ,
268+ } ) ;
269+
270+ // Encrypt
271+ run ! ( SubCommand :: Encrypt ) ;
272+
273+ // Partial decrypt
274+ run ! ( SubCommand :: Decrypt {
275+ path: Some ( "dir/**" . into( ) )
276+ } ) ;
277+
278+ // Test
279+ for entry in temp_dir. read_dir ( ) ? {
280+ println ! ( "{:?}" , entry?) ;
281+ }
282+ assert ! ( temp_dir. join( "t1.txt.enc" ) . exists( ) ) ;
283+ assert ! ( temp_dir. join( "dir/t4.txt" ) . exists( ) ) ;
284+
285+ // Reencrypt
286+ run ! ( SubCommand :: Encrypt ) ;
287+
288+ // Partial decrypt
289+ run ! ( SubCommand :: Decrypt {
290+ path: Some ( "t1.txt.enc" . into( ) )
291+ } ) ;
292+
293+ // Test
294+ for entry in temp_dir. read_dir ( ) ? {
295+ println ! ( "{:?}" , entry?) ;
296+ }
297+ assert ! ( temp_dir. join( "t1.txt" ) . exists( ) ) ;
298+ assert ! ( temp_dir. join( "dir/t4.txt.enc" ) . exists( ) ) ;
299+
300+ Ok ( ( ) )
301+ }
0 commit comments