@@ -145,11 +145,10 @@ impl<'a> AddCommand<'a> {
145145
146146#[ cfg( test) ]
147147mod tests {
148- use std:: fs:: { self , File } ;
148+ use std:: fs;
149149
150150 use super :: AddCommand ;
151- use crate :: config:: locations:: LocationsProvider ;
152- use std:: io:: Write ;
151+ use crate :: config:: { app_config:: { AppConfig , Project } , locations:: LocationsProvider } ;
153152
154153 #[ test]
155154 fn add_file_when_project_does_not_exist ( ) {
@@ -162,8 +161,8 @@ mod tests {
162161
163162 let user_file = current_dir. path ( ) . join ( "file" ) ;
164163 let config_file = config_dir. path ( ) . join ( "config.json" ) ;
165- let mut file = File :: create ( & config_file ) . unwrap ( ) ;
166- write ! ( file , "{{ \" projects \" :[]}}" ) . unwrap ( ) ;
164+ let config = AppConfig { projects : vec ! [ ] } ;
165+ fs :: write ( & config_file , serde_json :: to_string ( & config ) . unwrap ( ) ) . unwrap ( ) ;
167166
168167 let sut = AddCommand :: new ( & locations_provider) ;
169168
@@ -187,13 +186,10 @@ mod tests {
187186
188187 let user_file = current_dir. path ( ) . join ( "file" ) ;
189188 let config_file = config_dir. path ( ) . join ( "config.json" ) ;
190- let mut file = File :: create ( & config_file) . unwrap ( ) ;
191- write ! (
192- file,
193- "{{\" projects\" :[{{\" name\" :\" proj1\" , \" path\" :\" {}\" , \" id\" :\" 1\" }}]}}" ,
194- current_dir. path( ) . to_str( ) . unwrap( )
195- )
196- . unwrap ( ) ;
189+ let config = AppConfig {
190+ projects : vec ! [ Project { name: "proj1" . into( ) , id: "1" . into( ) , path: current_dir. path( ) . to_path_buf( ) } ] ,
191+ } ;
192+ fs:: write ( & config_file, serde_json:: to_string ( & config) . unwrap ( ) ) . unwrap ( ) ;
197193
198194 let sut = AddCommand :: new ( & locations_provider) ;
199195
@@ -210,13 +206,10 @@ mod tests {
210206 LocationsProvider :: new ( config_dir. path ( ) . to_path_buf ( ) , data_dir. path ( ) . to_path_buf ( ) ) ;
211207
212208 let config_file = config_dir. path ( ) . join ( "config.json" ) ;
213- let mut file = File :: create ( & config_file) . unwrap ( ) ;
214- write ! (
215- file,
216- "{{\" projects\" :[{{\" name\" :\" proj1\" , \" path\" :\" {}\" , \" id\" :\" 1\" }}]}}" ,
217- project_root. path( ) . to_str( ) . unwrap( )
218- )
219- . unwrap ( ) ;
209+ let config = AppConfig {
210+ projects : vec ! [ Project { name: "proj1" . into( ) , id: "1" . into( ) , path: project_root. path( ) . to_path_buf( ) } ] ,
211+ } ;
212+ fs:: write ( & config_file, serde_json:: to_string ( & config) . unwrap ( ) ) . unwrap ( ) ;
220213
221214 let subdir = project_root. path ( ) . join ( "config" ) ;
222215 fs:: create_dir_all ( & subdir) . unwrap ( ) ;
@@ -239,13 +232,10 @@ mod tests {
239232 LocationsProvider :: new ( config_dir. path ( ) . to_path_buf ( ) , data_dir. path ( ) . to_path_buf ( ) ) ;
240233
241234 let config_file = config_dir. path ( ) . join ( "config.json" ) ;
242- let mut file = File :: create ( & config_file) . unwrap ( ) ;
243- write ! (
244- file,
245- "{{\" projects\" :[{{\" name\" :\" proj1\" , \" path\" :\" {}\" , \" id\" :\" 1\" }}]}}" ,
246- project_root. path( ) . to_str( ) . unwrap( )
247- )
248- . unwrap ( ) ;
235+ let config = AppConfig {
236+ projects : vec ! [ Project { name: "proj1" . into( ) , id: "1" . into( ) , path: project_root. path( ) . to_path_buf( ) } ] ,
237+ } ;
238+ fs:: write ( & config_file, serde_json:: to_string ( & config) . unwrap ( ) ) . unwrap ( ) ;
249239
250240 let subdir = project_root. path ( ) . join ( "config" ) ;
251241 fs:: create_dir_all ( & subdir) . unwrap ( ) ;
0 commit comments