fixed tests
This commit is contained in:
parent
dab4d52f4d
commit
9df8ea3558
3 changed files with 27 additions and 18 deletions
|
@ -286,7 +286,10 @@ mod route {
|
|||
let path = std::path::Path::new(path);
|
||||
assert!(path.is_relative());
|
||||
let path = path.to_str().unwrap();
|
||||
assert_eq!(from_str::<Route>(path).unwrap(), Route::Path(path.into()));
|
||||
assert_eq!(
|
||||
from_str::<Route>(path).unwrap(),
|
||||
Route::from_str(path).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -294,14 +297,17 @@ mod route {
|
|||
let tmpfile = NamedTempFile::new().unwrap();
|
||||
let path = format!("{}", tmpfile.path().display());
|
||||
assert!(tmpfile.path().is_absolute());
|
||||
assert_eq!(from_str::<Route>(&path).unwrap(), Route::Path(path));
|
||||
assert_eq!(
|
||||
from_str::<Route>(&path).unwrap(),
|
||||
Route::from_str(&path).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_http_path() {
|
||||
assert_eq!(
|
||||
from_str::<Route>("http://google.com").unwrap(),
|
||||
Route::External("http://google.com".into())
|
||||
Route::from_str("http://google.com").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -309,19 +315,15 @@ mod route {
|
|||
fn deserialize_https_path() {
|
||||
assert_eq!(
|
||||
from_str::<Route>("https://google.com").unwrap(),
|
||||
Route::External("https://google.com".into())
|
||||
Route::from_str("https://google.com").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
assert_eq!(
|
||||
&to_string(&Route::External("hello world".into())).unwrap(),
|
||||
"---\nhello world"
|
||||
);
|
||||
assert_eq!(
|
||||
&to_string(&Route::Path("hello world".into())).unwrap(),
|
||||
"---\nhello world"
|
||||
&to_string(&Route::from_str("hello world").unwrap()).unwrap(),
|
||||
"---\nroute_type: External\npath: hello world\nhidden: false\ndescription: ~"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -248,14 +248,15 @@ mod init_logger {
|
|||
mod cache_routes {
|
||||
use super::*;
|
||||
use std::iter::FromIterator;
|
||||
use std::str::FromStr;
|
||||
|
||||
fn generate_external_routes(
|
||||
routes: &[(&str, &str)],
|
||||
) -> HashMap<String, Route> {
|
||||
HashMap::from_iter(
|
||||
routes
|
||||
.iter()
|
||||
.map(|(k, v)| ((*k).into(), Route::External((*v).into()))),
|
||||
.into_iter()
|
||||
.map(|kv| (kv.0.into(), Route::from_str(kv.1).unwrap())),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -270,12 +271,14 @@ mod cache_routes {
|
|||
name: String::from("x"),
|
||||
description: Some(String::from("y")),
|
||||
routes: generate_external_routes(&[("a", "b"), ("c", "d")]),
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
let group2 = RouteGroup {
|
||||
name: String::from("5"),
|
||||
description: Some(String::from("6")),
|
||||
routes: generate_external_routes(&[("1", "2"), ("3", "4")]),
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
@ -295,12 +298,14 @@ mod cache_routes {
|
|||
name: String::from("x"),
|
||||
description: Some(String::from("y")),
|
||||
routes: generate_external_routes(&[("a", "b"), ("c", "d")]),
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
let group2 = RouteGroup {
|
||||
name: String::from("5"),
|
||||
description: Some(String::from("6")),
|
||||
routes: generate_external_routes(&[("a", "1"), ("c", "2")]),
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
@ -312,6 +317,7 @@ mod cache_routes {
|
|||
name: String::from("5"),
|
||||
description: Some(String::from("6")),
|
||||
routes: generate_external_routes(&[("a", "1"), ("b", "2")]),
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
|
|
@ -205,6 +205,7 @@ fn resolve_path(path: PathBuf, args: &str) -> Result<Vec<u8>, BunBunError> {
|
|||
#[cfg(test)]
|
||||
mod resolve_hop {
|
||||
use super::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
fn generate_route_result<'a>(
|
||||
keyword: &'a Route,
|
||||
|
@ -238,12 +239,12 @@ mod resolve_hop {
|
|||
let mut map: HashMap<String, Route> = HashMap::new();
|
||||
map.insert(
|
||||
"google".into(),
|
||||
Route::External("https://example.com".into()),
|
||||
Route::from_str("https://example.com").unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_hop("hello world", &map, &Some(String::from("google"))),
|
||||
generate_route_result(
|
||||
&Route::External("https://example.com".into()),
|
||||
&Route::from_str("https://example.com").unwrap(),
|
||||
"hello world"
|
||||
),
|
||||
);
|
||||
|
@ -254,12 +255,12 @@ mod resolve_hop {
|
|||
let mut map: HashMap<String, Route> = HashMap::new();
|
||||
map.insert(
|
||||
"google".into(),
|
||||
Route::External("https://example.com".into()),
|
||||
Route::from_str("https://example.com").unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_hop("google hello world", &map, &Some(String::from("a"))),
|
||||
generate_route_result(
|
||||
&Route::External("https://example.com".into()),
|
||||
&Route::from_str("https://example.com").unwrap(),
|
||||
"hello world"
|
||||
),
|
||||
);
|
||||
|
@ -270,12 +271,12 @@ mod resolve_hop {
|
|||
let mut map: HashMap<String, Route> = HashMap::new();
|
||||
map.insert(
|
||||
"google".into(),
|
||||
Route::External("https://example.com".into()),
|
||||
Route::from_str("https://example.com").unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_hop("google hello world", &map, &None),
|
||||
generate_route_result(
|
||||
&Route::External("https://example.com".into()),
|
||||
&Route::from_str("https://example.com").unwrap(),
|
||||
"hello world"
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue