Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run clippy on tests as well. #57

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ jobs:
with:
toolchain: stable
- name: Lint
run: cargo clippy -- -D warnings
run: cargo clippy --tests -- -D warnings
- name: Format check
run: cargo fmt --check
- name: Build (debug)
3 changes: 1 addition & 2 deletions src/hash.rs
Original file line number Diff line number Diff line change
@@ -158,7 +158,6 @@ pub fn validate_hash_file(path: &Path, expected: &str) -> Result<(), HashError>
#[cfg(test)]
mod tests {
use super::*;
use tempfile;

#[test]
fn can_deparse_hash_algorithm() {
@@ -274,7 +273,7 @@ mod tests {
#[test]
fn can_validate_hash() {
let expect_md5 = "md5:81dc9bdb52d04dc20036dbd8313ed055";
assert_eq!(validate_hash_data(b"1234", &expect_md5), Ok(()));
assert_eq!(validate_hash_data(b"1234", expect_md5), Ok(()));
assert_eq!(
validate_hash_data(b"12345", expect_md5),
Err(HashError::new(
5 changes: 1 addition & 4 deletions src/location.rs
Original file line number Diff line number Diff line change
@@ -118,10 +118,7 @@ mod tests {
let entry_a = entries_a.first().unwrap();
let loc_b = root.join(".outpack/location/local");
let entries_b = read_location(loc_b.clone()).unwrap();
assert!(entries_b
.iter()
.find(|e| e.packet == entry_a.packet)
.is_none());
assert!(!entries_b.iter().any(|e| e.packet == entry_a.packet));
let now = SystemTime::now();
mark_packet_known(
&entry_a.packet,
12 changes: 6 additions & 6 deletions src/metadata.rs
Original file line number Diff line number Diff line change
@@ -297,15 +297,15 @@ mod tests {
let all_packets = get_metadata_from_date(Path::new("tests/example"), None).unwrap();
assert_eq!(all_packets.len(), 4);
let recent_packets =
get_metadata_from_date(Path::new("tests/example"), Some(1662480556 as f64)).unwrap();
get_metadata_from_date(Path::new("tests/example"), Some(1662480556.)).unwrap();
assert_eq!(recent_packets.len(), 1);
assert_eq!(
recent_packets.first().unwrap().id,
"20170818-164847-7574883b"
);

let recent_packets =
get_metadata_from_date(Path::new("tests/example"), Some(1662480555 as f64)).unwrap();
get_metadata_from_date(Path::new("tests/example"), Some(1662480555.)).unwrap();
assert_eq!(recent_packets.len(), 4);
}

@@ -370,7 +370,7 @@ mod tests {
fn can_get_missing_ids() {
let ids = get_missing_ids(
Path::new("tests/example"),
&vec![
&[
"20180818-164043-7cdcde4b".to_string(),
"20170818-164830-33e0ab02".to_string(),
],
@@ -383,7 +383,7 @@ mod tests {
// check whitespace insensitivity
let ids = get_missing_ids(
Path::new("tests/example"),
&vec![
&[
"20180818-164043-7cdcde4b".to_string(),
"20170818-164830-33e0ab02".to_string(),
],
@@ -398,7 +398,7 @@ mod tests {
fn can_get_missing_unpacked_ids() {
let ids = get_missing_ids(
Path::new("tests/example"),
&vec![
&[
"20170818-164847-7574883b".to_string(),
"20170818-164830-33e0ab02".to_string(),
],
@@ -413,7 +413,7 @@ mod tests {
fn bad_ids_raise_error() {
let res = get_missing_ids(
Path::new("tests/example"),
&vec![
&[
"20180818-164043-7cdcde4b".to_string(),
"20170818-164830-33e0ab0".to_string(),
],
2 changes: 1 addition & 1 deletion src/metrics.rs
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ mod tests {
#[test]
fn repository_collector_empty_repo() {
let root = get_empty_outpack_root();
let collector = RepositoryCollector::new(&root);
let collector = RepositoryCollector::new(root);

assert_eq!(collector.metadata_total.get(), 0);
assert_eq!(collector.packets_total.get(), 0);
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ mod tests {

#[test]
fn can_detect_packet_id() {
assert_eq!(is_packet(&OsString::from("1234")), false);
assert_eq!(is_packet(&OsString::from("20170818-164830-33e0ab01")), true);
assert_eq!(is_packet(&OsString::from("20180818-164847-54699abf")), true)
assert!(!is_packet(&OsString::from("1234")));
assert!(is_packet(&OsString::from("20170818-164830-33e0ab01")));
assert!(is_packet(&OsString::from("20180818-164847-54699abf")))
}

#[test]
19 changes: 8 additions & 11 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use serde_json::Value;
use sha2::{Digest, Sha256};
use std::fs;
use std::fs::File;
use std::io::Read;

use std::path::{Path, PathBuf};
use std::sync::Arc;
use tar::Archive;
@@ -297,13 +297,10 @@ fn can_get_file() {

let path = Path::new("tests/example/.outpack/files/sha256/b1/")
.join("89579a9326f585d308304bd9e03326be5d395ac71b31df359ab8bac408d248");
let mut file = fs::File::open(&path).unwrap();
let metadata = fs::metadata(&path).unwrap();
let mut buffer = vec![0; metadata.len() as usize];

file.read(&mut buffer).unwrap();
let expected = fs::read(path).unwrap();

assert_eq!(response.into_bytes().unwrap(), buffer);
assert_eq!(response.into_bytes().unwrap(), expected);
}

#[test]
@@ -514,7 +511,7 @@ fn file_post_handles_errors() {
let client = Client::tracked(rocket).expect("valid rocket instance");
let content = "test";
let response = client
.post(format!("/file/md5:bad4a54"))
.post("/file/md5:bad4a54".to_string())
.body(content)
.header(ContentType::Binary)
.dispatch();
@@ -633,7 +630,7 @@ fn validate_error(instance: &Value, message: Option<&str>) {
.expect("Status property present")
.as_array()
.unwrap()
.get(0)
.first()
.expect("First error")
.get("detail")
.expect("Error detail")
@@ -644,14 +641,14 @@ fn validate_error(instance: &Value, message: Option<&str>) {
}

fn assert_valid(instance: &Value, compiled: &JSONSchema) {
let result = compiled.validate(&instance);
let result = compiled.validate(instance);
if let Err(errors) = result {
for error in errors {
println!("Validation error: {}", error);
println!("Instance path: {}", error.instance_path);
}
}
assert!(compiled.is_valid(&instance));
assert!(compiled.is_valid(instance));
}

fn get_schema(schema_group: &str, schema_name: &str) -> JSONSchema {
@@ -685,6 +682,6 @@ impl jsonschema::SchemaResolver for LocalSchemaResolver {
.join(original_reference);
let schema_as_string = fs::read_to_string(schema_path).expect("Schema file");
let json_schema = serde_json::from_str(&schema_as_string).expect("Schema is valid json");
return Ok(Arc::new(json_schema));
Ok(Arc::new(json_schema))
}
}