Skip to content

Commit

Permalink
rename env
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 27, 2024
1 parent ae9e428 commit cc95aee
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions tests/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use std::collections::HashMap;
use tailcall::EnvIO;

#[derive(Clone)]
pub struct TestEnvIO {
pub struct Env {
vars: HashMap<String, String>,
}

impl EnvIO for TestEnvIO {
impl EnvIO for Env {
fn get(&self, key: &str) -> Option<Cow<'_, str>> {
self.vars.get(key).map(Cow::from)
}
}

impl TestEnvIO {
impl Env {
pub fn init(vars: Option<HashMap<String, String>>) -> Self {
Self { vars: vars.unwrap_or_default() }
}
Expand Down
10 changes: 5 additions & 5 deletions tests/core/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use tailcall::FileIO;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use super::runtime::ExecutionSpec;
pub struct MockFileSystem {
pub struct File {
spec: ExecutionSpec,
}

impl MockFileSystem {
pub fn new(spec: ExecutionSpec) -> MockFileSystem {
MockFileSystem { spec }
impl File {
pub fn new(spec: ExecutionSpec) -> File {
File { spec }
}
}

#[async_trait::async_trait]
impl FileIO for MockFileSystem {
impl FileIO for File {
async fn write<'a>(&'a self, _path: &'a str, _content: &'a [u8]) -> anyhow::Result<()> {
Err(anyhow!("Cannot write to a file in an execution spec"))
}
Expand Down
8 changes: 4 additions & 4 deletions tests/core/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use tailcall::HttpIO;
use super::runtime::{ExecutionMock, ExecutionSpec};

#[derive(Clone, Debug)]
pub struct MockHttpClient {
pub struct Http {
mocks: Vec<ExecutionMock>,
spec_path: String,
}

impl MockHttpClient {
impl Http {
pub fn new(spec: &ExecutionSpec) -> Self {
let mocks = spec
.mock
Expand All @@ -44,7 +44,7 @@ impl MockHttpClient {
.to_string_lossy()
.into_owned();

MockHttpClient { mocks, spec_path }
Http { mocks, spec_path }
}

pub fn test_hits(&self, path: impl AsRef<Path>) {
Expand Down Expand Up @@ -83,7 +83,7 @@ fn string_to_bytes(input: &str) -> Vec<u8> {
}

#[async_trait::async_trait]
impl HttpIO for MockHttpClient {
impl HttpIO for Http {
async fn execute(&self, req: reqwest::Request) -> anyhow::Result<Response<Bytes>> {
// Determine if the request is a GRPC request based on PORT
let is_grpc = req.url().as_str().contains("50051");
Expand Down
8 changes: 4 additions & 4 deletions tests/core/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use tailcall::http::AppContext;
use tailcall::runtime::TargetRuntime;
use tailcall::EnvIO;

use super::file::MockFileSystem;
use super::http::MockHttpClient;
use super::file::File;
use super::http::Http;
use super::model::*;
use super::runtime::ExecutionSpec;

Expand Down Expand Up @@ -273,7 +273,7 @@ impl ExecutionSpec {
&self,
config: &ConfigModule,
env: HashMap<String, String>,
http_client: Arc<MockHttpClient>,
http_client: Arc<Http>,
) -> Arc<AppContext> {
let blueprint = Blueprint::try_from(config).unwrap();
let http = if let Some(script) = blueprint.server.script.clone() {
Expand All @@ -287,7 +287,7 @@ impl ExecutionSpec {
let runtime = TargetRuntime {
http,
http2_only,
file: Arc::new(MockFileSystem::new(self.clone())),
file: Arc::new(File::new(self.clone())),
env: Arc::new(Env::init(env)),
cache: Arc::new(InMemoryCache::new()),
extensions: Arc::new(vec![]),
Expand Down
8 changes: 4 additions & 4 deletions tests/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use tailcall::cli::javascript;
use tailcall::config::Source;
use tailcall::runtime::TargetRuntime;

use super::env::TestEnvIO;
use super::env::Env;
use super::file::TestFileIO;
use super::http::MockHttpClient;
use super::http::Http;
use super::model::*;

#[derive(Clone, Setters)]
Expand Down Expand Up @@ -78,7 +78,7 @@ impl ExecutionMock {
}

pub fn create_runtime(
http_client: Arc<MockHttpClient>,
http_client: Arc<Http>,
env: Option<HashMap<String, String>>,
script: Option<blueprint::Script>,
) -> TargetRuntime {
Expand All @@ -95,7 +95,7 @@ pub fn create_runtime(
};

let file = TestFileIO::init();
let env = TestEnvIO::init(env);
let env = Env::init(env);

TargetRuntime {
http,
Expand Down
14 changes: 7 additions & 7 deletions tests/core/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use tailcall::merge_right::MergeRight;
use tailcall::print_schema::print_schema;
use tailcall::valid::{Cause, ValidationError, Validator as _};

use super::file::MockFileSystem;
use super::http::MockHttpClient;
use super::file::File;
use super::http::Http;
use super::model::*;
use super::runtime::ExecutionSpec;
use crate::core::runtime;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl From<Cause<String>> for SDLError {
}
}

async fn is_sdl_error(spec: ExecutionSpec, mock_http_client: Arc<MockHttpClient>) -> bool {
async fn is_sdl_error(spec: ExecutionSpec, mock_http_client: Arc<Http>) -> bool {
if spec.sdl_error {
// errors: errors are expected, make sure they match
let (source, content) = &spec.server[0];
Expand All @@ -66,7 +66,7 @@ async fn is_sdl_error(spec: ExecutionSpec, mock_http_client: Arc<MockHttpClient>
let config = match config {
Ok(config) => {
let mut runtime = runtime::create_runtime(mock_http_client, spec.env.clone(), None);
runtime.file = Arc::new(MockFileSystem::new(spec.clone()));
runtime.file = Arc::new(File::new(spec.clone()));
let reader = ConfigReader::init(runtime);
match reader.resolve(config, spec.path.parent()).await {
Ok(config) => Blueprint::try_from(&config),
Expand Down Expand Up @@ -165,7 +165,7 @@ async fn check_server_config(spec: ExecutionSpec) -> Vec<Config> {
async fn run_query_tests_on_spec(
spec: ExecutionSpec,
server: Vec<ConfigModule>,
mock_http_client: Arc<MockHttpClient>,
mock_http_client: Arc<Http>,
) {
if let Some(tests) = spec.test.as_ref() {
let app_ctx = spec
Expand Down Expand Up @@ -215,7 +215,7 @@ async fn test_spec(spec: ExecutionSpec) {
insta_settings.set_prepend_module_to_snapshot(false);
let _guard = insta::Settings::bind_to_scope(&insta_settings);

let mock_http_client = Arc::new(MockHttpClient::new(&spec));
let mock_http_client = Arc::new(Http::new(&spec));

// check sdl error if any
if is_sdl_error(spec.clone(), mock_http_client.clone()).await {
Expand All @@ -237,7 +237,7 @@ async fn test_spec(spec: ExecutionSpec) {

// Resolve all configs
let mut runtime = runtime::create_runtime(mock_http_client.clone(), spec.env.clone(), None);
runtime.file = Arc::new(MockFileSystem::new(spec.clone()));
runtime.file = Arc::new(File::new(spec.clone()));
let reader = ConfigReader::init(runtime);

let server: Vec<ConfigModule> = join_all(
Expand Down

0 comments on commit cc95aee

Please sign in to comment.