Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bryn committed Dec 13, 2024
1 parent 14c3ed6 commit 1c0a232
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 158 deletions.
11 changes: 7 additions & 4 deletions apollo-router/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;

use buildstructor::{buildstructor};
use buildstructor::buildstructor;
use fred::clients::RedisClient;
use fred::interfaces::ClientLike;
use fred::interfaces::KeysInterface;
Expand Down Expand Up @@ -335,7 +335,11 @@ impl Telemetry {
}
}

pub(crate) fn extract_context(&self, request: &wiremock::Request, context: &Context) -> Context {
pub(crate) fn extract_context(
&self,
request: &wiremock::Request,
context: &Context,
) -> Context {
let headers: HashMap<String, String> = request
.headers
.iter()
Expand All @@ -362,8 +366,7 @@ impl Telemetry {
.expect("psr");
let new_trace_id = if original_span_context.is_valid() {
original_span_context.trace_id()
}
else {
} else {
context.span().span_context().trace_id()
};
context = context.with_remote_span_context(SpanContext::new(
Expand Down
7 changes: 5 additions & 2 deletions apollo-router/tests/integration/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ mod helper {
use wiremock::ResponseTemplate;

use super::test_is_enabled;
use crate::integration::common::{IntegrationTest, Query};
use crate::integration::common::IntegrationTest;
use crate::integration::common::Query;

/// Helper type for specifying a valid handler
pub type Handler = fn(&wiremock::Request) -> ResponseTemplate;
Expand Down Expand Up @@ -916,7 +917,9 @@ mod helper {

// Execute the request
let request = serde_json::to_value(requests)?;
let (_span, response) = router.execute_query(Query::builder().body(request).build()).await;
let (_span, response) = router
.execute_query(Query::builder().body(request).build())
.await;

serde_json::from_slice::<Vec<Response>>(&response.bytes().await?).map_err(BoxError::from)
}
Expand Down
7 changes: 5 additions & 2 deletions apollo-router/tests/integration/coprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use wiremock::matchers::path;
use wiremock::Mock;
use wiremock::ResponseTemplate;

use crate::integration::common::{graph_os_enabled, Query};
use crate::integration::common::graph_os_enabled;
use crate::integration::common::Query;
use crate::integration::IntegrationTest;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -75,7 +76,9 @@ async fn test_coprocessor_limit_payload() -> Result<(), BoxError> {
assert_eq!(response.status(), 200);

// This query is huge and will be rejected because it is too large before hitting the coprocessor
let (_trace_id, response) = router.execute_query(Query::default().with_huge_query()).await;
let (_trace_id, response) = router
.execute_query(Query::default().with_huge_query())
.await;
assert_eq!(response.status(), 413);
assert_yaml_snapshot!(response.text().await?);

Expand Down
5 changes: 3 additions & 2 deletions apollo-router/tests/integration/introspection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::integration::common::Query;
use crate::integration::IntegrationTest;
use apollo_router::plugin::test::MockSubgraph;
use apollo_router::services::supergraph::Request;
use serde_json::json;
use tower::ServiceExt;

use crate::integration::common::Query;
use crate::integration::IntegrationTest;

#[tokio::test]
async fn simple() {
let request = Request::fake_builder()
Expand Down
9 changes: 7 additions & 2 deletions apollo-router/tests/integration/operation_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use apollo_router::TestHarness;
use serde_json::json;
use tower::BoxError;
use tower::ServiceExt;

use crate::integration::common::Query;
use crate::integration::IntegrationTest;

Expand Down Expand Up @@ -310,7 +311,9 @@ async fn test_request_bytes_limit_with_coprocessor() -> Result<(), BoxError> {
.await;
router.start().await;
router.assert_started().await;
let (_, resp) = router.execute_query(Query::default().with_huge_query()).await;
let (_, resp) = router
.execute_query(Query::default().with_huge_query())
.await;
assert_eq!(resp.status(), 413);
router.graceful_shutdown().await;
Ok(())
Expand All @@ -324,7 +327,9 @@ async fn test_request_bytes_limit() -> Result<(), BoxError> {
.await;
router.start().await;
router.assert_started().await;
let (_, resp) = router.execute_query(Query::default().with_huge_query()).await;
let (_, resp) = router
.execute_query(Query::default().with_huge_query())
.await;
assert_eq!(resp.status(), 413);
router.graceful_shutdown().await;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde_json::json;

use crate::integration::common::Query;
use crate::integration::IntegrationTest;

Expand Down Expand Up @@ -31,10 +32,14 @@ async fn reports_evaluated_plans() {
router.start().await;
router.assert_started().await;
router
.execute_query(Query::builder().body(json!({
"query": r#"{ t { v1 v2 v3 v4 } }"#,
"variables": {},
})).build())
.execute_query(
Query::builder()
.body(json!({
"query": r#"{ t { v1 v2 v3 v4 } }"#,
"variables": {},
}))
.build(),
)
.await;

let metrics = router
Expand Down Expand Up @@ -70,10 +75,14 @@ async fn does_not_exceed_max_evaluated_plans() {
router.start().await;
router.assert_started().await;
router
.execute_query(Query::builder().body(json!({
"query": r#"{ t { v1 v2 v3 v4 } }"#,
"variables": {},
})).build())
.execute_query(
Query::builder()
.body(json!({
"query": r#"{ t { v1 v2 v3 v4 } }"#,
"variables": {},
}))
.build(),
)
.await;

let metrics = router
Expand Down
11 changes: 8 additions & 3 deletions apollo-router/tests/integration/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use serde_json::Value;
use tower::BoxError;
use tower::ServiceExt;

use crate::integration::common::{graph_os_enabled, Query};
use crate::integration::common::graph_os_enabled;
use crate::integration::common::Query;
use crate::integration::IntegrationTest;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -1072,11 +1073,15 @@ async fn test_redis_query_plan_config_update(updated_config: &str, new_cache_key
);
assert_ne!(starting_key, new_cache_key, "starting_key (cache key for the initial config) and new_cache_key (cache key with the updated config) should not be equal. This either means that the cache key is not being generated correctly, or that the test is not actually checking the updated key.");

router.execute_query(Query::default().with_anonymous()).await;
router
.execute_query(Query::default().with_anonymous())
.await;
router.assert_redis_cache_contains(starting_key, None).await;
router.update_config(updated_config).await;
router.assert_reloaded().await;
router.execute_query(Query::default().with_anonymous()).await;
router
.execute_query(Query::default().with_anonymous())
.await;
router
.assert_redis_cache_contains(new_cache_key, Some(starting_key))
.await;
Expand Down
69 changes: 50 additions & 19 deletions apollo-router/tests/integration/subgraph_response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde_json::json;
use tower::BoxError;
use wiremock::ResponseTemplate;

use crate::integration::common::Query;
use crate::integration::IntegrationTest;

Expand All @@ -21,7 +22,9 @@ async fn test_subgraph_returning_data_null() -> Result<(), BoxError> {
router.assert_started().await;

let query = "{ __typename topProducts { name } }";
let (_trace_id, response) = router.execute_query(Query::builder().body(json!({ "query": query })).build()).await;
let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": query })).build())
.await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
Expand Down Expand Up @@ -64,7 +67,9 @@ async fn test_subgraph_returning_different_typename_on_query_root() -> Result<()
inside_fragment: __typename
}
"#;
let (_trace_id, response) = router.execute_query(Query::builder().body(json!({ "query": query })).build()).await;
let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": query })).build())
.await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
Expand Down Expand Up @@ -99,7 +104,11 @@ async fn test_valid_extensions_service_for_subgraph_error() -> Result<(), BoxErr
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -141,7 +150,11 @@ async fn test_valid_extensions_service_is_preserved_for_subgraph_error() -> Resu
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -174,7 +187,11 @@ async fn test_valid_extensions_service_for_invalid_subgraph_response() -> Result
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -222,7 +239,11 @@ async fn test_valid_error_locations() -> Result<(), BoxError> {
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -264,7 +285,11 @@ async fn test_empty_error_locations() -> Result<(), BoxError> {
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -302,7 +327,11 @@ async fn test_invalid_error_locations() -> Result<(), BoxError> {
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -345,7 +374,11 @@ async fn test_invalid_error_locations_with_single_negative_one_location() -> Res
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -387,7 +420,11 @@ async fn test_invalid_error_locations_contains_negative_one_location() -> Result
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::builder().body(json!({ "query": "{ topProducts { name } }" })).build())
.execute_query(
Query::builder()
.body(json!({ "query": "{ topProducts { name } }" }))
.build(),
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -427,9 +464,7 @@ async fn test_valid_error_path() -> Result<(), BoxError> {
router.start().await;
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::default())
.await;
let (_trace_id, response) = router.execute_query(Query::default()).await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
Expand Down Expand Up @@ -464,9 +499,7 @@ async fn test_invalid_error_path() -> Result<(), BoxError> {
router.start().await;
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::default())
.await;
let (_trace_id, response) = router.execute_query(Query::default()).await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
Expand Down Expand Up @@ -502,9 +535,7 @@ async fn test_partially_valid_error_path() -> Result<(), BoxError> {
router.start().await;
router.assert_started().await;

let (_trace_id, response) = router
.execute_query(Query::default())
.await;
let (_trace_id, response) = router.execute_query(Query::default()).await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
Expand Down
8 changes: 6 additions & 2 deletions apollo-router/tests/integration/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use http::HeaderValue;
use serde_json::json;
use tower::BoxError;

use super::common::{IntegrationTest, Query};
use super::common::IntegrationTest;
use super::common::Query;
use super::common::Telemetry;

const SUBSCRIPTION_CONFIG: &str = include_str!("../fixtures/subscription.router.yaml");
Expand Down Expand Up @@ -59,7 +60,10 @@ async fn test_subscription_load() -> Result<(), BoxError> {

for _ in 0..100 {
let (_id, resp) = router
.execute_query(Query::builder().body(json!({"query":"query ExampleQuery {topProducts{name}}","variables":{}})).build(),
.execute_query(
Query::builder()
.body(json!({"query":"query ExampleQuery {topProducts{name}}","variables":{}}))
.build(),
)
.await;
assert!(resp.status().is_success());
Expand Down
Loading

0 comments on commit 1c0a232

Please sign in to comment.