Skip to content

Commit

Permalink
Extract helper for asserting on snapshot contents
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Nov 28, 2017
1 parent 885eae3 commit 4af866b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/rust/engine/fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ mod tests {
use tempdir::TempDir;
use self::testutil::make_file;

use super::super::{Digest, File, Fingerprint, GetFileDigest, PathGlobs, PathStat, PosixFS,
ResettablePool, Snapshot, Store, VFS};
use super::super::{Digest, File, FileContent, Fingerprint, GetFileDigest, PathGlobs, PathStat,
PosixFS, ResettablePool, Snapshot, Store, VFS};

use std;
use std::error::Error;
Expand Down Expand Up @@ -366,10 +366,7 @@ mod tests {
.contents(store)
.wait()
.unwrap();
// TODO: Write helper for asserting equality of FileContents (and Vecs thereof).
assert_eq!(contents.len(), 1);
assert_eq!(contents.get(0).unwrap().path, file_name);
assert_eq!(contents.get(0).unwrap().content, STR.as_bytes().to_vec());
assert_snapshot_contents(contents, vec![(file_name, STR)]);
}

#[test]
Expand Down Expand Up @@ -403,17 +400,10 @@ mod tests {
.contents(store)
.wait()
.unwrap();
// TODO: Write helper for asserting equality of FileContents (and Vecs thereof).
assert_eq!(contents.len(), 3);
assert_eq!(contents.get(0).unwrap().path, amy);
assert_eq!(contents.get(0).unwrap().content, LATIN.as_bytes().to_vec());
assert_eq!(contents.get(1).unwrap().path, rolex);
assert_eq!(
contents.get(1).unwrap().content,
AGGRESSIVE.as_bytes().to_vec()
assert_snapshot_contents(
contents,
vec![(amy, LATIN), (rolex, AGGRESSIVE), (roland, STR)],
);
assert_eq!(contents.get(2).unwrap().path, roland);
assert_eq!(contents.get(2).unwrap().content, STR.as_bytes().to_vec());
}

#[derive(Clone)]
Expand Down Expand Up @@ -443,4 +433,16 @@ mod tests {
v.sort_by(|a, b| a.path().cmp(b.path()));
v
}

fn assert_snapshot_contents(contents: Vec<FileContent>, expected: Vec<(PathBuf, &str)>) {
let expected_with_array: Vec<_> = expected
.into_iter()
.map(|(path, s)| (path, s.as_bytes().to_vec()))
.collect();
let got: Vec<_> = contents
.into_iter()
.map(|file_content| (file_content.path, file_content.content))
.collect();
assert_eq!(expected_with_array, got);
}
}

0 comments on commit 4af866b

Please sign in to comment.