Skip to content

Commit

Permalink
ROVER-245 Fix failing test and clippies
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrainer committed Nov 24, 2024
1 parent 91bbdc6 commit 2a746aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/command/lsp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use serde::Serialize;
use std::collections::HashMap;
use std::env::temp_dir;
use std::io::stdin;
use tokio::task::JoinHandle;
use tower_lsp::lsp_types::{Diagnostic, Range};
use tower_lsp::Server;
use tracing::debug;
Expand Down Expand Up @@ -105,15 +104,15 @@ async fn run_lsp(client_config: StudioClientConfig, lsp_opts: LspOpts) -> RoverR
HashMap::from_iter(
lazily_resolved_supergraph_config
.subgraphs()
.into_iter()
.iter()
.map(|(a, b)| (a.to_string(), b.schema().clone())),
),
);

let language_server = service.inner().clone();

// Spawn a separate thread to handle composition and passing that data to the language server
let _: JoinHandle<Result<(), Error>> = tokio::spawn(async move {
tokio::spawn(async move {
// Create a supergraph binary
// TODO: Check defaulting behaviour here and see if we need to centralise
let federation_version = lazily_resolved_supergraph_config
Expand Down Expand Up @@ -220,7 +219,7 @@ async fn run_lsp(client_config: StudioClientConfig, lsp_opts: LspOpts) -> RoverR
}
}
}
Ok(())
Ok::<(), Error>(())
});

let stdin = tokio::io::stdin();
Expand Down
6 changes: 3 additions & 3 deletions src/composition/supergraph/config/resolve/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl FullyResolvedSubgraph {
routing_url: Option<String>,
file: &Utf8PathBuf,
) -> Result<FullyResolvedSubgraph, ResolveSubgraphError> {
let schema = Fs::read_file(&file).map_err(|err| ResolveSubgraphError::Fs(Box::new(err)))?;
let schema = Fs::read_file(file).map_err(|err| ResolveSubgraphError::Fs(Box::new(err)))?;
let is_fed_two = schema_contains_link_directive(&schema);
Ok(FullyResolvedSubgraph {
routing_url: routing_url.clone(),
Expand All @@ -228,12 +228,12 @@ impl FullyResolvedSubgraph {
async fn resolve_subgraph(
fetch_remote_subgraph_impl: &impl FetchRemoteSubgraph,
routing_url: Option<String>,
graph_ref: &String,
graph_ref: &str,
subgraph: &String,
) -> Result<FullyResolvedSubgraph, ResolveSubgraphError> {
let graph_ref =
GraphRef::from_str(graph_ref).map_err(|err| ResolveSubgraphError::InvalidGraphRef {
graph_ref: graph_ref.clone(),
graph_ref: graph_ref.to_owned(),
source: Box::new(err),
})?;
let remote_subgraph = fetch_remote_subgraph_impl
Expand Down
18 changes: 15 additions & 3 deletions src/composition/watchers/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mod tests {

use anyhow::Result;
use apollo_federation_types::config::FederationVersion;
use apollo_federation_types::config::SchemaSource::Sdl;
use camino::Utf8PathBuf;
use futures::{
stream::{once, BoxStream},
Expand All @@ -155,6 +156,8 @@ mod tests {
use speculoos::prelude::*;
use tracing_test::traced_test;

use super::CompositionWatcher;
use crate::composition::CompositionSubgraphAdded;
use crate::{
composition::{
events::CompositionEvent,
Expand All @@ -172,8 +175,6 @@ mod tests {
},
};

use super::CompositionWatcher;

#[rstest]
#[case::success(false, serde_json::to_string(&default_composition_json()).unwrap())]
#[case::error(true, "invalid".to_string())]
Expand Down Expand Up @@ -216,7 +217,7 @@ mod tests {
indoc::indoc! {
r#"subgraphs:
{}:
routing_url: null
routing_url: localhost
schema:
sdl: '{}'
federation_version: null
Expand Down Expand Up @@ -253,6 +254,17 @@ mod tests {
let (mut composition_messages, composition_subtask) = Subtask::new(composition_handler);
let abort_handle = composition_subtask.run(subgraph_change_events);

// Assert we always get a subgraph added event.
let next_message = composition_messages.next().await;
assert_that!(next_message)
.is_some()
.is_equal_to(CompositionEvent::SubgraphAdded(CompositionSubgraphAdded {
name: String::from("subgraph-name"),
schema_source: Sdl {
sdl: String::from("type Query { test: String! }"),
},
}));

// Assert we always get a composition started event.
let next_message = composition_messages.next().await;
assert_that!(next_message)
Expand Down
8 changes: 4 additions & 4 deletions src/utils/supergraph_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ mod test_get_supergraph_config {
let supergraph_config_path = third_level_folder.path().join("supergraph.yaml");
fs::write(
supergraph_config_path.clone(),
&supergraph_config.into_bytes(),
supergraph_config.into_bytes(),
)
.expect("Could not write supergraph.yaml");

Expand Down Expand Up @@ -1185,7 +1185,7 @@ subgraphs:
routing_url: https://people.example.com
schema:
file: ./people.graphql"#,
latest_fed2_version.to_string()
latest_fed2_version
);
let tmp_home = TempDir::new().unwrap();
let mut config_path = Utf8PathBuf::try_from(tmp_home.path().to_path_buf()).unwrap();
Expand Down Expand Up @@ -1225,7 +1225,7 @@ subgraphs:
routing_url: https://people.example.com
schema:
file: ../../people.graphql"#,
latest_fed2_version.to_string()
latest_fed2_version
);
let tmp_home = TempDir::new().unwrap();
let tmp_dir = Utf8PathBuf::try_from(tmp_home.path().to_path_buf()).unwrap();
Expand Down Expand Up @@ -1279,7 +1279,7 @@ subgraphs:
routing_url: https://people.example.com
schema:
file: ../../people.graphql"#,
latest_fed2_version.to_string()
latest_fed2_version
);
let tmp_home = TempDir::new().unwrap();
let tmp_dir = Utf8PathBuf::try_from(tmp_home.path().to_path_buf()).unwrap();
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::env;
use std::io::BufRead;
use std::io::BufReader;
use std::path::Path;
use std::path::PathBuf;
use std::process::ChildStderr;
use std::time::Duration;
Expand Down

0 comments on commit 2a746aa

Please sign in to comment.