Skip to content

Commit 6a33c38

Browse files
Added some tests for completeness.
1 parent d971419 commit 6a33c38

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

rs/registry/helpers/src/subnet.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,74 @@ mod tests {
10211021
assert_matches!(result, Err(RegistryClientError::DecodeError { .. }));
10221022
}
10231023

1024+
// This wouldn't occur in practice, so this test is "just" for completeness.
1025+
#[test]
1026+
fn replica_version_id_with_illegal_characters_is_an_error() {
1027+
// Step 1: Prepare the world. A SubnetRecord whose replica_version_id
1028+
// contains a character that ReplicaVersion::try_from rejects.
1029+
let data_provider = ProtoRegistryDataProvider::new();
1030+
data_provider
1031+
.add(
1032+
&make_subnet_record_key(subnet_id(1)),
1033+
RegistryVersion::from(2),
1034+
Some(SubnetRecord {
1035+
replica_version_id: "G@RBAGE".to_string(),
1036+
..Default::default()
1037+
}),
1038+
)
1039+
.unwrap();
1040+
let registry = FakeRegistryClient::new(Arc::new(data_provider));
1041+
registry.update_to_latest_version();
1042+
1043+
// Step 2: Run the code under test.
1044+
let result = registry.get_replica_version(subnet_id(1), RegistryVersion::from(2));
1045+
1046+
// Step 3: Verify result(s).
1047+
assert_matches!(result, Err(RegistryClientError::DecodeError { .. }));
1048+
}
1049+
1050+
// This wouldn't occur in practice, so this test is "just" for completeness.
1051+
#[test]
1052+
fn resolved_standard_engine_replica_version_id_with_illegal_characters_is_an_error() {
1053+
// Step 1: Prepare the world. An engine subnet with a blank
1054+
// replica_version_id, resolving (via
1055+
// StandardEngineReplicaVersionRecord) to a new_replica_version_id
1056+
// that ReplicaVersion::try_from rejects.
1057+
let data_provider = ProtoRegistryDataProvider::new();
1058+
data_provider
1059+
.add(
1060+
&make_subnet_record_key(subnet_id(1)),
1061+
RegistryVersion::from(2),
1062+
Some(SubnetRecord {
1063+
replica_version_id: "".to_string(),
1064+
subnet_type: SubnetType::CloudEngine as i32,
1065+
..Default::default()
1066+
}),
1067+
)
1068+
.unwrap();
1069+
data_provider
1070+
.add(
1071+
&make_standard_engine_replica_version_record_key(),
1072+
RegistryVersion::from(2),
1073+
Some(StandardEngineReplicaVersionRecord {
1074+
new_replica_version_id: "G@RBAGE".to_string(),
1075+
old_replica_version_id: "old".to_string(),
1076+
// Guarantees priority <= this, so new_replica_version_id
1077+
// (the illegal one) is the one that gets resolved.
1078+
deployment_progress: 1.0,
1079+
}),
1080+
)
1081+
.unwrap();
1082+
let registry = FakeRegistryClient::new(Arc::new(data_provider));
1083+
registry.update_to_latest_version();
1084+
1085+
// Step 2: Run the code under test.
1086+
let result = registry.get_replica_version(subnet_id(1), RegistryVersion::from(2));
1087+
1088+
// Step 3: Verify result(s).
1089+
assert_matches!(result, Err(RegistryClientError::DecodeError { .. }));
1090+
}
1091+
10241092
#[test]
10251093
fn can_get_is_halted_from_subnet() {
10261094
let subnet_id = subnet_id(4);

0 commit comments

Comments
 (0)