Skip to content

Commit 49240ce

Browse files
0x00A5acatangiu
authored andcommitted
Add unit tests to raise coverage score
Signed-off-by: YUAN LYU <[email protected]>
1 parent 9e6ab4b commit 49240ce

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

coverage_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"coverage_score": 92.5, "exclude_path": "", "crate_features": ""}
1+
{"coverage_score": 93.1, "exclude_path": "", "crate_features": ""}

src/common/headers.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ mod tests {
432432
assert_eq!(headers.content_length(), 0);
433433
assert_eq!(headers.chunked(), false);
434434
assert_eq!(headers.expect(), false);
435+
assert_eq!(headers.accept(), MediaType::PlainText);
435436
}
436437

437438
#[test]
@@ -726,4 +727,13 @@ mod tests {
726727
let header = Header::try_from(b"Accept").unwrap();
727728
assert_eq!(header.raw(), b"Accept");
728729
}
730+
731+
#[test]
732+
fn test_set_accept() {
733+
let mut headers = Headers::default();
734+
assert_eq!(headers.accept(), MediaType::PlainText);
735+
736+
headers.set_accept(MediaType::ApplicationJson);
737+
assert_eq!(headers.accept(), MediaType::ApplicationJson);
738+
}
729739
}

src/common/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,14 @@ mod tests {
522522
);
523523
}
524524

525+
#[test]
526+
fn test_display_route_error() {
527+
assert_eq!(
528+
format!("{}", RouteError::HandlerExist("test".to_string())),
529+
"handler for test already exists"
530+
);
531+
}
532+
525533
#[test]
526534
fn test_method_to_str() {
527535
let val = Method::Get;

src/response.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,15 @@ mod tests {
383383
response.allow_method(Method::Put);
384384
assert_eq!(response.allow(), vec![Method::Get, Method::Put]);
385385
}
386+
387+
#[test]
388+
fn test_equal() {
389+
let response = Response::new(Version::Http10, StatusCode::MethodNotAllowed);
390+
let another_response = Response::new(Version::Http10, StatusCode::MethodNotAllowed);
391+
assert_eq!(response, another_response);
392+
393+
let response = Response::new(Version::Http10, StatusCode::OK);
394+
let another_response = Response::new(Version::Http10, StatusCode::BadRequest);
395+
assert_ne!(response, another_response);
396+
}
386397
}

0 commit comments

Comments
 (0)