summaryrefslogtreecommitdiff
path: root/src/chunkmeta.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-04-09 11:27:14 +0300
committerLars Wirzenius <liw@liw.fi>2022-04-16 09:04:28 +0300
commitd9b72ffa5485f3c253da22f09ff0a7090de7aa37 (patch)
treeffcfc0d0b2377c95072b609095589fbf83424382 /src/chunkmeta.rs
parent9f6ff22ff9a1b0a5a28d037846b1cecee4f2945c (diff)
downloadobnam2-d9b72ffa5485f3c253da22f09ff0a7090de7aa37.tar.gz
refactor: rename Checksum to Label
Label is a clearer and more accurate name for the type now that it is not just a checksum. Also, serialize a Label in tests, rather than using string literals. This is more correct, and we'll be changing serialization later. Sponsored-by: author
Diffstat (limited to 'src/chunkmeta.rs')
-rw-r--r--src/chunkmeta.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/chunkmeta.rs b/src/chunkmeta.rs
index 33c1070..1f591c6 100644
--- a/src/chunkmeta.rs
+++ b/src/chunkmeta.rs
@@ -1,6 +1,6 @@
//! Metadata about a chunk.
-use crate::checksummer::Checksum;
+use crate::label::Label;
use serde::{Deserialize, Serialize};
use std::default::Default;
use std::str::FromStr;
@@ -37,9 +37,9 @@ impl ChunkMeta {
/// Create a new data chunk.
///
/// Data chunks are not for generations.
- pub fn new(checksum: &Checksum) -> Self {
+ pub fn new(label: &Label) -> Self {
ChunkMeta {
- label: checksum.to_string(),
+ label: label.to_string(),
}
}
@@ -79,20 +79,20 @@ impl FromStr for ChunkMeta {
#[cfg(test)]
mod test {
- use super::{Checksum, ChunkMeta};
+ use super::{ChunkMeta, Label};
#[test]
fn new_creates_data_chunk() {
- let sum = Checksum::sha256_from_str_unchecked("abcdef");
+ let sum = Label::sha256(b"abcdef");
let meta = ChunkMeta::new(&sum);
- assert_eq!(meta.label(), "abcdef");
+ assert_eq!(meta.label(), &format!("{}", sum));
}
#[test]
fn new_generation_creates_generation_chunk() {
- let sum = Checksum::sha256_from_str_unchecked("abcdef");
+ let sum = Label::sha256(b"abcdef");
let meta = ChunkMeta::new(&sum);
- assert_eq!(meta.label(), "abcdef");
+ assert_eq!(meta.label(), &format!("{}", sum));
}
#[test]
@@ -113,7 +113,7 @@ mod test {
#[test]
fn generation_json_roundtrip() {
- let sum = Checksum::sha256_from_str_unchecked("abcdef");
+ let sum = Label::sha256(b"abcdef");
let meta = ChunkMeta::new(&sum);
let json = serde_json::to_string(&meta).unwrap();
let meta2 = serde_json::from_str(&json).unwrap();
@@ -122,7 +122,7 @@ mod test {
#[test]
fn data_json_roundtrip() {
- let sum = Checksum::sha256_from_str_unchecked("abcdef");
+ let sum = Label::sha256(b"abcdef");
let meta = ChunkMeta::new(&sum);
let json = meta.to_json_vec();
let meta2 = serde_json::from_slice(&json).unwrap();