From 9d323a64e824a0a5478b44f7b31900f3a50d1c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Thu, 1 Feb 2024 13:12:37 +0100 Subject: [PATCH] chore: introduce and use `TargetRuntime` (#1086) --- cloudflare/src/handle.rs | 33 ++++++---------------------- cloudflare/src/lib.rs | 16 ++++++++++++++ src/app_context.rs | 27 +++++++---------------- src/cli/mod.rs | 11 ++++++++++ src/cli/server/server_config.rs | 11 ++-------- src/cli/tc.rs | 13 ++++++----- src/config/reader.rs | 38 +++++++++++++++------------------ src/grpc/data_loader_request.rs | 7 +++--- src/grpc/protobuf.rs | 7 +++--- src/grpc/request_template.rs | 7 +++--- src/http/request_context.rs | 8 +++---- src/lib.rs | 1 + src/target_runtime.rs | 17 +++++++++++++++ tests/graphql_spec.rs | 22 ++++++------------- tests/http_spec.rs | 19 ++++++++++++----- tests/server_spec.rs | 12 +++++------ 16 files changed, 124 insertions(+), 125 deletions(-) create mode 100644 src/target_runtime.rs diff --git a/cloudflare/src/handle.rs b/cloudflare/src/handle.rs index 2f9401e196..eb686e1906 100644 --- a/cloudflare/src/handle.rs +++ b/cloudflare/src/handle.rs @@ -9,10 +9,10 @@ use tailcall::blueprint::Blueprint; use tailcall::config::reader::ConfigReader; use tailcall::config::ConfigSet; use tailcall::http::{graphiql, handle_request, AppContext}; -use tailcall::EnvIO; +use tailcall::target_runtime::TargetRuntime; use crate::http::{to_request, to_response}; -use crate::{init_cache, init_env, init_file, init_http}; +use crate::init_runtime; lazy_static! { static ref APP_CTX: RwLock)>> = RwLock::new(None); @@ -52,19 +52,8 @@ pub async fn fetch(req: worker::Request, env: worker::Env) -> anyhow::Result, - env: Rc, - file_path: &str, -) -> anyhow::Result { - let bucket_id = env_io - .get("BUCKET") - .ok_or(anyhow!("BUCKET var is not set"))?; - log::debug!("R2 Bucket ID: {}", bucket_id); - let file_io = init_file(env.clone(), bucket_id)?; - let http_io = init_http(); - - let reader = ConfigReader::init(file_io, http_io); +async fn get_config(runtime: TargetRuntime, file_path: &str) -> anyhow::Result { + let reader = ConfigReader::init(runtime); let config = reader.read(&file_path).await?; Ok(config) } @@ -82,21 +71,13 @@ async fn get_app_ctx(env: Rc, file_path: &str) -> anyhow::Result) -> Arc) -> anyhow::Result { + let http = init_http(); + let env_io = init_env(env.clone()); + let bucket_id = env_io + .get("BUCKET") + .ok_or(anyhow!("BUCKET var is not set"))?; + Ok(TargetRuntime { + http: http.clone(), + http2_only: http.clone(), + env: init_env(env.clone()), + file: init_file(env.clone(), bucket_id)?, + cache: init_cache(env), + }) +} + #[worker::event(fetch)] async fn fetch( req: worker::Request, diff --git a/src/app_context.rs b/src/app_context.rs index 5198d9c11c..43ee778173 100644 --- a/src/app_context.rs +++ b/src/app_context.rs @@ -7,32 +7,24 @@ use crate::blueprint::Type::ListType; use crate::blueprint::{Blueprint, Definition}; use crate::data_loader::DataLoader; use crate::graphql::GraphqlDataLoader; +use crate::grpc; use crate::grpc::data_loader::GrpcDataLoader; use crate::http::{DataLoaderRequest, HttpDataLoader}; use crate::lambda::{DataLoaderId, Expression, IO}; -use crate::{grpc, EntityCache, EnvIO, HttpIO}; +use crate::target_runtime::TargetRuntime; pub struct AppContext { pub schema: dynamic::Schema, - pub universal_http_client: Arc, - pub http2_only_client: Arc, + pub runtime: TargetRuntime, pub blueprint: Blueprint, pub http_data_loaders: Arc>>, pub gql_data_loaders: Arc>>, pub grpc_data_loaders: Arc>>, - pub cache: Arc, - pub env_vars: Arc, } impl AppContext { #[allow(clippy::too_many_arguments)] - pub fn new( - mut blueprint: Blueprint, - h_client: Arc, - h2_client: Arc, - env: Arc, - cache: Arc, - ) -> Self { + pub fn new(mut blueprint: Blueprint, runtime: TargetRuntime) -> Self { let mut http_data_loaders = vec![]; let mut gql_data_loaders = vec![]; let mut grpc_data_loaders = vec![]; @@ -44,7 +36,7 @@ impl AppContext { match expr { IO::Http { req_template, group_by, .. } => { let data_loader = HttpDataLoader::new( - h_client.clone(), + runtime.http.clone(), group_by.clone(), matches!(&field.of_type, ListType { .. }), ) @@ -63,7 +55,7 @@ impl AppContext { IO::GraphQLEndpoint { req_template, field_name, batch, .. } => { let graphql_data_loader = - GraphqlDataLoader::new(h_client.clone(), *batch) + GraphqlDataLoader::new(runtime.http.clone(), *batch) .to_data_loader( blueprint.upstream.batch.clone().unwrap_or_default(), ); @@ -80,7 +72,7 @@ impl AppContext { IO::Grpc { req_template, group_by, .. } => { let data_loader = GrpcDataLoader { - client: h2_client.clone(), + client: runtime.http2_only.clone(), operation: req_template.operation.clone(), group_by: group_by.clone(), }; @@ -106,14 +98,11 @@ impl AppContext { AppContext { schema, - universal_http_client: h_client, - http2_only_client: h2_client, + runtime, blueprint, http_data_loaders: Arc::new(http_data_loaders), gql_data_loaders: Arc::new(gql_data_loaders), - cache, grpc_data_loaders: Arc::new(grpc_data_loaders), - env_vars: env, } } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index cda8baeb3d..a61931e35d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -21,6 +21,7 @@ pub use tc::run; use crate::cache::InMemoryCache; use crate::config::Upstream; +use crate::target_runtime::TargetRuntime; use crate::{blueprint, EnvIO, FileIO, HttpIO}; // Provides access to env in native rust environment @@ -61,3 +62,13 @@ pub fn init_http2_only(upstream: &Upstream, script: Option) - pub fn init_in_memory_cache() -> InMemoryCache { InMemoryCache::new() } + +pub fn init_runtime(upstream: &Upstream, script: Option) -> TargetRuntime { + TargetRuntime { + http: init_http(upstream, script.clone()), + http2_only: init_http2_only(upstream, script), + env: init_env(), + file: init_file(), + cache: Arc::new(init_in_memory_cache()), + } +} diff --git a/src/cli/server/server_config.rs b/src/cli/server/server_config.rs index 0fba845dc4..2e41ed96c4 100644 --- a/src/cli/server/server_config.rs +++ b/src/cli/server/server_config.rs @@ -2,7 +2,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::sync::Arc; use crate::blueprint::{Blueprint, Http}; -use crate::cli::{init_env, init_http, init_http2_only, init_in_memory_cache}; +use crate::cli::init_runtime; use crate::http::AppContext; pub struct ServerConfig { @@ -12,16 +12,9 @@ pub struct ServerConfig { impl ServerConfig { pub fn new(blueprint: Blueprint) -> Self { - let h_client = init_http(&blueprint.upstream, blueprint.server.script.clone()); - let h2_client = init_http2_only(&blueprint.upstream, blueprint.server.script.clone()); - let env = init_env(); - let chrono_cache = Arc::new(init_in_memory_cache()); let server_context = Arc::new(AppContext::new( blueprint.clone(), - h_client, - h2_client, - env, - chrono_cache, + init_runtime(&blueprint.upstream, blueprint.server.script.clone()), )); Self { app_ctx: server_context, blueprint } } diff --git a/src/cli/tc.rs b/src/cli/tc.rs index 45ac278e38..c2c0f0c5a6 100644 --- a/src/cli/tc.rs +++ b/src/cli/tc.rs @@ -1,5 +1,4 @@ use std::path::Path; -use std::sync::Arc; use std::{env, fs}; use anyhow::Result; @@ -13,11 +12,11 @@ use super::update_checker; use crate::blueprint::{validate_operations, Blueprint, OperationQuery}; use crate::cli::fmt::Fmt; use crate::cli::server::Server; -use crate::cli::{init_file, init_http, CLIError}; +use crate::cli::{init_runtime, CLIError}; use crate::config::reader::ConfigReader; use crate::config::{Config, Upstream}; +use crate::print_schema; use crate::valid::Validator; -use crate::{print_schema, FileIO}; const FILE_NAME: &str = ".tailcallrc.graphql"; const YML_FILE_NAME: &str = ".graphqlrc.yml"; @@ -26,9 +25,8 @@ pub async fn run() -> Result<()> { let cli = Cli::parse(); logger_init(); update_checker::check_for_update().await; - let file_io: Arc = init_file(); - let default_http_io = init_http(&Upstream::default(), None); - let config_reader = ConfigReader::init(file_io.clone(), default_http_io); + let runtime = init_runtime(&Upstream::default(), None); + let config_reader = ConfigReader::init(runtime.clone()); match cli.command { Command::Start { file_paths } => { let config_set = config_reader.read_all(&file_paths).await?; @@ -51,7 +49,8 @@ pub async fn run() -> Result<()> { let ops: Vec = futures_util::future::join_all(operations.iter().map(|op| async { - file_io + runtime + .file .read(op) .await .map(|query| OperationQuery::new(query, op.clone())) diff --git a/src/config/reader.rs b/src/config/reader.rs index 48527c8829..825fa53c1e 100644 --- a/src/config/reader.rs +++ b/src/config/reader.rs @@ -1,5 +1,4 @@ use std::collections::{HashMap, VecDeque}; -use std::sync::Arc; use anyhow::Context; use futures_util::future::join_all; @@ -10,14 +9,13 @@ use url::Url; use super::{ConfigSet, ExprBody, Extensions, Script, ScriptOptions}; use crate::config::{Config, Source}; -use crate::{FileIO, HttpIO}; +use crate::target_runtime::TargetRuntime; const NULL_STR: &str = "\0\0\0\0\0\0\0"; /// Reads the configuration from a file or from an HTTP URL and resolves all linked extensions to create a ConfigSet. pub struct ConfigReader { - file_io: Arc, - http_io: Arc, + runtime: TargetRuntime, } /// Response of a file read operation @@ -27,8 +25,8 @@ struct FileRead { } impl ConfigReader { - pub fn init(file_io: Arc, http_io: Arc) -> Self { - Self { file_io, http_io } + pub fn init(runtime: TargetRuntime) -> Self { + Self { runtime } } /// Reads a file from the filesystem or from an HTTP URL @@ -36,7 +34,8 @@ impl ConfigReader { // Is an HTTP URL let content = if let Ok(url) = Url::parse(&file.to_string()) { let response = self - .http_io + .runtime + .http .execute(reqwest::Request::new(reqwest::Method::GET, url)) .await?; @@ -44,7 +43,7 @@ impl ConfigReader { } else { // Is a file path - self.file_io.read(&file.to_string()).await? + self.runtime.file.read(&file.to_string()).await? }; Ok(FileRead { content, path: file.to_string() }) @@ -187,13 +186,13 @@ mod test_proto_config { use anyhow::{Context, Result}; - use crate::cli::{init_file, init_http}; + use crate::cli::init_runtime; use crate::config::reader::ConfigReader; #[tokio::test] async fn test_resolve() { // Skipping IO tests as they are covered in reader.rs - let reader = ConfigReader::init(init_file(), init_http(&Default::default(), None)); + let reader = ConfigReader::init(init_runtime(&Default::default(), None)); reader .read_proto("google/protobuf/empty.proto") .await @@ -219,7 +218,7 @@ mod test_proto_config { assert!(test_file.exists()); let test_file = test_file.to_str().unwrap().to_string(); - let reader = ConfigReader::init(init_file(), init_http(&Default::default(), None)); + let reader = ConfigReader::init(init_runtime(&Default::default(), None)); let helper_map = reader .resolve_descriptors(HashMap::new(), test_file) .await?; @@ -264,7 +263,7 @@ mod reader_tests { use pretty_assertions::assert_eq; use tokio::io::AsyncReadExt; - use crate::cli::{init_file, init_http}; + use crate::cli::init_runtime; use crate::config::reader::ConfigReader; use crate::config::{Config, Script, ScriptOptions, Type, Upstream}; @@ -274,8 +273,7 @@ mod reader_tests { #[tokio::test] async fn test_all() { - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); + let runtime = init_runtime(&Upstream::default(), None); let mut cfg = Config::default(); cfg.schema.query = Some("Test".to_string()); @@ -309,7 +307,7 @@ mod reader_tests { .iter() .map(|x| x.to_string()) .collect(); - let cr = ConfigReader::init(file_io, http_io); + let cr = ConfigReader::init(runtime); let c = cr.read_all(&files).await.unwrap(); assert_eq!( ["Post", "Query", "Test", "User"] @@ -327,8 +325,7 @@ mod reader_tests { #[tokio::test] async fn test_local_files() { - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); + let runtime = init_runtime(&Upstream::default(), None); let files: Vec = [ "examples/jsonplaceholder.yml", @@ -338,7 +335,7 @@ mod reader_tests { .iter() .map(|x| x.to_string()) .collect(); - let cr = ConfigReader::init(file_io, http_io); + let cr = ConfigReader::init(runtime); let c = cr.read_all(&files).await.unwrap(); assert_eq!( ["Post", "Query", "User"] @@ -354,11 +351,10 @@ mod reader_tests { #[tokio::test] async fn test_script_loader() { - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); + let runtime = init_runtime(&Upstream::default(), None); let cargo_manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let reader = ConfigReader::init(file_io, http_io); + let reader = ConfigReader::init(runtime); let config = reader .read(&format!( diff --git a/src/grpc/data_loader_request.rs b/src/grpc/data_loader_request.rs index 434d644cb3..9cb2869634 100644 --- a/src/grpc/data_loader_request.rs +++ b/src/grpc/data_loader_request.rs @@ -61,7 +61,7 @@ mod tests { use url::Url; use super::DataLoaderRequest; - use crate::cli::{init_file, init_http}; + use crate::cli::init_runtime; use crate::config::reader::ConfigReader; use crate::config::{Config, Field, Grpc, Type, Upstream}; use crate::grpc::protobuf::{ProtobufOperation, ProtobufSet}; @@ -75,8 +75,7 @@ mod tests { test_file.push("tests"); test_file.push("greetings.proto"); - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); + let runtime = init_runtime(&Upstream::default(), None); let mut config = Config::default(); let grpc = Grpc { proto_path: test_file.to_str().unwrap().to_string(), @@ -86,7 +85,7 @@ mod tests { "foo".to_string(), Type::default().fields(vec![("bar", Field::default().grpc(grpc))]), ); - let reader = ConfigReader::init(file_io, http_io); + let reader = ConfigReader::init(runtime); let config_set = reader.resolve(config).await.unwrap(); let protobuf_set = diff --git a/src/grpc/protobuf.rs b/src/grpc/protobuf.rs index c350bfd1b7..3e1f44dea9 100644 --- a/src/grpc/protobuf.rs +++ b/src/grpc/protobuf.rs @@ -202,7 +202,7 @@ mod tests { use serde_json::json; use super::*; - use crate::cli::{init_file, init_http}; + use crate::cli::init_runtime; use crate::config::reader::ConfigReader; use crate::config::{Config, Field, Grpc, Type, Upstream}; @@ -224,9 +224,8 @@ mod tests { } async fn get_proto_file(name: &str) -> Result { - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); - let reader = ConfigReader::init(file_io, http_io); + let runtime = init_runtime(&Upstream::default(), None); + let reader = ConfigReader::init(runtime); let mut config = Config::default(); let grpc = Grpc { proto_path: get_test_file(name) diff --git a/src/grpc/request_template.rs b/src/grpc/request_template.rs index 2774b3af94..7035bea928 100644 --- a/src/grpc/request_template.rs +++ b/src/grpc/request_template.rs @@ -106,7 +106,7 @@ mod tests { use pretty_assertions::assert_eq; use super::RequestTemplate; - use crate::cli::{init_file, init_http}; + use crate::cli::init_runtime; use crate::config::reader::ConfigReader; use crate::config::{Config, Field, GraphQLOperationType, Grpc, Type, Upstream}; use crate::grpc::protobuf::{ProtobufOperation, ProtobufSet}; @@ -120,9 +120,8 @@ mod tests { test_file.push("tests"); test_file.push("greetings.proto"); - let file_io = init_file(); - let http_io = init_http(&Upstream::default(), None); - let reader = ConfigReader::init(file_io, http_io); + let runtime = init_runtime(&Upstream::default(), None); + let reader = ConfigReader::init(runtime); let mut config = Config::default(); let grpc = Grpc { proto_path: test_file.to_str().unwrap().to_string(), diff --git a/src/http/request_context.rs b/src/http/request_context.rs index c48005c73c..36ee621375 100644 --- a/src/http/request_context.rs +++ b/src/http/request_context.rs @@ -102,18 +102,18 @@ impl RequestContext { impl From<&AppContext> for RequestContext { fn from(server_ctx: &AppContext) -> Self { Self { - h_client: server_ctx.universal_http_client.clone(), - h2_client: server_ctx.http2_only_client.clone(), + h_client: server_ctx.runtime.http.clone(), + h2_client: server_ctx.runtime.http2_only.clone(), server: server_ctx.blueprint.server.clone(), upstream: server_ctx.blueprint.upstream.clone(), req_headers: HeaderMap::new(), http_data_loaders: server_ctx.http_data_loaders.clone(), gql_data_loaders: server_ctx.gql_data_loaders.clone(), - cache: server_ctx.cache.clone(), + cache: server_ctx.runtime.cache.clone(), grpc_data_loaders: server_ctx.grpc_data_loaders.clone(), min_max_age: Arc::new(Mutex::new(None)), cache_public: Arc::new(Mutex::new(None)), - env_vars: server_ctx.env_vars.clone(), + env_vars: server_ctx.runtime.env.clone(), } } } diff --git a/src/lib.rs b/src/lib.rs index d46e6bc1d4..8159ea579d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ pub mod lambda; pub mod mustache; pub mod path; pub mod print_schema; +pub mod target_runtime; pub mod try_fold; pub mod valid; diff --git a/src/target_runtime.rs b/src/target_runtime.rs new file mode 100644 index 0000000000..78bcff4d36 --- /dev/null +++ b/src/target_runtime.rs @@ -0,0 +1,17 @@ +use std::sync::Arc; + +use async_graphql_value::ConstValue; + +use crate::{Cache, EnvIO, FileIO, HttpIO}; + +/// The TargetRuntime struct unifies the available runtime-specific +/// IO implementations. This is used to reduce piping IO structs all +/// over the codebase. +#[derive(Clone)] +pub struct TargetRuntime { + pub http: Arc, + pub http2_only: Arc, + pub env: Arc, + pub file: Arc, + pub cache: Arc>, +} diff --git a/tests/graphql_spec.rs b/tests/graphql_spec.rs index 900c08f432..1c2dca2499 100644 --- a/tests/graphql_spec.rs +++ b/tests/graphql_spec.rs @@ -15,7 +15,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::Value; use tailcall::blueprint::Blueprint; -use tailcall::cli::{init_env, init_file, init_http, init_in_memory_cache}; +use tailcall::cli::init_runtime; use tailcall::config::reader::ConfigReader; use tailcall::config::{Config, ConfigSet}; use tailcall::directive::DirectiveCodec; @@ -282,7 +282,6 @@ fn test_config_identity() -> std::io::Result<()> { #[tokio::test] async fn test_server_to_client_sdl() -> std::io::Result<()> { let specs = GraphQLSpec::cargo_read("tests/graphql"); - let file_io = init_file(); for spec in specs? { let expected = spec.find_source(Tag::ClientSDL); @@ -291,7 +290,8 @@ async fn test_server_to_client_sdl() -> std::io::Result<()> { let content = content.as_str(); let config = Config::from_sdl(content).to_result().unwrap(); let upstream = config.upstream.clone(); - let reader = ConfigReader::init(file_io.clone(), init_http(&upstream, None)); + let runtime = init_runtime(&upstream, None); + let reader = ConfigReader::init(runtime); let config_set = reader.resolve(config).await.unwrap(); let actual = print_schema::print_schema((Blueprint::try_from(&config_set).unwrap()).to_schema()); @@ -330,16 +330,8 @@ async fn test_execution() -> std::io::Result<()> { .trace(spec.path.to_str().unwrap_or_default()) .to_result() .unwrap(); - let h_client = init_http(&blueprint.upstream, None); - let h2_client = init_http(&blueprint.upstream, None); - let chrono_cache = init_in_memory_cache(); - let server_ctx = AppContext::new( - blueprint, - h_client, - h2_client, - init_env(), - Arc::new(chrono_cache), - ); + let runtime = init_runtime(&blueprint.upstream, None); + let server_ctx = AppContext::new(blueprint, runtime); let schema = &server_ctx.schema; for q in spec.test_queries { @@ -379,7 +371,6 @@ async fn test_execution() -> std::io::Result<()> { #[tokio::test] async fn test_failures_in_client_sdl() -> std::io::Result<()> { let specs = GraphQLSpec::cargo_read("tests/graphql/errors"); - let file_io = init_file(); for spec in specs? { let content = spec.find_source(Tag::ServerSDL); @@ -391,7 +382,8 @@ async fn test_failures_in_client_sdl() -> std::io::Result<()> { let actual = match config { Ok(config) => { let upstream = config.upstream.clone(); - let reader = ConfigReader::init(file_io.clone(), init_http(&upstream, None)); + let runtime = init_runtime(&upstream, None); + let reader = ConfigReader::init(runtime); match reader.resolve(config).await { Ok(config_set) => Valid::from(Blueprint::try_from(&config_set)) .to_result() diff --git a/tests/http_spec.rs b/tests/http_spec.rs index 6873fa4743..c03810c723 100644 --- a/tests/http_spec.rs +++ b/tests/http_spec.rs @@ -18,10 +18,11 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use tailcall::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest}; use tailcall::blueprint::Blueprint; -use tailcall::cli::{init_file, init_hook_http, init_http, init_in_memory_cache}; +use tailcall::cli::{init_hook_http, init_in_memory_cache, init_runtime}; use tailcall::config::reader::ConfigReader; use tailcall::config::{Config, ConfigSet, Source, Upstream}; use tailcall::http::{handle_request, AppContext, Method, Response}; +use tailcall::target_runtime::TargetRuntime; use tailcall::{EnvIO, HttpIO}; use url::Url; @@ -199,11 +200,10 @@ impl HttpSpec { } async fn server_context(&self) -> Arc { - let file_io = init_file(); - let http_client = init_http(&Upstream::default(), None); + let runtime = init_runtime(&Upstream::default(), None); let config = match self.config.clone() { ConfigSource::File(file) => { - let reader = ConfigReader::init(file_io, http_client); + let reader = ConfigReader::init(runtime.clone()); reader.read_all(&[file]).await.unwrap() } ConfigSource::Inline(config) => ConfigSet::from(config), @@ -216,7 +216,16 @@ impl HttpSpec { let http2_client = Arc::new(MockHttpClient::new(self.clone())); let env = Arc::new(Env::init(self.env.clone())); let chrono_cache = Arc::new(init_in_memory_cache()); - let server_context = AppContext::new(blueprint, client, http2_client, env, chrono_cache); + let server_context = AppContext::new( + blueprint, + TargetRuntime { + http: client, + http2_only: http2_client, + env, + cache: chrono_cache, + file: runtime.file.clone(), + }, + ); Arc::new(server_context) } } diff --git a/tests/server_spec.rs b/tests/server_spec.rs index 6f4fe775ab..86fed8c3ad 100644 --- a/tests/server_spec.rs +++ b/tests/server_spec.rs @@ -1,14 +1,13 @@ use reqwest::Client; use serde_json::json; +use tailcall::cli::init_runtime; use tailcall::cli::server::Server; -use tailcall::cli::{init_file, init_http}; use tailcall::config::reader::ConfigReader; use tailcall::config::Upstream; async fn test_server(configs: &[&str], url: &str) { - let file_io = init_file(); - let http_client = init_http(&Upstream::default(), None); - let reader = ConfigReader::init(file_io, http_client); + let runtime = init_runtime(&Upstream::default(), None); + let reader = ConfigReader::init(runtime); let config = reader.read_all(configs).await.unwrap(); let mut server = Server::new(config); let server_up_receiver = server.server_up_receiver(); @@ -92,9 +91,8 @@ async fn server_start_http2_rsa() { #[tokio::test] async fn server_start_http2_nokey() { let configs = &["tests/server/config/server-start-http2-nokey.graphql"]; - let file_io = init_file(); - let http_client = init_http(&Upstream::default(), None); - let reader = ConfigReader::init(file_io, http_client); + let runtime = init_runtime(&Upstream::default(), None); + let reader = ConfigReader::init(runtime); let config = reader.read_all(configs).await.unwrap(); let server = Server::new(config); assert!(server.start().await.is_err())