@@ -490,6 +490,54 @@ bar: baz",
490490 panic ! ( "Output JSON does not have the expected structure" ) ;
491491 }
492492
493+ #[ test]
494+ fn set_json_file_insert_with_value_file ( ) {
495+ let file_path = prepare_temp_file (
496+ "test_set_json_file_insert_with_value_file.json" ,
497+ r#"{"a": 2, "b": "ba"}"# . as_bytes ( ) ,
498+ ) ;
499+ let value_file = prepare_temp_file ( "insert_value_file.json" , r#"{"cc": "ccc"}"# . as_bytes ( ) ) ;
500+ assert ! (
501+ Command :: new( SOPS_BINARY_PATH )
502+ . arg( "encrypt" )
503+ . arg( "-i" )
504+ . arg( file_path. clone( ) )
505+ . output( )
506+ . expect( "Error running sops" )
507+ . status
508+ . success( ) ,
509+ "sops didn't exit successfully"
510+ ) ;
511+ let output = Command :: new ( SOPS_BINARY_PATH )
512+ . arg ( "set" )
513+ . arg ( "--value-file" )
514+ . arg ( file_path. clone ( ) )
515+ . arg ( r#"["c"]"# )
516+ . arg ( value_file. clone ( ) )
517+ . output ( )
518+ . expect ( "Error running sops" ) ;
519+ println ! (
520+ "stdout: {}, stderr: {}" ,
521+ String :: from_utf8_lossy( & output. stdout) ,
522+ String :: from_utf8_lossy( & output. stderr)
523+ ) ;
524+ assert ! ( output. status. success( ) , "sops didn't exit successfully" ) ;
525+ let mut s = String :: new ( ) ;
526+ File :: open ( file_path)
527+ . unwrap ( )
528+ . read_to_string ( & mut s)
529+ . unwrap ( ) ;
530+ let data: Value = serde_json:: from_str ( & s) . expect ( "Error parsing sops's JSON output" ) ;
531+ if let Value :: Mapping ( data) = data {
532+ let a = data. get ( & Value :: String ( "c" . to_owned ( ) ) ) . unwrap ( ) ;
533+ if let & Value :: Mapping ( ref a) = a {
534+ assert_encrypted ! ( & a, Value :: String ( "cc" . to_owned( ) ) ) ;
535+ return ;
536+ }
537+ }
538+ panic ! ( "Output JSON does not have the expected structure" ) ;
539+ }
540+
493541 #[ test]
494542 fn set_yaml_file_update ( ) {
495543 let file_path = prepare_temp_file (
0 commit comments