Skip to content

Commit

Permalink
Fix throttling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quambene committed Nov 26, 2024
1 parent df10862 commit 603ebdc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 28 deletions.
21 changes: 14 additions & 7 deletions tests/test_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ async fn test_fetch() {
"--request-throttling",
request_throttling,
]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert!(bookmarks.is_empty());
Expand All @@ -49,7 +50,8 @@ async fn test_fetch() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["-v", "import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert_eq!(bookmarks.len(), 3);
Expand Down Expand Up @@ -144,19 +146,22 @@ async fn test_fetch_diff() {
"--request-throttling",
request_throttling,
]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep import'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep fetch'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["fetch"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

// Change the content for the mock website to simulate a diff.
drop(mock_website_1);
Expand Down Expand Up @@ -215,7 +220,8 @@ async fn test_fetch_empty_cache() {
"--request-throttling",
request_throttling,
]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert!(bookmarks.is_empty());
Expand All @@ -224,7 +230,8 @@ async fn test_fetch_empty_cache() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert_eq!(bookmarks.len(), 3);
Expand Down
69 changes: 54 additions & 15 deletions tests/test_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tempfile::tempdir;

#[tokio::test]
async fn test_search_case_sensitive() {
let request_throttling = "1";
let mock_server = common::start_mock_server().await;
let mocks = common::mount_mocks(&mock_server, 3).await;
let temp_dir = tempdir().unwrap();
Expand All @@ -24,23 +25,35 @@ async fn test_search_case_sensitive() {
writeln!(file, "{}", url).unwrap();
}

println!("Execute 'bogrep config --source {}'", source.display());
println!(
"Execute 'bogrep config --source {} --request-throttling {request_throttling}'",
source_path.display()
);
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["config", "--source", source.to_str().unwrap()]);
cmd.output().unwrap();
cmd.args([
"config",
"--source",
source.to_str().unwrap(),
"--request-throttling",
request_throttling,
]);
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep import'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep fetch'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["fetch"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep \"Test content 1\"'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand All @@ -67,6 +80,7 @@ async fn test_search_case_sensitive() {

#[tokio::test]
async fn test_search_case_insensitive() {
let request_throttling = "1";
let mock_server = common::start_mock_server().await;
let mocks = common::mount_mocks(&mock_server, 3).await;
let temp_dir = tempdir().unwrap();
Expand All @@ -81,23 +95,35 @@ async fn test_search_case_insensitive() {
writeln!(file, "{}", url).unwrap();
}

println!("Execute 'bogrep config --source {}'", source.display());
println!(
"Execute 'bogrep config --source {} --request-throttling {request_throttling}'",
source_path.display()
);
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["config", "--source", source.to_str().unwrap()]);
cmd.output().unwrap();
cmd.args([
"config",
"--source",
source.to_str().unwrap(),
"--request-throttling",
request_throttling,
]);
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep import'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep fetch'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["fetch"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep -i \"test content 1\"'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand All @@ -124,6 +150,7 @@ async fn test_search_case_insensitive() {

#[tokio::test]
async fn test_search_no_content() {
let request_throttling = "1";
let mock_server = common::start_mock_server().await;
let mocks = common::mount_mocks(&mock_server, 3).await;
let temp_dir = tempdir().unwrap();
Expand All @@ -138,23 +165,35 @@ async fn test_search_no_content() {
writeln!(file, "{}", url).unwrap();
}

println!("Execute 'bogrep config --source {}'", source.display());
println!(
"Execute 'bogrep config --source {} --request-throttling {request_throttling}'",
source_path.display()
);
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["config", "--source", source.to_str().unwrap()]);
cmd.output().unwrap();
cmd.args([
"config",
"--source",
source.to_str().unwrap(),
"--request-throttling",
request_throttling,
]);
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep import'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep fetch'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["fetch"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

println!("Execute 'bogrep -l \"Test content 1\"'");
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand Down
26 changes: 20 additions & 6 deletions tests/test_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tempfile::tempdir;

#[tokio::test]
async fn test_sync() {
let request_throttling = "1";
let mock_server = common::start_mock_server().await;
let mocks = common::mount_mocks(&mock_server, 3).await;
let temp_dir = tempdir().unwrap();
Expand All @@ -23,11 +24,21 @@ async fn test_sync() {
writeln!(file, "{}", url).unwrap();
}

println!("Execute 'bogrep config --source {}'", source.display());
println!(
"Execute 'bogrep config --source {} --request-throttling {request_throttling}'",
source_path.display()
);
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["config", "--source", source.to_str().unwrap()]);
cmd.output().unwrap();
cmd.args([
"config",
"--source",
source.to_str().unwrap(),
"--request-throttling",
request_throttling,
]);
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert!(bookmarks.is_empty());
Expand All @@ -36,7 +47,8 @@ async fn test_sync() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["import"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert_eq!(bookmarks.len(), 3);
Expand All @@ -45,7 +57,8 @@ async fn test_sync() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["fetch"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert_eq!(bookmarks.len(), 3);
Expand All @@ -57,7 +70,8 @@ async fn test_sync() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("BOGREP_HOME", temp_path);
cmd.args(["sync"]);
cmd.output().unwrap();
let res = cmd.output();
assert!(res.is_ok(), "Can't execute command: {}", res.unwrap_err());

let bookmarks = common::test_bookmarks(temp_path);
assert_eq!(bookmarks.len(), 3);
Expand Down

0 comments on commit 603ebdc

Please sign in to comment.