Skip to content

Commit

Permalink
tests: Rewrite as Abscissa acceptance tests
Browse files Browse the repository at this point in the history
The tests were previously written using a smorgasbord of little tiny
test helper crates which didn't necessarily work together very well.

This rewrites them using Abscissa's built-in acceptance testing support.
It should hopefully cover everything which was previously being tested.
  • Loading branch information
tarcieri committed Aug 10, 2019
1 parent 4980e1c commit 00b3c6a
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 274 deletions.
110 changes: 8 additions & 102 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ rustsec = "0.12"
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1"

[dev-dependencies]
tempfile = "3"

[dev-dependencies.abscissa_core]
version = "0.3"
features = ["testing"]

[dev-dependencies]
assert_cmd = "0.11"
serial_test = "0.2"
serial_test_derive = "0.2"
tempfile = "3.0.8"
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ environment:
matrix:
- channel: stable
target: x86_64-pc-windows-msvc
- channel: stable
target: i686-pc-windows-msvc

install:
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
Expand Down
50 changes: 34 additions & 16 deletions src/commands/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ pub struct AuditCommand {
#[options(short = "u", long = "url", help = "URL for advisory database git repo")]
url: Option<String>,

/// Quiet mode - avoids printing extraneous information
#[options(
short = "q",
long = "quiet",
help = "Avoid printing unnecessary information"
)]
quiet: bool,

/// Output reports as JSON
#[options(no_short, long = "json", help = "Output report in JSON format")]
output_json: bool,
Expand Down Expand Up @@ -97,6 +105,8 @@ impl Override<CargoAuditConfig> for AuditCommand {

impl Runnable for AuditCommand {
fn run(&self) {
let quiet = self.quiet || self.output_json;

let lockfile_path = self
.file
.as_ref()
Expand All @@ -114,14 +124,16 @@ impl Runnable for AuditCommand {
}
});

let advisory_db = self.load_advisory_db();
let advisory_db = self.load_advisory_db(quiet);

status_ok!(
"Scanning",
"{} for vulnerabilities ({} crate dependencies)",
lockfile_path.display(),
lockfile.packages.len(),
);
if !quiet {
status_ok!(
"Scanning",
"{} for vulnerabilities ({} crate dependencies)",
lockfile_path.display(),
lockfile.packages.len(),
);
}

let all_matching_vulnerabilities = Vulnerabilities::find(&advisory_db, &lockfile);

Expand All @@ -132,7 +144,9 @@ impl Runnable for AuditCommand {
.collect::<Vec<_>>();

if vulnerabilities.is_empty() {
status_ok!("Success", "No vulnerable packages found");
if !quiet {
status_ok!("Success", "No vulnerable packages found");
}
} else {
status_err!("Vulnerable crates found!");
}
Expand Down Expand Up @@ -170,7 +184,7 @@ impl Runnable for AuditCommand {

impl AuditCommand {
/// Load the advisory database
fn load_advisory_db(&self) -> AdvisoryDatabase {
fn load_advisory_db(&self, quiet: bool) -> AdvisoryDatabase {
let advisory_repo_url = self
.url
.as_ref()
Expand All @@ -183,7 +197,9 @@ impl AuditCommand {
.map(PathBuf::from)
.unwrap_or_else(Repository::default_path);

status_ok!("Fetching", "advisory database from `{}`", advisory_repo_url);
if !quiet {
status_ok!("Fetching", "advisory database from `{}`", advisory_repo_url);
}

let advisory_db_repo =
Repository::fetch(advisory_repo_url, &advisory_repo_path, !self.stale).unwrap_or_else(
Expand All @@ -199,12 +215,14 @@ impl AuditCommand {
exit(1);
});

status_ok!(
"Loaded",
"{} security advisories (from {})",
advisory_db.advisories().count(),
advisory_repo_path.display()
);
if !quiet {
status_ok!(
"Loaded",
"{} security advisories (from {})",
advisory_db.advisories().count(),
advisory_repo_path.display()
);
}

advisory_db
}
Expand Down
Loading

0 comments on commit 00b3c6a

Please sign in to comment.