@@ -36,9 +36,11 @@ pub use bootstrap::start;
3636#[ cfg( not( target_arch = "wasm32" ) ) ]
3737mod bootstrap {
3838 use super :: * ;
39- use azure_core:: Result ;
39+ use azure_core:: { test:: TestMode , Result } ;
40+ use serde_json:: json;
4041 use std:: { env, io, path:: Path , process:: Stdio , time:: Duration } ;
4142 use tokio:: {
43+ fs,
4244 io:: { AsyncBufReadExt , BufReader } ,
4345 process:: { ChildStdout , Command } ,
4446 } ;
@@ -59,6 +61,7 @@ mod bootstrap {
5961 ///
6062 /// This is intended for internal use only and should not be called directly in tests.
6163 pub async fn start (
64+ test_mode : Option < TestMode > ,
6265 crate_dir : impl AsRef < Path > ,
6366 options : Option < ProxyOptions > ,
6467 ) -> Result < Proxy > {
@@ -68,11 +71,41 @@ mod bootstrap {
6871 }
6972
7073 // Find root of git repo or work tree: a ".git" directory or file will exist either way.
71- let git_dir = crate :: find_ancestor_file ( crate_dir, ".git" ) ?;
74+ let git_dir = crate :: find_ancestor_file ( crate_dir. as_ref ( ) , ".git" ) ?;
7275 let git_dir = git_dir. parent ( ) . ok_or_else ( || {
7376 io:: Error :: new ( io:: ErrorKind :: NotFound , "parent git repository not found" )
7477 } ) ?;
7578
79+ // Create an assets.json file in the crate_dir if a parent doesn't already exist.
80+ #[ cfg( not( target_arch = "wasm32" ) ) ]
81+ if test_mode == Some ( TestMode :: Record )
82+ && matches ! ( crate :: find_ancestor_file( crate_dir. as_ref( ) , "assets.json" ) , Err ( err) if err. kind( ) == & ErrorKind :: Io )
83+ {
84+ let assets_file = crate_dir. as_ref ( ) . join ( "assets.json" ) ;
85+ tracing:: trace!( "creating {path}" , path = assets_file. display( ) ) ;
86+
87+ let assets_dir = assets_file
88+ . parent ( )
89+ . and_then ( Path :: file_name)
90+ . map ( |dir| dir. to_ascii_lowercase ( ) )
91+ . ok_or_else ( || {
92+ azure_core:: Error :: message (
93+ ErrorKind :: Io ,
94+ "failed to get assets.json parent directory name" ,
95+ )
96+ } ) ?;
97+ let assets_dir = assets_dir. to_string_lossy ( ) ;
98+ let assets_content = json ! ( {
99+ "AssetsRepo" : "Azure/azure-sdk-assets" ,
100+ "AssetsRepoPrefixPath" : "rust" ,
101+ "TagPrefix" : format!( "rust/{assets_dir}" ) ,
102+ "Tag" : "" ,
103+ } ) ;
104+ let file = fs:: File :: create_new ( assets_file) . await ?;
105+ serde_json:: to_writer_pretty ( file. into_std ( ) . await , & assets_content) ?;
106+ }
107+
108+ // Construct the command line arguments and start the test-proxy service.
76109 let mut args: Vec < String > = Vec :: new ( ) ;
77110 args. extend_from_slice ( & [
78111 "start" . into ( ) ,
0 commit comments