Skip to content

Commit

Permalink
Clever hack to get workspace root and avoid evil target turds
Browse files Browse the repository at this point in the history
The target turds were preventing me from replicating the CI test
failures locally.

Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 committed Aug 28, 2024
1 parent bdeddac commit a93b493
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[alias]
xtask = "run --package xtask --"
xtask = "run --package xtask --"

[env]
CARGO_WORKSPACE_ROOT = { value = "", relative = true }
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
/target/
.idea
.DS_Store
/data
Expand Down
5 changes: 4 additions & 1 deletion modules/importer/src/runner/clearly_defined/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ mod test {

#[test_log::test(tokio::test)]
async fn test_walker() {
let path = PathBuf::from("target/test.data/test_clearly_defined_walker.git");
let path = PathBuf::from(format!(
"{}target/test.data/test_clearly_defined_walker.git",
env!("CARGO_WORKSPACE_ROOT")
));

let cont = Continuation::default();

Expand Down
5 changes: 4 additions & 1 deletion modules/importer/src/runner/cve/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ mod test {
#[ignore]
#[test_log::test(tokio::test)]
async fn test_walker() {
let path = PathBuf::from("target/test.data/test_cve_walker.git");
let path = PathBuf::from(format!(
"{}target/test.data/test_cve_walker.git",
env!("CARGO_WORKSPACE_ROOT")
));

let cont = Continuation::default();

Expand Down
10 changes: 8 additions & 2 deletions modules/importer/src/runner/osv/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ mod test {
#[test_log::test(tokio::test)]
async fn test_walker() {
const SOURCE: &str = "https://github.com/RConsortium/r-advisory-database";
let path = PathBuf::from("target/test.data/test_walker.git");
let path = PathBuf::from(format!(
"{}target/test.data/test_walker.git",
env!("CARGO_WORKSPACE_ROOT")
));

let cont = Continuation::default();

Expand All @@ -176,7 +179,10 @@ mod test {
#[test_log::test(tokio::test)]
async fn test_walker_fail_escape() {
const SOURCE: &str = "https://github.com/RConsortium/r-advisory-database";
let path = PathBuf::from("target/test.data/test_walker_fail_escape.git");
let path = PathBuf::from(format!(
"{}target/test.data/test_walker_fail_escape.git",
env!("CARGO_WORKSPACE_ROOT")
));

let cont = Continuation::default();

Expand Down
19 changes: 3 additions & 16 deletions test-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use futures::Stream;
use peak_alloc::PeakAlloc;
use postgresql_embedded::PostgreSQL;
use std::env;
use std::env::current_dir;
use std::io::{ErrorKind, Read, Seek};
use std::io::{Read, Seek};
use std::path::PathBuf;
use test_context::AsyncTestContext;
use tokio::io::AsyncReadExt;
Expand Down Expand Up @@ -119,21 +118,9 @@ impl AsyncTestContext for TrustifyContext {
}
}

fn find_workspace_root() -> Result<PathBuf, anyhow::Error> {
let current_dir = current_dir()?;
let mut i = Some(current_dir.as_path());
while let Some(cur) = i {
if cur.join("rust-toolchain.toml").exists() {
return Ok(cur.to_path_buf());
}
i = cur.parent();
}
Err(std::io::Error::new(ErrorKind::NotFound, "damnit").into())
}

fn absolute(path: &str) -> Result<PathBuf, anyhow::Error> {
let workspace_root = find_workspace_root()?;
let test_data = workspace_root.join("etc").join("test-data");
let workspace_root: PathBuf = env!("CARGO_WORKSPACE_ROOT").into();
let test_data = workspace_root.join("etc/test-data");
Ok(test_data.join(path))
}

Expand Down

0 comments on commit a93b493

Please sign in to comment.