Compare commits

..

No commits in common. "910d95230ffef920145fa2a2366c63b0e248f74b" and "47ad51f860abe07c7a743ce4d3f03f9e2ca93bd2" have entirely different histories.

4 changed files with 18 additions and 79 deletions

View file

@ -18,7 +18,7 @@
"ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall:0": {
"packages": "cargo-llvm-cov"
},
"ghcr.io/devcontainers-extra/features/apt-get-packages:1": {
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1": {
"packages": "git-flow, musl-tools"
}
},

View file

@ -112,7 +112,7 @@ mod tests {
}
#[test]
#[should_panic = "did not fit into \"u32\""]
#[should_panic(expected = "did not fit into \"u32\"")]
fn test_usize_overflow_panics() {
// works
assert_eq!(from_usize_or_panic::<u64>(usize::MAX), u64::MAX);

View file

@ -66,7 +66,7 @@ impl Uploading {
Some(self)
} else {
warn!("attempted to rewind with no `previous_offset`");
warn!("attempted to rewind twice");
None
}
}
@ -142,10 +142,7 @@ mod tests {
use crate::{
sharry::{Client, json::NewShareRequest},
test_util::{
MockClient, create_file,
data::{DATA_LENGTHS_BAD, cases, cases_with},
},
test_util::{MockClient, create_file, data::cases},
};
use super::*;
@ -172,7 +169,7 @@ mod tests {
#[test]
fn basic_tests() {
fn check_members(upl: &Uploading, path: &PathBuf, size: u64) {
assert_eq!(upl.path, *path);
assert_eq!(&upl.path, path);
assert_eq!(upl.size, size);
assert_eq!(upl.offset, 0);
assert!(upl.previous_offset.is_none());
@ -197,75 +194,23 @@ mod tests {
unsafe { Uploading::new_unchecked(upl.path, upl.size, upl.hash, upl.file_id) };
check_members(&upl, &path, size);
// TODO into separate test
// // `check_eof`
// let upl = if size == 0 {
// upl
// } else {
// let eof = upl.check_eof();
// assert!(eof.is_ok());
// let upl = eof.unwrap();
// check_members(&upl, &path, size);
// upl
// };
// `stop`
let chk = upl.stop();
assert_eq!(chk.get_name(), path.file_name().unwrap().to_str().unwrap());
assert_eq!(chk.get_size(), size);
}
}
#[test]
fn check_eof_works() {
for (content, size) in cases() {
let (upl, _share_id, file) = create_uploading(content);
let path = file.path().canonicalize().unwrap();
let eof = upl.check_eof();
if size > 0 {
assert!(eof.is_ok());
} else {
assert!(eof.is_err());
assert_eq!(eof.unwrap_err(), path);
};
}
}
#[test]
fn check_read_works() {
for (content, size, extra) in cases_with(DATA_LENGTHS_BAD) {
let (mut upl, _share_id, _file) = create_uploading(content);
// use oversized buffer
let mut buf = vec![0; (size + extra) as usize];
let chunk_res = upl.read(&mut buf);
if size > 0 {
assert_eq!(upl.previous_offset, Some(0));
assert_eq!(upl.offset, size);
let chunk = chunk_res.unwrap();
assert_eq!(chunk.get_offset(), 0);
assert_eq!(chunk.get_length(), size);
assert_eq!(chunk.get_file_id().to_string(), upl.file_id.to_string());
assert_eq!(chunk.get_data(), content);
} else {
assert!(chunk_res.is_err());
};
}
}
#[test]
fn check_rewind_works() {
let cases = cases()
// ignore "empty" testcase
.filter(|&(_, size)| size > 0)
// remove "size"
.map(|(content, _)| content);
for content in cases {
let (mut upl, _share_id, _file) = create_uploading(content);
// read 1 byte and rewind
upl.read(&mut [0]).unwrap();
upl = upl.rewind().unwrap();
// check: read has been rewound
assert_eq!(upl.offset, 0);
assert_eq!(upl.previous_offset, None);
// check: attempting to rewind again will destroy
assert!(upl.rewind().is_none());
}
}
}

View file

@ -28,9 +28,3 @@ pub fn create_file(data: &[u8]) -> NamedTempFile {
tmp.write_all(data).unwrap();
tmp
}
#[test]
#[should_panic = "`impl foo for bar` expected: 1, actual: 0"]
fn make_check_trait_panic() {
check_trait(0, 1, "foo", "bar");
}