Skip to content

Commit

Permalink
Add function to check for macOS support in Federation Versions (#533)
Browse files Browse the repository at this point in the history
At present we have a check for ARM Linux support but no corresponding
check for ARM on macOS. This adds that check and a test to ensure we
retain the supported versions we want in the future.
  • Loading branch information
jonathanrainer authored Jul 11, 2024
2 parents 5d08f7d + 3f0eb5d commit 1661bce
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 6 deletions.
90 changes: 84 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apollo-federation-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ serde_json = {version = "1", optional = true}

[dev-dependencies]
assert_fs = "1"
rstest = "0.21.0"
serde_json = "1"
serde_yaml = "0.8"
39 changes: 39 additions & 0 deletions apollo-federation-types/src/config/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ impl FederationVersion {
}
supports_arm
}

pub fn supports_arm_macos(&self) -> bool {
let mut supports_arm = false;
// No published fed1 version supports aarch64 on macOS
if self.is_fed_two() {
if self.is_latest() {
supports_arm = true;
} else if let Some(exact) = self.get_exact() {
// v2.7.3 is the earliest version published with aarch64 support for macOS
supports_arm = exact.ge(&Version::parse("2.7.3").unwrap())
}
}
supports_arm
}
}

impl PluginVersion for FederationVersion {
Expand Down Expand Up @@ -227,6 +241,7 @@ impl<'de> Deserialize<'de> for FederationVersion {

#[cfg(test)]
mod test_federation_version {
use rstest::rstest;
use serde_yaml::Value;

use crate::config::FederationVersion;
Expand Down Expand Up @@ -281,4 +296,28 @@ mod test_federation_version {
serde_yaml::from_str("v0.37.8").unwrap()
);
}

#[rstest]
#[case::fed1_latest(FederationVersion::LatestFedOne, true)]
#[case::fed1_supported(FederationVersion::ExactFedOne("0.37.2".parse().unwrap()), true)]
#[case::fed1_supported_boundary(FederationVersion::ExactFedOne("0.37.1".parse().unwrap()), true)]
#[case::fed1_unsupported(FederationVersion::ExactFedOne("0.25.0".parse().unwrap()), false)]
#[case::fed2_latest(FederationVersion::LatestFedTwo, true)]
#[case::fed2_supported(FederationVersion::ExactFedTwo("2.4.5".parse().unwrap()), true)]
#[case::fed2_supported_boundary(FederationVersion::ExactFedTwo("2.1.0".parse().unwrap()), true)]
#[case::fed2_unsupported(FederationVersion::ExactFedTwo("2.0.1".parse().unwrap()), false)]
fn test_supports_arm_linux(#[case] version: FederationVersion, #[case] expected: bool) {
assert_eq!(version.supports_arm_linux(), expected)
}

#[rstest]
#[case::fed1_latest(FederationVersion::LatestFedOne, false)]
#[case::fed1_unsupported(FederationVersion::ExactFedOne("0.37.2".parse().unwrap()), false)]
#[case::fed2_latest(FederationVersion::LatestFedTwo, true)]
#[case::fed2_supported(FederationVersion::ExactFedTwo("2.8.1".parse().unwrap()), true)]
#[case::fed2_supported_boundary(FederationVersion::ExactFedTwo("2.7.3".parse().unwrap()), true)]
#[case::fed2_unsupported(FederationVersion::ExactFedTwo("2.6.5".parse().unwrap()), false)]
fn test_supports_arm_macos(#[case] version: FederationVersion, #[case] expected: bool) {
assert_eq!(version.supports_arm_macos(), expected)
}
}

0 comments on commit 1661bce

Please sign in to comment.