Skip to content

Commit e6b3544

Browse files
committed
A little less magical
1 parent 919b5e4 commit e6b3544

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

tests/common/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ pub struct TestCase {
1515
}
1616

1717
impl TestCase {
18-
pub async fn new(request_file_name: &str, response_file_name: &str) -> TestCase {
19-
let request_fixture = File::open(fixture_path(&request_file_name))
18+
pub async fn new(request_file_path: &str, response_file_path: &str) -> TestCase {
19+
let request_fixture = File::open(fixture_path(&request_file_path))
2020
.await
2121
.expect(&format!(
22-
"Could not open request fixture file: {}",
23-
request_file_name
22+
"Could not open request fixture file: {:?}",
23+
&fixture_path(request_file_path)
2424
));
2525
let request_fixture = Arc::new(request_fixture);
2626

2727
let response_fixture =
28-
File::open(fixture_path(&response_file_name))
28+
File::open(fixture_path(&response_file_path))
2929
.await
3030
.expect(&format!(
31-
"Could not open response fixture file: {}",
32-
response_file_name
31+
"Could not open response fixture file: {:?}",
32+
&fixture_path(response_file_path)
3333
));
3434
let response_fixture = Arc::new(Mutex::new(response_fixture));
3535

@@ -94,10 +94,9 @@ impl TestCase {
9494
}
9595
}
9696

97-
fn fixture_path(name: &str) -> PathBuf {
97+
fn fixture_path(relative_path: &str) -> PathBuf {
9898
let directory: PathBuf = env!("CARGO_MANIFEST_DIR").into();
99-
let relative_path: PathBuf = format!("tests/fixtures/{}.txt", name).into();
100-
directory.join(relative_path)
99+
directory.join("tests").join(relative_path)
101100
}
102101

103102
impl Read for TestCase {

tests/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use http_types::{Response, StatusCode};
77
#[test]
88
fn test_basic_request() {
99
task::block_on(async {
10-
let case = TestCase::new("request1", "response1").await;
10+
let case = TestCase::new("fixtures/request1.txt", "fixtures/response1.txt").await;
1111
let addr = "http://example.com";
1212

1313
server::accept(addr, case.clone(), |_req| async {

0 commit comments

Comments
 (0)