refactor(tvix/store/blobsvc): move from Vec<u8> to B3Digest
Change-Id: I809bab75221f81b6023cfe75c2fe9e589c1e9192 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8605 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
b8ff08b1b0
commit
066179651c
9 changed files with 79 additions and 95 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use crate::proto::{self, Directory, DirectoryNode, FileNode, SymlinkNode};
|
||||
use crate::{
|
||||
proto::{self, Directory, DirectoryNode, FileNode, SymlinkNode},
|
||||
B3Digest,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub const HELLOWORLD_BLOB_CONTENTS: &[u8] = b"Hello World!";
|
||||
|
|
@ -12,18 +15,19 @@ lazy_static! {
|
|||
];
|
||||
pub static ref DUMMY_DATA_1: Vec<u8> = vec![0x01, 0x02, 0x03];
|
||||
pub static ref DUMMY_DATA_2: Vec<u8> = vec![0x04, 0x05];
|
||||
pub static ref HELLOWORLD_BLOB_DIGEST: Vec<u8> =
|
||||
blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().to_vec();
|
||||
pub static ref EMPTY_BLOB_DIGEST: Vec<u8> =
|
||||
blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().to_vec();
|
||||
|
||||
pub static ref HELLOWORLD_BLOB_DIGEST: B3Digest =
|
||||
blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().into();
|
||||
pub static ref EMPTY_BLOB_DIGEST: B3Digest =
|
||||
blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().into();
|
||||
|
||||
// 2 bytes
|
||||
pub static ref BLOB_A: Vec<u8> = vec![0x00, 0x01];
|
||||
pub static ref BLOB_A_DIGEST: Vec<u8> = blake3::hash(&BLOB_A).as_bytes().to_vec();
|
||||
pub static ref BLOB_A_DIGEST: B3Digest = blake3::hash(&BLOB_A).as_bytes().into();
|
||||
|
||||
// 1MB
|
||||
pub static ref BLOB_B: Vec<u8> = (0..255).collect::<Vec<u8>>().repeat(4 * 1024);
|
||||
pub static ref BLOB_B_DIGEST: Vec<u8> = blake3::hash(&BLOB_B).as_bytes().to_vec();
|
||||
pub static ref BLOB_B_DIGEST: B3Digest = blake3::hash(&BLOB_B).as_bytes().into();
|
||||
|
||||
// Directories
|
||||
pub static ref DIRECTORY_WITH_KEEP: proto::Directory = proto::Directory {
|
||||
|
|
|
|||
|
|
@ -61,9 +61,7 @@ fn single_file() {
|
|||
);
|
||||
|
||||
// ensure the blob has been uploaded
|
||||
assert!(blob_service
|
||||
.has(&HELLOWORLD_BLOB_DIGEST.to_vec().try_into().unwrap())
|
||||
.unwrap());
|
||||
assert!(blob_service.has(&HELLOWORLD_BLOB_DIGEST).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -111,7 +109,5 @@ fn complicated() {
|
|||
.is_some());
|
||||
|
||||
// ensure EMPTY_BLOB_CONTENTS has been uploaded
|
||||
assert!(blob_service
|
||||
.has(&EMPTY_BLOB_DIGEST.to_vec().try_into().unwrap())
|
||||
.unwrap());
|
||||
assert!(blob_service.has(&EMPTY_BLOB_DIGEST).unwrap());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ fn single_file_wrong_blob_size() {
|
|||
&mut writer,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(HELLOWORLD_BLOB_DIGEST.to_vec(), writer.close().unwrap());
|
||||
assert_eq!(HELLOWORLD_BLOB_DIGEST.clone(), writer.close().unwrap());
|
||||
|
||||
let renderer = NARRenderer::new(blob_service, gen_directory_service());
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ fn single_file() {
|
|||
&mut writer,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(HELLOWORLD_BLOB_DIGEST.to_vec(), writer.close().unwrap());
|
||||
assert_eq!(HELLOWORLD_BLOB_DIGEST.clone(), writer.close().unwrap());
|
||||
|
||||
let renderer = NARRenderer::new(blob_service, gen_directory_service());
|
||||
let mut buf: Vec<u8> = vec![];
|
||||
|
|
@ -164,7 +164,7 @@ fn test_complicated() {
|
|||
&mut writer,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(EMPTY_BLOB_DIGEST.to_vec(), writer.close().unwrap());
|
||||
assert_eq!(EMPTY_BLOB_DIGEST.clone(), writer.close().unwrap());
|
||||
|
||||
directory_service.put(DIRECTORY_WITH_KEEP.clone()).unwrap();
|
||||
directory_service
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue