mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
more scope tests
This commit is contained in:
parent
3b08b16c11
commit
17f1a2b92a
@ -313,8 +313,8 @@ impl Resource {
|
|||||||
}
|
}
|
||||||
PatternType::Prefix(ref s) => if path == s {
|
PatternType::Prefix(ref s) => if path == s {
|
||||||
Some(s.len())
|
Some(s.len())
|
||||||
} else if path.starts_with(s) && (s.ends_with('/') ||
|
} else if path.starts_with(s)
|
||||||
path.split_at(s.len()).1.starts_with('/'))
|
&& (s.ends_with('/') || path.split_at(s.len()).1.starts_with('/'))
|
||||||
{
|
{
|
||||||
if s.ends_with('/') {
|
if s.ends_with('/') {
|
||||||
Some(s.len() - 1)
|
Some(s.len() - 1)
|
||||||
|
76
src/scope.rs
76
src/scope.rs
@ -792,6 +792,40 @@ mod tests {
|
|||||||
assert_eq!(resp.as_msg().status(), StatusCode::CREATED);
|
assert_eq!(resp.as_msg().status(), StatusCode::CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_scope_root2() {
|
||||||
|
let mut app = App::new()
|
||||||
|
.scope("/app/", |scope| {
|
||||||
|
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
})
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_scope_root3() {
|
||||||
|
let mut app = App::new()
|
||||||
|
.scope("/app/", |scope| {
|
||||||
|
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
})
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_scope_route() {
|
fn test_scope_route() {
|
||||||
let mut app = App::new()
|
let mut app = App::new()
|
||||||
@ -916,6 +950,48 @@ mod tests {
|
|||||||
assert_eq!(resp.as_msg().status(), StatusCode::CREATED);
|
assert_eq!(resp.as_msg().status(), StatusCode::CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_scope_with_state_root2() {
|
||||||
|
struct State;
|
||||||
|
|
||||||
|
let mut app = App::new()
|
||||||
|
.scope("/app", |scope| {
|
||||||
|
scope.with_state("/t1/", State, |scope| {
|
||||||
|
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/t1").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/t1/").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_scope_with_state_root3() {
|
||||||
|
struct State;
|
||||||
|
|
||||||
|
let mut app = App::new()
|
||||||
|
.scope("/app", |scope| {
|
||||||
|
scope.with_state("/t1/", State, |scope| {
|
||||||
|
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/t1").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/app/t1/").finish();
|
||||||
|
let resp = app.run(req);
|
||||||
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_scope_with_state_filter() {
|
fn test_scope_with_state_filter() {
|
||||||
struct State;
|
struct State;
|
||||||
|
Loading…
Reference in New Issue
Block a user