From a07c1bdf4da77c8227c110e750fce7169618d75e Mon Sep 17 00:00:00 2001 From: khai96_ Date: Mon, 29 Apr 2019 01:07:02 +0700 Subject: Split integration test into multiple files --- tests/auth.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/auth.rs (limited to 'tests/auth.rs') diff --git a/tests/auth.rs b/tests/auth.rs new file mode 100644 index 0000000..cefc7ec --- /dev/null +++ b/tests/auth.rs @@ -0,0 +1,50 @@ +mod helpers; +use helpers::*; + +#[rstest_parametrize( + cli_auth_arg, client_username, client_password, + case("testuser:testpassword", "testuser", "testpassword"), + case( + "testuser:sha256:9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05", + "testuser", + "testpassword" + ), + case( + "testuser:sha512:e9e633097ab9ceb3e48ec3f70ee2beba41d05d5420efee5da85f97d97005727587fda33ef4ff2322088f4c79e8133cc9cd9f3512f4d3a303cbdb5bc585415a00", + "testuser", + "testpassword" + ), +)] +fn auth_works( + tmpdir: TempDir, + port: u16, + cli_auth_arg: &str, + client_username: &str, + client_password: &str +) -> Result<(), Error> { + let mut child = Command::cargo_bin("miniserve")? + .arg(tmpdir.path()) + .arg("-p") + .arg(port.to_string()) + .arg("-a") + .arg(cli_auth_arg) + .stdout(Stdio::null()) + .spawn()?; + + sleep(Duration::from_secs(1)); + + let client = reqwest::Client::new(); + let body = client + .get(format!("http://localhost:{}", port).as_str()) + .basic_auth(client_username, Some(client_password)) + .send()? + .error_for_status()?; + let parsed = Document::from_read(body)?; + for &file in FILES { + assert!(parsed.find(Text).any(|x| x.text() == file)); + } + + child.kill()?; + + Ok(()) +} -- cgit v1.2.3 From 014bc52dc0e693bca8183bcf19c813452a34cc1c Mon Sep 17 00:00:00 2001 From: khai96_ Date: Mon, 29 Apr 2019 18:37:04 +0700 Subject: Move helpers.rs to fixtures/mod.rs --- tests/auth.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auth.rs') diff --git a/tests/auth.rs b/tests/auth.rs index cefc7ec..48f070e 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,5 +1,5 @@ -mod helpers; -use helpers::*; +mod fixtures; +use fixtures::*; #[rstest_parametrize( cli_auth_arg, client_username, client_password, -- cgit v1.2.3 From 1adab9d2f5d7863b6df32992ecb21dcea5b51d21 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Wed, 1 May 2019 09:13:13 +0200 Subject: Make tests into their own proper modules without star imports Star imports make it hard to see which imports a module is actually using so I prefer to have this be a bit more explicit. --- tests/auth.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/auth.rs') diff --git a/tests/auth.rs b/tests/auth.rs index 48f070e..f43553b 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,5 +1,14 @@ mod fixtures; -use fixtures::*; + +use assert_cmd::prelude::*; +use assert_fs::fixture::TempDir; +use fixtures::{port, tmpdir, Error, FILES}; +use rstest::rstest_parametrize; +use select::document::Document; +use select::predicate::Text; +use std::process::{Command, Stdio}; +use std::thread::sleep; +use std::time::Duration; #[rstest_parametrize( cli_auth_arg, client_username, client_password, @@ -20,7 +29,7 @@ fn auth_works( port: u16, cli_auth_arg: &str, client_username: &str, - client_password: &str + client_password: &str, ) -> Result<(), Error> { let mut child = Command::cargo_bin("miniserve")? .arg(tmpdir.path()) -- cgit v1.2.3