diff options
Diffstat (limited to 'tests/config.rs')
| -rw-r--r-- | tests/config.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/config.rs b/tests/config.rs index 7b9d179..6a44a17 100644 --- a/tests/config.rs +++ b/tests/config.rs | |||
| @@ -21,6 +21,7 @@ fn test_config_get_scan_interval() { | |||
| 21 | volume: None, | 21 | volume: None, |
| 22 | shuffle: None, | 22 | shuffle: None, |
| 23 | display_format: Some(String::from("$ARTIST - $TRACK")), | 23 | display_format: Some(String::from("$ARTIST - $TRACK")), |
| 24 | sample_rate: None, | ||
| 24 | }; | 25 | }; |
| 25 | assert_eq!(config.get("scan_interval").unwrap(), "3600"); | 26 | assert_eq!(config.get("scan_interval").unwrap(), "3600"); |
| 26 | } | 27 | } |
| @@ -38,6 +39,7 @@ fn test_config_get_not_set() { | |||
| 38 | volume: None, | 39 | volume: None, |
| 39 | shuffle: None, | 40 | shuffle: None, |
| 40 | display_format: None, | 41 | display_format: None, |
| 42 | sample_rate: None, | ||
| 41 | }; | 43 | }; |
| 42 | assert_eq!(config.get("scan_interval").unwrap(), "not set"); | 44 | assert_eq!(config.get("scan_interval").unwrap(), "not set"); |
| 43 | } | 45 | } |
| @@ -55,6 +57,7 @@ fn test_config_get_volume() { | |||
| 55 | volume: Some(75), | 57 | volume: Some(75), |
| 56 | shuffle: None, | 58 | shuffle: None, |
| 57 | display_format: None, | 59 | display_format: None, |
| 60 | sample_rate: None, | ||
| 58 | }; | 61 | }; |
| 59 | assert_eq!(config.get("volume").unwrap(), "75"); | 62 | assert_eq!(config.get("volume").unwrap(), "75"); |
| 60 | } | 63 | } |
| @@ -135,6 +138,7 @@ fn test_config_unset_volume() { | |||
| 135 | volume: Some(50), | 138 | volume: Some(50), |
| 136 | shuffle: None, | 139 | shuffle: None, |
| 137 | display_format: None, | 140 | display_format: None, |
| 141 | sample_rate: None, | ||
| 138 | }; | 142 | }; |
| 139 | config.unset("volume").unwrap(); | 143 | config.unset("volume").unwrap(); |
| 140 | assert_eq!(config.volume, None); | 144 | assert_eq!(config.volume, None); |
| @@ -146,3 +150,41 @@ fn test_config_unset_unknown_key() { | |||
| 146 | let result = config.unset("unknown_key"); | 150 | let result = config.unset("unknown_key"); |
| 147 | assert!(result.is_err()); | 151 | assert!(result.is_err()); |
| 148 | } | 152 | } |
| 153 | |||
| 154 | #[test] | ||
| 155 | fn test_config_sample_rate_defaults_to_auto() { | ||
| 156 | let config = Config { | ||
| 157 | config_path: PathBuf::from("/test/config.toml"), | ||
| 158 | music_paths: vec![], | ||
| 159 | scan_interval: None, | ||
| 160 | lastfm_api_key: None, | ||
| 161 | lastfm_api_secret: None, | ||
| 162 | lastfm_session_key: None, | ||
| 163 | listenbrainz_token: None, | ||
| 164 | volume: None, | ||
| 165 | shuffle: None, | ||
| 166 | display_format: None, | ||
| 167 | sample_rate: None, | ||
| 168 | }; | ||
| 169 | assert_eq!(config.get("sample_rate").unwrap(), "auto"); | ||
| 170 | assert_eq!(config.sample_rate_hz(), None); | ||
| 171 | } | ||
| 172 | |||
| 173 | #[test] | ||
| 174 | fn test_config_set_sample_rate() { | ||
| 175 | let mut config = Config::default(); | ||
| 176 | config.set("sample_rate", "48000").unwrap(); | ||
| 177 | assert_eq!(config.get("sample_rate").unwrap(), "48000"); | ||
| 178 | assert_eq!(config.sample_rate_hz(), Some(48_000)); | ||
| 179 | |||
| 180 | config.set("sample_rate", "auto").unwrap(); | ||
| 181 | assert_eq!(config.sample_rate_hz(), None); | ||
| 182 | } | ||
| 183 | |||
| 184 | #[test] | ||
| 185 | fn test_config_rejects_bad_sample_rate() { | ||
| 186 | let mut config = Config::default(); | ||
| 187 | assert!(config.set("sample_rate", "fast").is_err()); | ||
| 188 | assert!(config.set("sample_rate", "100").is_err()); | ||
| 189 | assert!(config.set("sample_rate", "999999").is_err()); | ||
| 190 | } | ||
