From 5161bf5082edb7e16b1cc0bf4f56e2706d692f4b Mon Sep 17 00:00:00 2001 From: Robin Arnold <1297660+RRArny@users.noreply.github.com> Date: Sun, 24 Nov 2024 16:35:55 +0100 Subject: [PATCH] Switched to tokio::test for unit tests. Closing #3. --- Cargo.lock | 31 ++++++++ Cargo.toml | 4 +- src/api.rs | 7 +- src/config.rs | 4 +- src/main.rs | 9 +-- src/metar.rs | 112 ++++++++++++++-------------- src/metar/clouds.rs | 24 +++--- src/metar/units.rs | 13 ++-- src/metar/wxcodes.rs | 173 ++++++++++++++++++++++--------------------- src/position.rs | 4 +- 10 files changed, 209 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aceaabb..7c7bd4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,6 +257,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -442,6 +465,12 @@ version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "1.4.1" @@ -1622,6 +1651,8 @@ dependencies = [ "chrono", "clap", "colored", + "env_logger", + "log", "regex", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3fd218d..c6c79b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,12 +13,14 @@ anyhow = "1.0.86" chrono = "0.4.38" clap = { version = "4.5.7", features = ["derive"] } colored = "2" +env_logger = "0.11.5" +log = "0.4.22" regex = "1.10.5" reqwest = { version = "0.12.5", features = ["json"] } serde = "1.0.203" serde_json = "1.0.117" strum = { version = "0.26.3", features = ["derive", "strum_macros"] } strum_macros = "0.26.4" -tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.38.0", features = ["macros", "rt", "rt-multi-thread"] } tokio-macros = "2.3.0" toml = "0.8.14" diff --git a/src/api.rs b/src/api.rs index 632b2b3..d4507f8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -10,6 +10,7 @@ // limitations under the License. // WxFetch - api.rs +use log::error; use reqwest::{Client, Error, Response}; use serde_json::Value; @@ -19,9 +20,13 @@ use crate::{Config, Secrets}; pub async fn request_wx(config: &Config, secrets: &Secrets) -> Option { let position = config.position.get_location_str().await; let resp = send_api_call(position, secrets).await.ok()?; + let status = resp.status().as_u16(); - if resp.status().as_u16() == 200 { + if status == 200 { resp.json().await.ok() + } else if status == 401 { + error!("Weather request failed. Provide a valid AvWx API key."); + None } else if let Some(nearest_station_code) = get_nearest_station(config, secrets).await { send_api_call(nearest_station_code, secrets) .await diff --git a/src/config.rs b/src/config.rs index c388ec6..a133ea1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -192,8 +192,8 @@ fn read_config_file(config_filepath: Option) -> Config { mod test { use super::*; - #[test] - fn test_read_config_file() { + #[tokio::test] + async fn test_read_config_file() { let expected = Config::default(); let actual = read_config_file(Some("./config.toml".to_string())); assert_eq!(expected, actual); diff --git a/src/main.rs b/src/main.rs index c8cc49a..aba4026 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,11 +52,8 @@ struct Secrets { } fn get_secrets(param: Option) -> Secrets { - let avwx_api_key = if let Some(key) = param { - key - } else { - std::env::var("AVWX_API_KEY").expect("Could not load secret keys.") - }; + let avwx_api_key = + param.unwrap_or(std::env::var("AVWX_API_KEY").expect("Could not load secret key.")); Secrets { avwx_api_key } } @@ -82,7 +79,7 @@ async fn main() { None => get_weather(&config, &secrets).await, }; let wx_string = Metar::from_json(&json, &config) - .expect("Invalid weather data received...") + .expect("Invalid weather data received.") .colorise(&config); println!("{wx_string}"); diff --git a/src/metar.rs b/src/metar.rs index 6f18f22..71c3875 100644 --- a/src/metar.rs +++ b/src/metar.rs @@ -404,8 +404,8 @@ mod tests { use super::*; - #[test] - fn test_metar_from_json_icao() { + #[tokio::test] + async fn test_metar_from_json_icao() { let json: Value = Value::from_str("{\"station\":\"EDRK\"}").unwrap(); let config = Config { position: Position::Airfield("EDRK".to_string()), @@ -415,8 +415,8 @@ mod tests { assert!(metar.is_some_and(|m| m.icao_code == "EDRK")); } - #[test] - fn test_metar_from_json_time() { + #[tokio::test] + async fn test_metar_from_json_time() { let json: Value = Value::from_str("{\"time\":{\"dt\":\"2024-06-21T05:50:00Z\"}}").unwrap(); let config = Config { position: Position::Airfield("EDRK".to_string()), @@ -427,8 +427,8 @@ mod tests { assert!(metar.is_some_and(|m| m.fields.contains(&WxField::TimeStamp(expected)))); } - #[test] - fn test_is_exact_match_positive() { + #[tokio::test] + async fn test_is_exact_match_positive() { let config = Config { position: Position::Airfield("EDDK".to_string()), ..Default::default() @@ -436,8 +436,8 @@ mod tests { assert!(is_exact_match("EDDK", &config)); } - #[test] - fn test_is_exact_match_negative() { + #[tokio::test] + async fn test_is_exact_match_negative() { let config = Config { position: Position::Airfield("EDDK".to_string()), ..Default::default() @@ -445,8 +445,8 @@ mod tests { assert!(!is_exact_match("EDRK", &config)); } - #[test] - fn test_is_exact_match_geoip() { + #[tokio::test] + async fn test_is_exact_match_geoip() { let config = Config { position: Position::GeoIP, ..Default::default() @@ -454,8 +454,8 @@ mod tests { assert!(is_exact_match("EDRK", &config)); } - #[test] - fn test_is_exact_match_latlong() { + #[tokio::test] + async fn test_is_exact_match_latlong() { let config = Config { position: Position::LatLong(LatLong(10.0, 10.0)), ..Default::default() @@ -463,29 +463,29 @@ mod tests { assert!(is_exact_match("EDRK", &config)); } - #[test] - fn test_colourise_visibility_good() { + #[tokio::test] + async fn test_colourise_visibility_good() { let config = Config::default(); let vis_str: ColoredString = colourise_visibility(9999, &config); assert_eq!(vis_str.fgcolor(), Some(Color::Green)); } - #[test] - fn test_colourise_visibility_medium() { + #[tokio::test] + async fn test_colourise_visibility_medium() { let config = Config::default(); let vis_str: ColoredString = colourise_visibility(2000, &config); assert_eq!(vis_str.fgcolor(), Some(Color::Yellow)); } - #[test] - fn test_colourise_visibility_bad() { + #[tokio::test] + async fn test_colourise_visibility_bad() { let config = Config::default(); let vis_str: ColoredString = colourise_visibility(1000, &config); assert_eq!(vis_str.fgcolor(), Some(Color::Red)); } - #[test] - fn test_get_winds() { + #[tokio::test] + async fn test_get_winds() { let json: Value = Value::from_str("{\"wind_direction\": {\"value\":100}, \"wind_speed\":{\"value\":10}, \"wind_gust\":{\"value\":15}}").unwrap(); let expected = WxField::Wind { direction: 100, @@ -497,8 +497,8 @@ mod tests { assert!(actual.is_some_and(|w| w == expected)); } - #[test] - fn test_get_winds_no_gust() { + #[tokio::test] + async fn test_get_winds_no_gust() { let json: Value = Value::from_str("{\"wind_direction\": {\"value\":100}, \"wind_speed\":{\"value\":10}}") .unwrap(); @@ -512,16 +512,16 @@ mod tests { assert!(actual.is_some_and(|w| w == expected)); } - #[test] - fn test_get_qnh() { + #[tokio::test] + async fn test_get_qnh() { let json: Value = Value::from_str("{\"altimeter\":{\"value\": 1013}}").unwrap(); let expected = WxField::Qnh(1013, PressureUnit::Hpa); let actual = get_qnh(&json, Units::default()); assert!(actual.is_some_and(|q| q == expected)); } - #[test] - fn test_get_qnh_inhg() { + #[tokio::test] + async fn test_get_qnh_inhg() { let json: Value = Value::from_str("{\"altimeter\":{\"value\": 29.92}}").unwrap(); let expected = WxField::Qnh(2992, PressureUnit::Inhg); let units = Units { @@ -536,16 +536,16 @@ mod tests { assert!(actual.is_some_and(|q| q == expected)); } - #[test] - fn test_get_remarks() { + #[tokio::test] + async fn test_get_remarks() { let json: Value = Value::from_str("{\"remarks\":\"RWY UNAVAILABLE\"}").unwrap(); let expected = "RWY UNAVAILABLE".to_string(); let actual = get_remarks(&json); assert!(actual.is_some_and(|r| r == WxField::Remarks(expected))); } - #[test] - fn test_get_temp() { + #[tokio::test] + async fn test_get_temp() { let json: Value = Value::from_str("{\"temperature\":{\"value\": 10}, \"dewpoint\":{\"value\": 9}}") .unwrap(); @@ -558,8 +558,8 @@ mod tests { assert!(actual.is_some_and(|t| t == expected)); } - #[test] - fn test_get_wind_var() { + #[tokio::test] + async fn test_get_wind_var() { let json: Value = Value::from_str("{\"wind_variable_direction\":[{\"value\" : 80},{\"value\" : 150}]}") .unwrap(); @@ -571,16 +571,16 @@ mod tests { assert!(actual.is_some_and(|v| v == expected)); } - #[test] - fn test_get_visibility() { + #[tokio::test] + async fn test_get_visibility() { let json: Value = Value::from_str("{\"visibility\":{\"value\":9999}}").unwrap(); let expected: WxField = WxField::Visibility(9999); let actual = get_visibility(&json, Units::default()); assert!(actual.is_some_and(|v| v == expected)); } - #[test] - fn test_colourise_vis() { + #[tokio::test] + async fn test_colourise_vis() { let config = Config::default(); let vis = WxField::Visibility(9999); let expected = colourise_visibility(9999, &config); @@ -588,8 +588,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_wind() { + #[tokio::test] + async fn test_colourise_wind() { let config = Config::default(); let wind = WxField::Wind { direction: 0, @@ -602,8 +602,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_wind_var() { + #[tokio::test] + async fn test_colourise_wind_var() { let config = Config::default(); let wind = WxField::WindVariability { low_dir: 0, @@ -614,8 +614,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_temp() { + #[tokio::test] + async fn test_colourise_temp() { let config = Config::default(); let temp = WxField::Temperature { temp: 20, @@ -627,8 +627,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_qnh() { + #[tokio::test] + async fn test_colourise_qnh() { let config = Config::default(); let qnh = WxField::Qnh(1013, PressureUnit::Hpa); let expected = colourise_qnh(1013, PressureUnit::Hpa, &config); @@ -636,8 +636,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_wxcode() { + #[tokio::test] + async fn test_colourise_wxcode() { let config = Config::default(); let wxcode = WxField::WxCode( WxCode::Ra, @@ -656,8 +656,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_rmk() { + #[tokio::test] + async fn test_colourise_rmk() { let config = Config::default(); let rmk = WxField::Remarks("NONE".to_string()); let expected = "NONE".black().on_white(); @@ -665,8 +665,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_clouds() { + #[tokio::test] + async fn test_colourise_clouds() { let config = Config::default(); let clouds = WxField::Clouds(Clouds::Sct, 50); let expected = colourise_clouds(&Clouds::Sct, 50, &config); @@ -674,8 +674,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_timestamp() { + #[tokio::test] + async fn test_colourise_timestamp() { let config = Config::default(); let fixed_offset = Utc::now().fixed_offset(); let timestamp = WxField::TimeStamp(fixed_offset); @@ -684,8 +684,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_clouds_marginal() { + #[tokio::test] + async fn test_colourise_clouds_marginal() { let config = Config::default(); let clouds = WxField::Clouds(Clouds::Ovc, 8); let expected = colourise_clouds(&Clouds::Ovc, 8, &config); @@ -693,8 +693,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_colourise_clouds_bad() { + #[tokio::test] + async fn test_colourise_clouds_bad() { let config = Config::default(); let clouds = WxField::Clouds(Clouds::Brk, 5); let expected = colourise_clouds(&Clouds::Brk, 5, &config); diff --git a/src/metar/clouds.rs b/src/metar/clouds.rs index 9e95617..eb88b97 100644 --- a/src/metar/clouds.rs +++ b/src/metar/clouds.rs @@ -113,41 +113,41 @@ mod tests { use super::{clouds_from_str, get_clouds_from_json, Clouds}; - #[test] - fn test_get_regex() { + #[tokio::test] + async fn test_get_regex() { let expected: &str = "SKC|FEW|SCT|BRK|OVC"; let actual = Clouds::get_regex(); assert_eq!(expected, actual); } - #[test] - fn test_clouds_from_str() { + #[tokio::test] + async fn test_clouds_from_str() { let expected = WxField::Clouds(Clouds::Skc, 0); let actual = clouds_from_str("SKC"); assert_eq!(Some(expected), actual); } - #[test] - fn test_clouds_from_str_sct() { + #[tokio::test] + async fn test_clouds_from_str_sct() { let expected = WxField::Clouds(Clouds::Sct, 50); let actual = clouds_from_str("SCT50"); assert_eq!(Some(expected), actual); } - #[test] - fn test_clouds_from_str_err() { + #[tokio::test] + async fn test_clouds_from_str_err() { let actual = clouds_from_str("OCC33"); assert!(actual.is_none()); } - #[test] - fn test_from_str_err() { + #[tokio::test] + async fn test_from_str_err() { let str = "CLS9999"; assert!(Clouds::from_str(str).is_err()); } - #[test] - fn test_get_clouds() { + #[tokio::test] + async fn test_get_clouds() { let json: Value = Value::from_str( "{\"clouds\":[{\"repr\": \"SCT050\"},{\"repr\": \"BRK100\"},{\"repr\": \"OVC200\"}]}", ) diff --git a/src/metar/units.rs b/src/metar/units.rs index 001f758..295f556 100644 --- a/src/metar/units.rs +++ b/src/metar/units.rs @@ -160,8 +160,8 @@ mod tests { use super::*; - #[test] - fn test_units_from_json_empty() { + #[tokio::test] + async fn test_units_from_json_empty() { let json: Value = Value::from_str("{}").unwrap(); let expected: Units = Units { pressure: PressureUnit::Hpa, @@ -173,8 +173,9 @@ mod tests { let actual = Units::from_json(&json); assert_eq!(actual, expected); } - #[test] - fn test_units_from_json_invalid() { + + #[tokio::test] + async fn test_units_from_json_invalid() { let json: Value = Value::from_str("{\"units\":{\"altimeter\": \"aa\",\"altitude\":\"bb\",\"temperature\":\"cc\",\"wind_speed\": \"dd\", \"visibility\":\"ee\"}}").unwrap(); let expected: Units = Units { pressure: PressureUnit::Hpa, @@ -187,8 +188,8 @@ mod tests { assert_eq!(actual, expected); } - #[test] - fn test_units_from_json_us_units() { + #[tokio::test] + async fn test_units_from_json_us_units() { let json: Value = Value::from_str("{\"units\":{\"altimeter\": \"inHg\",\"altitude\":\"ft\",\"temperature\":\"F\",\"wind_speed\": \"mph\", \"visibility\":\"mi\"}}").unwrap(); let expected: Units = Units { pressure: PressureUnit::Inhg, diff --git a/src/metar/wxcodes.rs b/src/metar/wxcodes.rs index 3e7253c..62caa1c 100644 --- a/src/metar/wxcodes.rs +++ b/src/metar/wxcodes.rs @@ -347,29 +347,29 @@ mod tests { use super::{get_wxcodes_from_json, WxCode, WxCodeIntensity}; use crate::metar::{wxcodes::WxCodeDescription, WxCodeProximity, WxField}; - #[test] - fn test_get_regex() { + #[tokio::test] + async fn test_get_regex() { let expected: &str = "RA|DZ|GR|GS|IC|PL|SG|SN|UP|BR|DU|FG|FU|HZ|PY|SA|VA|DS|FC|PO|SQ|SS"; let actual = WxCode::get_regex(); assert_eq!(expected, actual); } - #[test] - fn test_get_wxcodes_empty() { + #[tokio::test] + async fn test_get_wxcodes_empty() { let json: Value = Value::from_str("{\"wx_codes\":[]}").unwrap(); let actual = get_wxcodes_from_json(&json); assert!(actual.is_empty()); } - #[test] - fn test_get_wxcodes_no_field() { + #[tokio::test] + async fn test_get_wxcodes_no_field() { let json: Value = Value::from_str("{}").unwrap(); let actual = get_wxcodes_from_json(&json); assert!(actual.is_empty()); } - #[test] - fn test_get_wxcodes_one() { + #[tokio::test] + async fn test_get_wxcodes_one() { let expected: Vec = vec![WxField::WxCode( WxCode::Ra, WxCodeIntensity::Light, @@ -381,267 +381,268 @@ mod tests { assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_ra() { + #[tokio::test] + async fn test_wxcode_from_str_ra() { let expected = WxCode::Ra; let actual = WxCode::from_str("RA").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_dz() { + #[tokio::test] + async fn test_wxcode_from_str_dz() { let expected = WxCode::Dz; let actual = WxCode::from_str("DZ").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_gr() { + #[tokio::test] + async fn test_wxcode_from_str_gr() { let expected = WxCode::Gr; let actual = WxCode::from_str("GR").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_gs() { + #[tokio::test] + async fn test_wxcode_from_str_gs() { let expected = WxCode::Gs; let actual = WxCode::from_str("GS").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_ic() { + #[tokio::test] + async fn test_wxcode_from_str_ic() { let expected = WxCode::Ic; let actual = WxCode::from_str("IC").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_pl() { + #[tokio::test] + async fn test_wxcode_from_str_pl() { let expected = WxCode::Pl; let actual = WxCode::from_str("PL").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_sg() { + #[tokio::test] + async fn test_wxcode_from_str_sg() { let expected = WxCode::Sg; let actual = WxCode::from_str("SG").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_sn() { + #[tokio::test] + async fn test_wxcode_from_str_sn() { let expected = WxCode::Sn; let actual = WxCode::from_str("SN").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_up() { + #[tokio::test] + async fn test_wxcode_from_str_up() { let expected = WxCode::Up; let actual = WxCode::from_str("UP").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_br() { + #[tokio::test] + async fn test_wxcode_from_str_br() { let expected = WxCode::Br; let actual = WxCode::from_str("BR").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_du() { + #[tokio::test] + async fn test_wxcode_from_str_du() { let expected = WxCode::Du; let actual = WxCode::from_str("DU").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_fg() { + #[tokio::test] + async fn test_wxcode_from_str_fg() { let expected = WxCode::Fg; let actual = WxCode::from_str("FG").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_fu() { + #[tokio::test] + async fn test_wxcode_from_str_fu() { let expected = WxCode::Fu; let actual = WxCode::from_str("FU").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_hz() { + #[tokio::test] + async fn test_wxcode_from_str_hz() { let expected = WxCode::Hz; let actual = WxCode::from_str("HZ").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_py() { + #[tokio::test] + async fn test_wxcode_from_str_py() { let expected = WxCode::Py; let actual = WxCode::from_str("PY").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_sa() { + #[tokio::test] + async fn test_wxcode_from_str_sa() { let expected = WxCode::Sa; let actual = WxCode::from_str("SA").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_va() { + #[tokio::test] + async fn test_wxcode_from_str_va() { let expected = WxCode::Va; let actual = WxCode::from_str("VA").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_ds() { + #[tokio::test] + async fn test_wxcode_from_str_ds() { let expected = WxCode::Ds; let actual = WxCode::from_str("DS").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_fc() { + #[tokio::test] + async fn test_wxcode_from_str_fc() { let expected = WxCode::Fc; let actual = WxCode::from_str("FC").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_po() { + #[tokio::test] + async fn test_wxcode_from_str_po() { let expected = WxCode::Po; let actual = WxCode::from_str("PO").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_sq() { + #[tokio::test] + async fn test_wxcode_from_str_sq() { let expected = WxCode::Sq; let actual = WxCode::from_str("SQ").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_ss() { + #[tokio::test] + async fn test_wxcode_from_str_ss() { let expected = WxCode::Ss; let actual = WxCode::from_str("SS").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_wxcode_from_str_invalid() { + #[tokio::test] + async fn test_wxcode_from_str_invalid() { assert!(WxCode::from_str("INVALID").is_err()); } - #[test] - fn test_prox_from_str_dist() { + #[tokio::test] + async fn test_prox_from_str_dist() { let expected = WxCodeProximity::Distant; let actual = WxCodeProximity::from_str("DSNT").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_prox_from_str_vic() { + #[tokio::test] + async fn test_prox_from_str_vic() { let expected = WxCodeProximity::Vicinity; let actual = WxCodeProximity::from_str("VC").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_prox_from_str_invalid() { + #[tokio::test] + async fn test_prox_from_str_invalid() { assert!(WxCodeProximity::from_str("SOMEWHEREELSE").is_err()); } - #[test] - fn test_desc_from_str_ts() { + #[tokio::test] + async fn test_desc_from_str_ts() { let expected = WxCodeDescription::Ts; let actual = WxCodeDescription::from_str("TS").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_bc() { + #[tokio::test] + async fn test_desc_from_str_bc() { let expected = WxCodeDescription::Bc; let actual = WxCodeDescription::from_str("BC").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_bl() { + #[tokio::test] + async fn test_desc_from_str_bl() { let expected = WxCodeDescription::Bl; let actual = WxCodeDescription::from_str("BL").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_dr() { + #[tokio::test] + async fn test_desc_from_str_dr() { let expected = WxCodeDescription::Dr; let actual = WxCodeDescription::from_str("DR").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_fz() { + #[tokio::test] + async fn test_desc_from_str_fz() { let expected = WxCodeDescription::Fz; let actual = WxCodeDescription::from_str("FZ").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_mi() { + #[tokio::test] + async fn test_desc_from_str_mi() { let expected = WxCodeDescription::Mi; let actual = WxCodeDescription::from_str("MI").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_pr() { + #[tokio::test] + async fn test_desc_from_str_pr() { let expected = WxCodeDescription::Pr; let actual = WxCodeDescription::from_str("PR").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_sh() { + #[tokio::test] + async fn test_desc_from_str_sh() { let expected = WxCodeDescription::Sh; let actual = WxCodeDescription::from_str("SH").unwrap(); assert_eq!(expected, actual); } - #[test] - fn test_desc_from_str_invalid() { + #[tokio::test] + async fn test_desc_from_str_invalid() { assert!(WxCodeDescription::from_str("SOME").is_err()); } - #[test] - fn test_intens_from_str_invalid() { + #[tokio::test] + async fn test_intens_from_str_invalid() { assert!(WxCodeIntensity::from_str("#").is_err()) } - #[test] - fn test_intens_display_light() { + #[tokio::test] + async fn test_intens_display_light() { let code = WxCodeIntensity::Light; let expected = "-"; let actual = code.to_string(); assert_eq!(expected, actual); } - #[test] - fn test_intens_display_moderate() { + #[tokio::test] + async fn test_intens_display_moderate() { let code = WxCodeIntensity::Moderate; let expected = ""; let actual = code.to_string(); assert_eq!(expected, actual); } - #[test] - fn test_intens_display_heavy() { + + #[tokio::test] + async fn test_intens_display_heavy() { let code = WxCodeIntensity::Heavy; let expected = "+"; let actual = code.to_string(); diff --git a/src/position.rs b/src/position.rs index ad15dfc..40cac89 100644 --- a/src/position.rs +++ b/src/position.rs @@ -61,8 +61,8 @@ async fn get_geoip() -> Option { mod test { use super::*; - #[test] - fn test_display_latlong() { + #[tokio::test] + async fn test_display_latlong() { let latlon = LatLong(51.4, 8.5); let expected = "51.4,8.5"; let actual = latlon.to_string();