summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-08 12:07:06 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-08 12:07:06 -0700
commit74196d6e4fbed6a1157ac29afcfe14728ecef03c (patch)
tree370df322bfd4df66efa084e55bef25b1d87e018e
parent5c474afe36c9a7f0fe89b67c214a566d02091208 (diff)
Add tests for url parsing
-rw-r--r--TODO.md3
-rw-r--r--roadmap.md3
-rw-r--r--src/stackexchange.rs25
3 files changed, 20 insertions, 11 deletions
diff --git a/TODO.md b/TODO.md
index 59b1f47..60ab5f7 100644
--- a/TODO.md
+++ b/TODO.md
@@ -12,6 +12,9 @@
4. Display with [space] to see more, any other key to exit.
### v0.2.1
+1. Add colors.yml configuration
+
+### v0.2.2
1. Site can be multiple
2. do tokio async on SE api
3. add warning to README about throttling on excessive requests
diff --git a/roadmap.md b/roadmap.md
index 0efa01a..0bd6a85 100644
--- a/roadmap.md
+++ b/roadmap.md
@@ -16,6 +16,9 @@
[ ] Termimad interface for viewing multiple results
### v0.2.1
+[ ] Add colors.yml configuration
+
+### v0.2.2
[ ] Support multiple --site args & searches
### v0.3.0
diff --git a/src/stackexchange.rs b/src/stackexchange.rs
index 58a2c0f..a790a2a 100644
--- a/src/stackexchange.rs
+++ b/src/stackexchange.rs
@@ -11,7 +11,8 @@ use crate::config::{project_dir, Config};
use crate::error::{Error, ErrorKind, Result};
/// StackExchange API v2.2 URL
-const SE_URL: &str = "http://api.stackexchange.com/2.2/";
+const SE_API_URL: &str = "http://api.stackexchange.com";
+const SE_API_VERSION: &str = "2.2";
/// Filter generated to include only the fields needed to populate
/// the structs below. Go here to make new filters:
@@ -220,22 +221,24 @@ impl LocalStorage {
}
}
-/// Creates url from const string; can technically panic
+/// Creates stackexchange API url given endpoint; can technically panic
fn stackexchange_url(path: &str) -> Url {
- let mut url = Url::parse(SE_URL).unwrap();
- url.set_path(path);
+ let mut url = Url::parse(SE_API_URL).unwrap();
+ url.path_segments_mut()
+ .unwrap()
+ .push(SE_API_VERSION)
+ .extend(path.split('/'));
url
}
#[cfg(test)]
mod tests {
- // TODO for both, detect situation and print helpful error message
+ use super::*;
#[test]
- fn test_invalid_api_key() {
- assert!(true)
- }
- #[test]
- fn test_invalid_filter() {
- assert!(true)
+ fn test_stackexchange_url() {
+ assert_eq!(
+ stackexchange_url("some/endpoint").as_str(),
+ "http://api.stackexchange.com/2.2/some/endpoint"
+ )
}
}