Skip to content

Commit 8461a0f

Browse files
committed
clean and update tests
1 parent 6aec582 commit 8461a0f

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

crates/fig_install/src/index.rs

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,13 @@ mod tests {
775775

776776
#[test]
777777
fn index_test_allowed_autoupdate_product_names_update() {
778+
// Loads an index with the versions:
779+
// - 1.1.0 | no update conditions
780+
// - 1.2.0 | no update conditions
781+
// - 1.2.1 | update conditions = [AllowedAutoUpdateProductNames("qv2")]
778782
let mut index = load_test_index();
779783

784+
// ProductName("Amazon Q") can update into 1.2.1 during manual update
780785
let next = index
781786
.find_next_version(FindNextVersionArgs {
782787
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
@@ -795,6 +800,8 @@ mod tests {
795800
"1.2.1",
796801
"amazon q during manual update should update into 1.2.1"
797802
);
803+
804+
// ProductName("Amazon Q") updates into 1.2.0 during auto update
798805
let next = index
799806
.find_next_version(FindNextVersionArgs {
800807
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
@@ -813,6 +820,8 @@ mod tests {
813820
"1.2.0",
814821
"amazon q during auto update should update into 1.2.0"
815822
);
823+
824+
// ProductName("qv2") updates into 1.2.1 during auto update
816825
let next = index
817826
.find_next_version(FindNextVersionArgs {
818827
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
@@ -832,10 +841,11 @@ mod tests {
832841
"qv2 during auto update should update into 1.2.1"
833842
);
834843

835-
// Push a newer update that allows Amazon Q
844+
// Push a newer update that allows both Amazon Q and qv2 to auto update into
836845
let mut last = index.versions.last().cloned().unwrap();
837846
last.update_conditions = vec![UpdateCondition::AllowedAutoUpdateProductNames(vec![
838847
ProductName::AmazonQ,
848+
ProductName::Unknown("qv2".to_string()),
839849
])];
840850
last.version = Version::from_str("2.0.0").unwrap();
841851
index.versions.push(last);
@@ -854,6 +864,24 @@ mod tests {
854864
.unwrap()
855865
.expect("should have update package");
856866
assert_eq!(next.version.to_string().as_str(), "2.0.0");
867+
let next = index
868+
.find_next_version(FindNextVersionArgs {
869+
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
870+
variant: &Variant::Full,
871+
file_type: None,
872+
current_version: "1.0.5",
873+
product_name: &ProductName::Unknown("qv2".to_string()),
874+
ignore_rollout: true,
875+
is_auto_update: true,
876+
threshold_override: None,
877+
})
878+
.unwrap()
879+
.expect("should have update package");
880+
assert_eq!(
881+
next.version.to_string().as_str(),
882+
"2.0.0",
883+
"qv2 during auto update should update into 2.0.0"
884+
);
857885
}
858886

859887
#[test]
@@ -884,4 +912,58 @@ mod tests {
884912
"qv2 should update into 1.2.1"
885913
);
886914
}
915+
916+
#[test]
917+
fn index_test_multiple_update_conditions_uses_and_boolean_logic() {
918+
let mut index = load_test_index();
919+
920+
// - 1.2.1 | update conditions = [AllowedAutoUpdateProductNames("qv2")]
921+
let next = index
922+
.find_next_version(FindNextVersionArgs {
923+
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
924+
variant: &Variant::Full,
925+
file_type: None,
926+
current_version: "1.0.5",
927+
product_name: &ProductName::Unknown("qv2".to_string()),
928+
ignore_rollout: true,
929+
is_auto_update: true,
930+
threshold_override: None,
931+
})
932+
.unwrap()
933+
.expect("should have update package");
934+
assert_eq!(
935+
next.version.to_string().as_str(),
936+
"1.2.1",
937+
"qv2 should update into 1.2.1"
938+
);
939+
940+
index
941+
.versions
942+
.last_mut()
943+
.unwrap()
944+
.update_conditions
945+
.push(UpdateCondition::AllowedAutoUpdateProductNames(vec![
946+
ProductName::AmazonQ,
947+
]));
948+
949+
// qv2 can no longer update into 1.2.1
950+
let next = index
951+
.find_next_version(FindNextVersionArgs {
952+
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
953+
variant: &Variant::Full,
954+
file_type: None,
955+
current_version: "1.0.5",
956+
product_name: &ProductName::Unknown("qv2".to_string()),
957+
ignore_rollout: true,
958+
is_auto_update: true,
959+
threshold_override: None,
960+
})
961+
.unwrap()
962+
.expect("should have update package");
963+
assert_eq!(
964+
next.version.to_string().as_str(),
965+
"1.2.0",
966+
"qv2 should update into 1.2.0"
967+
);
968+
}
887969
}

0 commit comments

Comments
 (0)