Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions dropshot/tests/integration-tests/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ use serde::Deserialize;
use serde::Serialize;
use serde::de::DeserializeOwned;
use std::collections::BTreeSet;
use std::env::consts::EXE_SUFFIX;
use std::env::current_exe;
use std::fmt::Debug;
use std::net::Ipv4Addr;
use std::net::SocketAddr;
use std::ops::Bound;
use std::path::PathBuf;
use std::sync::LazyLock;
use std::sync::atomic::AtomicU16;
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -783,6 +785,34 @@ impl Drop for ExampleContext {
}
}

/// Returns the path of the named example program.
fn example_path(name: &str) -> PathBuf {
let test_program = current_exe().expect("failed to find test program");

// The test program sits in `deps` or, with Cargo 1.100 and later, in
// `build/<package>/<hash>/out`. The nearest ancestor with an `examples`
// directory is the profile directory.
let examples_dir = test_program
.ancestors()
.skip(1)
.map(|dir| dir.join("examples"))
.find(|dir| dir.is_dir())
.unwrap_or_else(|| {
panic!(
"no examples directory above test program {}",
test_program.display(),
)
});

let path = examples_dir.join(format!("{name}{EXE_SUFFIX}"));
assert!(
path.is_file(),
"example program {} not found; run `cargo build --examples` first",
path.display(),
);
path
}

/// For one of the example programs that starts a Dropshot server on localhost
/// using a TCP port provided as a command-line argument, this function starts
/// the requested example on the requested TCP port and attempts to wait for the
Expand All @@ -799,15 +829,7 @@ async fn start_example(path: &str, port: u16) -> ExampleContext {
);

let log = logctx.log.new(o!());
let cmd_path = {
let mut my_path = current_exe().expect("failed to find test program");
my_path.pop();
assert_eq!(my_path.file_name().unwrap(), "deps");
my_path.pop();
my_path.push("examples");
my_path.push(path);
my_path
};
let cmd_path = example_path(path);

// We redirect stderr to /dev/null to avoid spamming the user's terminal.
// It would be better to put this in some log file that we manage similarly
Expand Down
Loading