summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/src/database_models.rs4
-rw-r--r--rust/src/entity_crud.rs18
-rw-r--r--rust/tests/test_refs.rs80
3 files changed, 58 insertions, 44 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index b76b469a..ce804c50 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -4,7 +4,9 @@ use crate::database_schema::*;
use crate::errors::*;
use crate::identifiers::uuid2fcid;
use chrono;
-use fatcat_api_spec::models::{ChangelogEntry, Editgroup, EditgroupAnnotation, Editor, EntityEdit, ReleaseRef};
+use fatcat_api_spec::models::{
+ ChangelogEntry, Editgroup, EditgroupAnnotation, Editor, EntityEdit, ReleaseRef,
+};
use serde_json;
use uuid::Uuid;
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index 09ce9542..a7186f38 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -1829,7 +1829,8 @@ impl EntityCrud for ReleaseEntity {
refs[index].index = Some(index as i64)
}
for row in ref_rows {
- refs[row.index_val as usize].target_release_id = Some(FatcatId::from_uuid(&row.target_release_ident_id).to_string());
+ refs[row.index_val as usize].target_release_id =
+ Some(FatcatId::from_uuid(&row.target_release_ident_id).to_string());
}
refs
}),
@@ -1960,11 +1961,11 @@ impl EntityCrud for ReleaseEntity {
match &model.refs {
None => {
refs_blob_sha1.push(None);
- },
+ }
Some(ref_list) => {
if ref_list.is_empty() {
refs_blob_sha1.push(None);
- continue
+ continue;
}
// Have to strip out target refs and indexes, or hashing won't work well when
// these change
@@ -1981,7 +1982,10 @@ impl EntityCrud for ReleaseEntity {
let refs_json = serde_json::to_value(ref_list)?;
let refs_str = refs_json.to_string();
let sha1 = Sha1::from(refs_str).hexdigest();
- let blob = RefsBlobRow { sha1: sha1.clone(), refs_json };
+ let blob = RefsBlobRow {
+ sha1: sha1.clone(),
+ refs_json,
+ };
refs_blob_rows.push(blob);
refs_blob_sha1.push(Some(sha1));
}
@@ -2044,7 +2048,6 @@ impl EntityCrud for ReleaseEntity {
let mut release_abstract_rows: Vec<ReleaseRevAbstractNewRow> = vec![];
for (model, rev_id) in models.iter().zip(rev_ids.iter()) {
-
// We didn't know the release_rev id to insert here, so need to re-iterate over refs
match &model.refs {
None => (),
@@ -2057,7 +2060,10 @@ impl EntityCrud for ReleaseEntity {
Ok(ReleaseRefRow {
release_rev: *rev_id,
// unwrap() checked by is_some() filter
- target_release_ident_id: FatcatId::from_str(&r.target_release_id.clone().unwrap())?.to_uuid(),
+ target_release_ident_id: FatcatId::from_str(
+ &r.target_release_id.clone().unwrap(),
+ )?
+ .to_uuid(),
index_val: index as i32,
})
})
diff --git a/rust/tests/test_refs.rs b/rust/tests/test_refs.rs
index a2bf37ba..262f1d85 100644
--- a/rust/tests/test_refs.rs
+++ b/rust/tests/test_refs.rs
@@ -1,13 +1,12 @@
-
-use fatcat::identifiers::FatcatId;
-use fatcat::server;
-use std::str::FromStr;
+use diesel::prelude::*;
use fatcat::database_models::*;
use fatcat::database_schema::*;
+use fatcat::editing::{accept_editgroup, make_edit_context};
use fatcat::entity_crud::{EntityCrud, HideFlags};
-use fatcat::editing::{make_edit_context, accept_editgroup};
+use fatcat::identifiers::FatcatId;
+use fatcat::server;
use fatcat_api_spec::models::*;
-use diesel::prelude::*;
+use std::str::FromStr;
use uuid::Uuid;
mod helpers;
@@ -18,9 +17,9 @@ fn test_refs_blob() {
let conn = server.db_pool.get().expect("db_pool error");
let editor_id = FatcatId::from_str(helpers::TEST_ADMIN_EDITOR_ID).unwrap();
let editgroup_id = helpers::quick_editgroup(&conn);
- let edit_context = make_edit_context(&conn, editor_id, Some(editgroup_id), false).unwrap();
+ let edit_context = make_edit_context(&conn, editor_id, Some(editgroup_id), false).unwrap();
- // this release entity should be unchanged after being inserted/fetched
+ // this release entity should be unchanged after being inserted/fetched
let mut r1 = ReleaseEntity::new();
r1.title = Some("release-test hashes".to_string());
r1.refs = Some(vec![
@@ -33,7 +32,7 @@ fn test_refs_blob() {
container_name: Some("bogus container".to_string()),
title: Some("first bogus paper".to_string()),
locator: Some("p100".to_string()),
- },
+ },
ReleaseRef {
index: Some(1),
target_release_id: Some("aaaaaaaaaaaaarceaaaaaaaaai".to_string()),
@@ -43,7 +42,7 @@ fn test_refs_blob() {
container_name: Some("bogus other container".to_string()),
title: Some("second bogus paper".to_string()),
locator: Some("p200".to_string()),
- },
+ },
]);
// this release entity should have the same hash as r1. the indexes will change after fetching,
@@ -59,7 +58,7 @@ fn test_refs_blob() {
container_name: Some("bogus container".to_string()),
title: Some("first bogus paper".to_string()),
locator: Some("p100".to_string()),
- },
+ },
ReleaseRef {
index: Some(99),
target_release_id: Some("aaaaaaaaaaaaarceaaaaaaaaai".to_string()),
@@ -69,7 +68,7 @@ fn test_refs_blob() {
container_name: Some("bogus other container".to_string()),
title: Some("second bogus paper".to_string()),
locator: Some("p200".to_string()),
- },
+ },
]);
// this release entity has different ref *targets* and indexes, but should still have the same
@@ -85,7 +84,7 @@ fn test_refs_blob() {
container_name: Some("bogus container".to_string()),
title: Some("first bogus paper".to_string()),
locator: Some("p100".to_string()),
- },
+ },
ReleaseRef {
index: Some(1),
target_release_id: Some("aaaaaaaaaaaaarceaaaaaaaaam".to_string()),
@@ -95,23 +94,21 @@ fn test_refs_blob() {
container_name: Some("bogus other container".to_string()),
title: Some("second bogus paper".to_string()),
locator: Some("p200".to_string()),
- },
+ },
]);
// this one is obviously just plain different (hashes shouldn't match)
let mut r4 = r1.clone();
- r4.refs = Some(vec![
- ReleaseRef {
- index: Some(1),
- target_release_id: Some("aaaaaaaaaaaaarceaaaaaaaaae".to_string()),
- extra: None,
- key: Some("one".to_string()),
- year: Some(1932),
- container_name: Some("bogus container".to_string()),
- title: Some("first bogus paper".to_string()),
- locator: Some("p100".to_string()),
- },
- ]);
+ r4.refs = Some(vec![ReleaseRef {
+ index: Some(1),
+ target_release_id: Some("aaaaaaaaaaaaarceaaaaaaaaae".to_string()),
+ extra: None,
+ key: Some("one".to_string()),
+ year: Some(1932),
+ container_name: Some("bogus container".to_string()),
+ title: Some("first bogus paper".to_string()),
+ locator: Some("p100".to_string()),
+ }]);
let edit1 = r1.db_create(&conn, &edit_context).unwrap();
let edit2 = r2.db_create(&conn, &edit_context).unwrap();
@@ -129,33 +126,42 @@ fn test_refs_blob() {
let r1_row: ReleaseRevRow = release_rev::table
.find(Uuid::from_str(&r1b.revision.clone().unwrap()).unwrap())
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
let r2_row: ReleaseRevRow = release_rev::table
.find(Uuid::from_str(&r2b.revision.unwrap()).unwrap())
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
let r3_row: ReleaseRevRow = release_rev::table
.find(Uuid::from_str(&r3b.revision.clone().unwrap()).unwrap())
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
let r4_row: ReleaseRevRow = release_rev::table
.find(Uuid::from_str(&r4b.revision.unwrap()).unwrap())
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(r1_row.refs_blob_sha1, r2_row.refs_blob_sha1);
assert_eq!(r1_row.refs_blob_sha1, r3_row.refs_blob_sha1);
assert_ne!(r1_row.refs_blob_sha1, r4_row.refs_blob_sha1);
// ensure that SHA1 hashing is stable over time (as much as possible!)
- assert_eq!(r1_row.refs_blob_sha1, Some("4e38812fbf99e00e0cb648896e9f7a9d58c5ab23".to_string()));
+ assert_eq!(
+ r1_row.refs_blob_sha1,
+ Some("4e38812fbf99e00e0cb648896e9f7a9d58c5ab23".to_string())
+ );
- // update r1 with new target_idents (r3); SHA1 row still shouldn't change
+ // update r1 with new target_idents (r3); SHA1 row still shouldn't change
accept_editgroup(&conn, editgroup_id).unwrap();
let editgroup_id = helpers::quick_editgroup(&conn);
- let edit_context = make_edit_context(&conn, editor_id, Some(editgroup_id), false).unwrap();
+ let edit_context = make_edit_context(&conn, editor_id, Some(editgroup_id), false).unwrap();
- let _edit4 = r3b.db_update(&conn, &edit_context, edit1.ident_id.into()).unwrap();
+ let _edit4 = r3b
+ .db_update(&conn, &edit_context, edit1.ident_id.into())
+ .unwrap();
let r1c = ReleaseEntity::db_get(&conn, edit1.ident_id.into(), HideFlags::none()).unwrap();
let r1c_row: ReleaseRevRow = release_rev::table
.find(Uuid::from_str(&r1c.revision.unwrap()).unwrap())
- .get_result(&conn).unwrap();
- assert_eq!(r1_row.refs_blob_sha1, r1c_row.refs_blob_sha1);
+ .get_result(&conn)
+ .unwrap();
+ assert_eq!(r1_row.refs_blob_sha1, r1c_row.refs_blob_sha1);
}
-