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

feat(tests): e2e supergraph fetch #2024

Merged
merged 2 commits into from
Aug 5, 2024
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
49 changes: 49 additions & 0 deletions tests/e2e/supergraph/fetch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::fs::read_to_string;
use std::process::Command;

use assert_cmd::prelude::CommandCargoExt;
use httpmock::Regex;
use rstest::rstest;
use tempfile::Builder;
use tracing::error;
use tracing_test::traced_test;

use crate::e2e::remote_supergraph_graphref;

#[rstest]
#[ignore]
#[tokio::test(flavor = "multi_thread")]
#[traced_test]
async fn e2e_test_rover_supergraph_fetch(remote_supergraph_graphref: String) {
// GIVEN
// - supergraph fetch with a file output
let out_file = Builder::new()
.suffix(".graphql")
.tempfile()
.expect("Could not create output file");

// WHEN
// - invoked
let mut cmd = Command::cargo_bin("rover").expect("Could not find necessary binary");
cmd.args([
"supergraph",
"fetch",
"--output",
out_file.path().to_str().unwrap(),
&remote_supergraph_graphref,
]);

// THEN
// - successful command; no panics, stderr messages
// - the Query type exists, meaning that a schema was properly fetched
let output = cmd.output().expect("Could not run command");
if !output.status.success() {
error!("{}", String::from_utf8(output.stderr).unwrap());
panic!("Command did not complete successfully");
}
let fetched_schema = read_to_string(out_file.path()).expect("Could not read output file");
let re = Regex::new("query: Query").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again would it be better to assert against the schema we expect via the diff function?

let query_type_found = re.is_match(&fetched_schema);

assert!(query_type_found);
}
1 change: 1 addition & 0 deletions tests/e2e/supergraph/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod compose;
mod fetch;
Loading