Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: describe latest federation versions #1363

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions latest_plugin_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"supergraph": {
"repository": "https://github.com/apollographql/federation-rs",
"versions": {
"latest-0": "v0.37.1",
"latest-2": "v2.1.2"
}
}
}
100 changes: 100 additions & 0 deletions tests/installers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,103 @@ fn get_binstall_scripts_root() -> Utf8PathBuf {
.join("binstall")
.join("scripts")
}

// this test ensures that `./latest_plugin_versions.json` exists and contains valid
// binary versions that can be downloaded from
#[test]
fn latest_plugins_are_valid_versions() {
use reqwest::{blocking::Client, Url};
use semver::Version;
use serde_json::Value;
// first, parse ./latest_plugin_versions.json to JSON
let latest_json: Value = serde_json::from_str(include_str!("../latest_plugin_versions.json")).expect("could not read latest_plugin_versions.json from the root of the repo, which is needed to supply latest versions to `rover supergraph compsoe`.");
let supergraph = latest_json["supergraph"]
.as_object()
.expect("JSON malformed: top-level `supergraphs` should be an object");
// then validate the fields we expect (and are also expected by https://rover.apollo.dev)
let versions = supergraph
.get("versions")
.expect("JSON malformed: `supergraph.versions` did not exist");

let latest_federation_one = versions
.get("latest-0")
.expect("JSON malformed: `supergraph.versions.latest-0` did not exist")
.as_str()
.expect("JSON malformed: `supergraph.versions.latest-0` was not a string");

assert!(latest_federation_one.starts_with("v"));
Version::parse(&latest_federation_one.to_string()[1..])
.expect("JSON malformed: `supergraph.versions.latest-0` was not valid semver");

let latest_federation_two = versions
.get("latest-2")
.expect("JSON malformed: `supergraph.versions.latest-2` did not exist")
.as_str()
.expect("JSON malformed: `supergraph.versions.latest-2` was not a string");

assert!(latest_federation_two.starts_with("v"));
Version::parse(&latest_federation_two.to_string()[1..])
.expect("JSON malformed: `supergraph.versions.latest-2 was not valid semver");

let repository = Url::parse(
&supergraph
.get("repository")
.expect("JSON malformed: `supergraph.resitory` does not exist")
.as_str()
.expect("JSON malformed: `supergraph.repository` is not a string"),
)
.expect("JSON malformed: `supergraph.repository` is not a valid URL");

// after validating the fields, make sure we can download the binaries from GitHub
let release_url = format!("{}/releases/download/", &repository);
let arch = match (std::env::consts::OS, std::env::consts::ARCH) {
("linux", "aarch64" | "arm") => "aarch64-unknown-linux-gnu",
("linux", _) => "x86_64-unknown-linux-gnu",
("macos", _) => "x86_64-apple-darwin",
("windows", _) => "x86_64-pc-windows-msvc",
_ => panic!("not linux, macos, or windows OS for this test runner"),
};
let latest_federation_one = format!(
"{url}supergraph@{version}/supergraph-{version}-{arch}.tar.gz",
url = &release_url,
version = &latest_federation_one
);
let latest_federation_two = format!(
"{url}supergraph@{version}/supergraph-{version}-{arch}.tar.gz",
url = &release_url,
version = &latest_federation_two
);
let client = Client::new();
client
.get(&latest_federation_one)
.send()
.unwrap_or_else(|e| {
panic!(
"could not send HEAD request to {}: {}",
&latest_federation_one, e
)
})
.error_for_status()
.unwrap_or_else(|e| {
panic!(
"HEAD request to {} failed with a status code: {}",
&latest_federation_one, e
)
});
client
.get(&latest_federation_two)
.send()
.unwrap_or_else(|e| {
panic!(
"could not send HEAD request to {}: {}",
&latest_federation_one, e
)
})
.error_for_status()
.unwrap_or_else(|e| {
panic!(
"HEAD request to {} failed with a status code: {}",
&latest_federation_one, e
)
});
}