Skip to content

Commit 5e7ac07

Browse files
committed
Refactoring.
1 parent c3fe6c4 commit 5e7ac07

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/helpers/daemon.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ impl MpdConfig {
2929
sock_path: base.join("sock"),
3030
}
3131
}
32-
}
3332

34-
fn write_config(config: &MpdConfig) {
35-
let config_text = format!(r#"
33+
fn config_text(&self) -> String {
34+
format!(r#"
3635
db_file "{db_file}"
3736
log_file "/dev/null"
3837
music_directory "{music_directory}"
@@ -43,15 +42,19 @@ audio_output {{
4342
name "null"
4443
}}
4544
"#,
46-
db_file=config.db_file.display(),
47-
music_directory=config.music_directory.display(),
48-
playlist_directory=config.playlist_directory.display(),
49-
sock_path=config.sock_path.display(),
50-
);
51-
create_dir(&config.music_directory).expect("Could not create music directory.");
52-
create_dir(&config.playlist_directory).expect("Could not create playlist directory.");
53-
let mut file = File::create(&config.config_path).expect("Could not create config file.");
54-
file.write_all(config_text.as_bytes()).expect("Could not write config file.");
45+
db_file=self.db_file.display(),
46+
music_directory=self.music_directory.display(),
47+
playlist_directory=self.playlist_directory.display(),
48+
sock_path=self.sock_path.display(),
49+
)
50+
}
51+
52+
fn generate(&self) {
53+
create_dir(&self.music_directory).expect("Could not create music directory.");
54+
create_dir(&self.playlist_directory).expect("Could not create playlist directory.");
55+
let mut file = File::create(&self.config_path).expect("Could not create config file.");
56+
file.write_all(self.config_text().as_bytes()).expect("Could not write config file.");
57+
}
5558
}
5659

5760
pub struct Daemon {
@@ -79,7 +82,7 @@ impl Daemon {
7982
pub fn new() -> Daemon {
8083
let temp_dir = TempDir::new("mpd-test").unwrap();
8184
let config = MpdConfig::new(&temp_dir);
82-
write_config(&config);
85+
config.generate();
8386
let process = Command::new("mpd")
8487
.arg("--no-daemon")
8588
.arg(&config.config_path)

0 commit comments

Comments
 (0)