1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
use swhid::snapshot::*;
fn name(s: &'static str) -> Box<[u8]> {
s.as_bytes().into()
}
#[test]
fn simple_snp_hash() {
let snp = Snapshot::new(vec![
Branch::new(
name("refs/heads/develop"),
BranchTarget::Revision(Some([2; 20])),
),
Branch::new(
name("refs/heads/main"),
BranchTarget::Revision(Some([1; 20])),
),
])
.unwrap();
// Checked against the implementation in https://archive.softwareheritage.org/swh:1:dir:60e683f48069373ee85227f2d7ab2eb1a8873ddb;origin=https://gitlab.softwareheritage.org/swh/devel/swh-model.git;visit=swh:1:snp:291aefbdccd43abac57629431201c2fd55284df7;anchor=swh:1:rev:9e54500902fc00ab1e6400431e2803b9bb41cc0a
assert_eq!(
snp_manifest(snp.branches().into()).unwrap(),
b"\
revision refs/heads/develop\020:\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\
revision refs/heads/main\020:\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
"
);
// ditto
assert_eq!(
snp.swhid().to_string(),
"swh:1:snp:870148a17e00ea8bd84b727cd26104b8c6ac6a72"
);
}
#[test]
fn snp_order() {
let snp = Snapshot::new(vec![
Branch::new(
name("refs/heads/main"),
BranchTarget::Revision(Some([1; 20])),
),
Branch::new(
name("refs/heads/develop"),
BranchTarget::Revision(Some([2; 20])),
),
])
.unwrap();
// Checked against the implementation in https://archive.softwareheritage.org/swh:1:dir:60e683f48069373ee85227f2d7ab2eb1a8873ddb;origin=https://gitlab.softwareheritage.org/swh/devel/swh-model.git;visit=swh:1:snp:291aefbdccd43abac57629431201c2fd55284df7;anchor=swh:1:rev:9e54500902fc00ab1e6400431e2803b9bb41cc0a
assert_eq!(
snp_manifest(snp.branches().into()).unwrap(),
b"\
revision refs/heads/develop\020:\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\
revision refs/heads/main\020:\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
"
);
// ditto
assert_eq!(
snp.swhid().to_string(),
"swh:1:snp:870148a17e00ea8bd84b727cd26104b8c6ac6a72"
);
}
#[test]
fn empty_snp_hash() {
let snp = Snapshot::new(vec![]).unwrap();
assert_eq!(snp_manifest(snp.branches().into()).unwrap(), b"");
// Checked against the implementation in https://archive.softwareheritage.org/swh:1:dir:60e683f48069373ee85227f2d7ab2eb1a8873ddb;origin=https://gitlab.softwareheritage.org/swh/devel/swh-model.git;visit=swh:1:snp:291aefbdccd43abac57629431201c2fd55284df7;anchor=swh:1:rev:9e54500902fc00ab1e6400431e2803b9bb41cc0a
assert_eq!(
snp.swhid().to_string(),
"swh:1:snp:1a8893e6a86f444e8be8e7bda6cb34fb1735a00e"
);
}
#[test]
fn snp_with_alias() {
let snp = Snapshot::new(vec![
Branch::new(
name("refs/heads/main"),
BranchTarget::Revision(Some([1; 20])),
),
Branch::new(
name("refs/heads/develop"),
BranchTarget::Revision(Some([2; 20])),
),
Branch::new(
name("HEAD"),
BranchTarget::Alias(Some(name("refs/heads/main"))),
),
])
.unwrap();
assert_eq!(
snp_manifest(snp.branches().into()).unwrap(),
b"\
alias HEAD\x0015:refs/heads/main\
revision refs/heads/develop\x0020:\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\
revision refs/heads/main\x0020:\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
"
);
// Checked against the implementation in https://archive.softwareheritage.org/swh:1:dir:60e683f48069373ee85227f2d7ab2eb1a8873ddb;origin=https://gitlab.softwareheritage.org/swh/devel/swh-model.git;visit=swh:1:snp:291aefbdccd43abac57629431201c2fd55284df7;anchor=swh:1:rev:9e54500902fc00ab1e6400431e2803b9bb41cc0a
assert_eq!(
snp.swhid().to_string(),
"swh:1:snp:9ecd7950d10ed3d02bfcf9c4a534f173697ab9f3"
);
}
|