Update onefuzz-agent unit tests (#592)

This commit is contained in:
Joe Ranweiler 2021-02-24 17:54:36 -08:00 committed by GitHub
parent ed86bb0099
commit a3fa5f6b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 5 deletions

View File

@ -226,7 +226,7 @@ mod tests {
use super::*; use super::*;
use crate::tasks::stats::afl::read_stats; use crate::tasks::stats::afl::read_stats;
use onefuzz::process::monitor_process; use onefuzz::process::monitor_process;
use onefuzz::telemetry::EventData; use onefuzz_telemetry::EventData;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::Instant; use std::time::Instant;

View File

@ -27,6 +27,23 @@ pub enum State<M> {
Processed(M), Processed(M),
} }
impl<M: PartialEq> PartialEq for State<M> {
fn eq(&self, other: &State<M>) -> bool {
use State::*;
match (self, other) {
(Ready, Ready) => true,
(Polled(l), Polled(r)) => l == r,
(Parsed(l0, l1), Parsed(r0, r1)) => l0 == r0 && l1 == r1,
(Downloaded(l0, l1, l2, l3), Downloaded(r0, r1, r2, r3)) => {
l0 == r0 && l1 == r1 && l2 == r2 && l3.path() == r3.path()
}
(Processed(l), Processed(r)) => l == r,
_ => false,
}
}
}
impl<M> fmt::Display for State<M> { impl<M> fmt::Display for State<M> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {

View File

@ -180,7 +180,7 @@ async fn test_parsed_download() {
.unwrap(); .unwrap();
match task.state() { match task.state() {
State::Downloaded(got_msg, got_url, got_path) => { State::Downloaded(got_msg, got_url, got_path, _tmp_dir) => {
assert_eq!(*got_msg, msg); assert_eq!(*got_msg, msg);
assert_eq!(*got_url, url); assert_eq!(*got_url, url);
assert_eq!(got_path.file_name(), input.file_name()); assert_eq!(got_path.file_name(), input.file_name());
@ -194,6 +194,7 @@ async fn test_parsed_download() {
#[tokio::test] #[tokio::test]
async fn test_downloaded_process() { async fn test_downloaded_process() {
let mut task = fixture(); let mut task = fixture();
let tmp_dir = tempfile::tempdir().unwrap();
let dir = Path::new("etc"); let dir = Path::new("etc");
@ -201,7 +202,7 @@ async fn test_downloaded_process() {
let url = url_fixture(msg); let url = url_fixture(msg);
let input = input_fixture(dir, msg); let input = input_fixture(dir, msg);
task.set_state(State::Downloaded(msg, url.clone(), input.clone())); task.set_state(State::Downloaded(msg, url.clone(), input.clone(), tmp_dir));
let mut processor = TestProcessor::default(); let mut processor = TestProcessor::default();

View File

@ -173,6 +173,8 @@ impl SendRetry for reqwest::RequestBuilder {
mod test { mod test {
use super::*; use super::*;
// TODO: convert to feature-gated integration test.
#[ignore]
#[tokio::test] #[tokio::test]
async fn empty_stack() -> Result<()> { async fn empty_stack() -> Result<()> {
let resp = reqwest::Client::new() let resp = reqwest::Client::new()

View File

@ -38,8 +38,11 @@ cargo clippy --release -- -D warnings
# export RUST_LOG=trace # export RUST_LOG=trace
export RUST_BACKTRACE=full export RUST_BACKTRACE=full
cargo test --release --manifest-path ./onefuzz-supervisor/Cargo.toml cargo test --release --manifest-path ./onefuzz-supervisor/Cargo.toml
# TODO: re-enable
# TODO: re-enable integration tests.
# cargo test --release --manifest-path ./onefuzz-agent/Cargo.toml --features integration_test -- --nocapture # cargo test --release --manifest-path ./onefuzz-agent/Cargo.toml --features integration_test -- --nocapture
cargo test --release --manifest-path ./onefuzz-agent/Cargo.toml
cargo test --release --manifest-path ./onefuzz/Cargo.toml cargo test --release --manifest-path ./onefuzz/Cargo.toml
cp target/release/onefuzz-agent* ../../artifacts/agent cp target/release/onefuzz-agent* ../../artifacts/agent